Custom Indicator
Created at 04 Sep 2016, 22:51
Custom Indicator
04 Sep 2016, 22:51
Could you help me please with my custom indicator... I would like to compile two "buffer" line in one window with own rules for up buffer and down buffer but without success. I dont know how to set up rules or variables. Thanks.
RSI with Momentum Osc is Rule 1, ADX is Rule 2, here is my code:
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using cAlgo.Indicators; namespace cAlgo { [Levels(0)] [Indicator(IsOverlay = false, ScalePrecision = 0, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class RSIMomentum : Indicator { [Parameter("Source")] public DataSeries Source { get; set; } [Parameter("RSI Periods", DefaultValue = 5)] public int RSIPeriods { get; set; } [Parameter("Momentum Periods", DefaultValue = 10)] public int MomentumPeriods { get; set; } [Parameter("DMI Periods", DefaultValue = 8)] public int DMIPeriods { get; set; } [Parameter("Tresh", DefaultValue = 25)] public int Tresh { get; set; } [Output("RSI", LineStyle = LineStyle.Solid, Thickness = 1, Color = Colors.Orange)] public IndicatorDataSeries RSI { get; set; } [Output("Momentum", LineStyle = LineStyle.Solid, Thickness = 1, Color = Colors.Green)] public IndicatorDataSeries Momentum { get; set; } [Output("Momentum Buffer", PlotType = PlotType.Points, Thickness = 4, Color = Colors.Gray)] public IndicatorDataSeries MomentumBuffer { get; set; } [Output("DMI Buffer", PlotType = PlotType.Points, Thickness = 4, Color = Colors.Gray)] public IndicatorDataSeries DMIBuffer { get; set; } [Output("Up", PlotType = PlotType.Points, Thickness = 4, Color = Colors.Green)] public IndicatorDataSeries Up { get; set; } [Output("Down", PlotType = PlotType.Points, Thickness = 4, Color = Colors.Orange)] public IndicatorDataSeries Down { get; set; } private RelativeStrengthIndex _rsi; private MomentumOscillator _momentum; private DirectionalMovementSystem _adx; protected override void Initialize() { _rsi = Indicators.RelativeStrengthIndex(Source, RSIPeriods); _momentum = Indicators.MomentumOscillator(Source, MomentumPeriods); _adx = Indicators.DirectionalMovementSystem(DMIPeriods); } public override void Calculate(int index) { RSI[index] = _rsi.Result[index] - 50; Momentum[index] = 10 * _momentum.Result[index] - 1000; double mb = -75; double db = -85; MomentumBuffer[index] = mb; DMIBuffer[index] = db; if ((RSI[index] > 0) && (Momentum[index] > 0)) { Up[index] = mb; MomentumBuffer[index] = double.NaN; } else if ((RSI[index] < 0) && (Momentum[index] < 0)) { Down[index] = mb; MomentumBuffer[index] = double.NaN; } double dmplus = _adx.DIPlus[index]; double dmminus = _adx.DIMinus[index]; double dmi = dmplus - dmminus; if (_adx.ADX.Last(0) > Tresh) { if (dmi > 0) { Up[index] = db; DMIBuffer[index] = double.NaN; } else if (dmi < 0) { Down[index] = db; DMIBuffer[index] = double.NaN; } } } } }
hedgehog
05 Sep 2016, 11:12
I created this way:
@hedgehog