Description
This indicator detects Signal-To-Noise ratio.
As an additional piece of information, you can use the indicator's cross components to draw trend lines, which can be a proper and effective way to identify price moves.
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Levels(0)]
[Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
public class mSignalToNoise : Indicator
{
[Parameter("Main Period (21)", DefaultValue = 21)]
public int inpMainPeriod{ get; set; }
[Parameter("Smooth Period (7)", DefaultValue = 7)]
public int inpSmoothPeriod{ get; set; }
[Parameter("Show Difference as Oscillator", DefaultValue = false)]
public bool inpShowDifferenceOscillator { get; set; }
[Parameter("Show Arrows ", DefaultValue = true)]
public bool inpShowArrows { get; set; }
[Output("SignalToNoise", LineColor = "Black", PlotType = PlotType.DiscontinuousLine, Thickness = 1)]
public IndicatorDataSeries outSignalToNoise { get; set; }
[Output("Signal", LineColor = "Red", PlotType = PlotType.DiscontinuousLine, Thickness = 1)]
public IndicatorDataSeries outSignal { get; set; }
private IndicatorDataSeries _stn;
private MovingAverage _smooth;
private double raw;
private AverageTrueRange _atr;
protected override void Initialize()
{
_stn = CreateDataSeries();
_smooth = Indicators.MovingAverage(_stn, inpSmoothPeriod, MovingAverageType.Simple);
_atr = Indicators.AverageTrueRange(27, MovingAverageType.Simple);
}
public override void Calculate(int i)
{
raw =0;
for (int j=1; j<inpMainPeriod-1; j++)
raw += (1 / Bars.ClosePrices[i-j]) / inpMainPeriod;
_stn[i] = -10 * Math.Log(raw);
outSignalToNoise[i] = !inpShowDifferenceOscillator ? _stn[i] : _stn[i] -_smooth.Result[i];
outSignal[i] = !inpShowDifferenceOscillator ? _smooth.Result[i] : double.NaN;
if(inpShowArrows)
{
if(_stn[i-1] < _smooth.Result[i-1] && _stn[i] > _smooth.Result[i])
Chart.DrawIcon("SignalToNoiseUp" + Bars.OpenTimes.Last(0).ToString(), ChartIconType.Star, Bars.OpenTimes.Last(0), Bars.LowPrices.Last(0) - _atr.Result.Last(1), "Teal");
else
Chart.RemoveObject("SignalToNoiseUp" + Bars.OpenTimes.Last(0).ToString());
if(_stn[i-1] > _smooth.Result[i-1] && _stn[i] < _smooth.Result[i])
Chart.DrawIcon("SignalToNoiseDown" + Bars.OpenTimes.Last(0).ToString(), ChartIconType.Star, Bars.OpenTimes.Last(0), Bars.HighPrices.Last(0) + _atr.Result.Last(1), "Brown");
else
Chart.RemoveObject("SignalToNoiseDown" + Bars.OpenTimes.Last(0).ToString());
}
}
}
}
mfejza
Joined on 25.01.2022
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: mSignalToNoise.algo
- Rating: 5
- Installs: 673
- Modified: 01/04/2023 15:14
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
No comments found.