Description
This is a version of the SSL Channel indicator which workes on higher time frames. It does not work on Tick charts!
Based on this indicator.
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Cloud("SSLDown", "SSLUp")]
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class TimeFrameSSLChannel : Indicator
{
//////////////////////////////////////////////////////////////////////// PARAMETERS
[Parameter("Time Frame", DefaultValue = "Daily")]
public TimeFrame SelectedTimeFrame { get; set; }
[Parameter("Length", DefaultValue = 10)]
public int _length { get; set; }
[Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
public MovingAverageType _MAType { get; set; }
//////////////////////////////////////////////////////////////////////// OUTPUTS
[Output("SSLDown", LineColor = "Red")]
public IndicatorDataSeries _sslDown { get; set; }
[Output("SSLUp", LineColor = "Green")]
public IndicatorDataSeries _sslUp { get; set; }
private MovingAverage _maHigh, _maLow;
private IndicatorDataSeries _hlv;
private bool isCurrentTimeFrame;
private Bars bars;
//////////////////////////////////////////////////////////////////////// INITIALIZE
protected override void Initialize()
{
isCurrentTimeFrame = SelectedTimeFrame == TimeFrame;
bars = MarketData.GetBars(SelectedTimeFrame);
while (bars.OpenTimes[0] > Bars.OpenTimes[0])
bars.LoadMoreHistory();
_maHigh = Indicators.MovingAverage(bars.HighPrices, _length, _MAType);
_maLow = Indicators.MovingAverage(bars.LowPrices, _length, _MAType);
_hlv = CreateDataSeries();
}
//////////////////////////////////////////////////////////////////////// CALCULATE
public override void Calculate(int index)
{
int dataIndex = isCurrentTimeFrame ? index : bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
int dataIndex2 = isCurrentTimeFrame ? index - 1 : bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index - 1]);
if (dataIndex < 0)
{
return;
}
_hlv[index] = bars.ClosePrices[dataIndex] > _maHigh.Result[dataIndex] ? 1 : bars.ClosePrices[dataIndex] < _maLow.Result[dataIndex] ? -1 : _hlv[Bars.OpenTimes.GetIndexByTime(bars.OpenTimes[dataIndex]) - 1];
_sslDown[index] = _hlv[index] < 0 ? _maHigh.Result[dataIndex] : _maLow.Result[dataIndex];
_sslUp[index] = _hlv[index] < 0 ? _maLow.Result[dataIndex] : _maHigh.Result[dataIndex];
// Check if a new bar started (open time of tf bar != open time of last TF bar) on the selected TF, if so keep the values of the last index (index - 1)
// since this was the actual close of the TF bar otherwise "delete" the values of the last index
// index when the TF bar opened
int lastDataIndex = Bars.OpenTimes.GetIndexByTime(bars.OpenTimes[dataIndex]);
int lastDataIndex2 = Bars.OpenTimes.GetIndexByTime(bars.OpenTimes[dataIndex2]);
if (lastDataIndex == lastDataIndex2 && !isCurrentTimeFrame)
{
_sslDown[index - 1] = double.NaN;
_sslUp[index - 1] = double.NaN;
}
}
}
}
CW
cW22Trader
Joined on 16.03.2021
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Time Frame SSL Channel.algo
- Rating: 0
- Installs: 1569
- Modified: 13/10/2021 09:54
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.