Warning! This section will be deprecated on February 1st 2025. Please move all your Indicators to the cTrader Store catalogue.
Description
RSI on btf with result as slope or step
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Levels(30, 50, 70)]
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class mRSIbtf : Indicator
{
[Parameter("Working TimeFrame", DefaultValue = "H4")]
public TimeFrame inpTF1 { get; set; }
[Parameter("DrawMode (slope)", DefaultValue = enumDrawMode.DrawModeSlope)]
public enumDrawMode inpDrawMode { get; set; }
[Parameter("Periods (14)", DefaultValue = 14)]
public int inpPeriods { get; set; }
[Output("RSIbtf", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries outRSI { get; set; }
private Bars _barsTF1;
private RelativeStrengthIndex _rsi;
protected override void Initialize()
{
_barsTF1 = MarketData.GetBars(inpTF1);
while (_barsTF1.OpenTimes[0] > Bars.OpenTimes[0])
_barsTF1.LoadMoreHistory();
_rsi = Indicators.RelativeStrengthIndex(_barsTF1.ClosePrices, inpPeriods);
}
public override void Calculate(int i)
{
int idx = inpTF1 == Chart.TimeFrame ? i : _barsTF1.OpenTimes.GetIndexByTime(Bars.OpenTimes[i]);
int idx1 = inpTF1 == Chart.TimeFrame ? i-1 : _barsTF1.OpenTimes.GetIndexByTime(Bars.OpenTimes[i-1]);
outRSI[i] = idx >= 0 ? _rsi.Result[idx] : 50.0;;
if (idx >= 0 && inpDrawMode == enumDrawMode.DrawModeSlope && inpTF1 != Chart.TimeFrame && Bars.OpenTimes.GetIndexByTime(_barsTF1.OpenTimes[idx]) == Bars.OpenTimes.GetIndexByTime(_barsTF1.OpenTimes[idx1]))
outRSI[i-1] = double.NaN;
}
}
public enum enumDrawMode
{
DrawModeSteps,
DrawModeSlope
}
}
mfejza
Joined on 25.01.2022
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: mRSIbtf.algo
- Rating: 2.5
- Installs: 1012
- Modified: 07/12/2022 22:19
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.