Problem in Coding
Created at 22 Feb 2018, 15:57
Problem in Coding
22 Feb 2018, 15:57
Hello,
I'm new to coding and I had coded a simple indicator to get the difference of two MAs (Value usually fluctuate around 0.003 to -0.003) then use 1 to divide it, but at certain point the output of indicator is abnormal it's giving value larger than 100000 by right the value should be smaller than 1000.
Someone please help me on this.
Thank you.
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using cAlgo.Indicators; namespace cAlgo { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewIndicator : Indicator { [Parameter()] public DataSeries Source { get; set; } [Parameter(DefaultValue = 1)] public int X1 { get; set; } [Parameter(DefaultValue = 100)] public int X2 { get; set; } [Parameter(DefaultValue = MovingAverageType.Simple)] public MovingAverageType MAType1 { get; set; } [Parameter(DefaultValue = MovingAverageType.Simple)] public MovingAverageType MAType2 { get; set; } [Output("Main", Color = Colors.LightBlue)] public IndicatorDataSeries Result { get; set; } private MovingAverage ma1; private MovingAverage ma2; public IndicatorDataSeries a; public IndicatorDataSeries b; protected override void Initialize() { a = CreateDataSeries(); b = CreateDataSeries(); ma1 = Indicators.MovingAverage(MarketSeries.Close, X1, MAType1); ma2 = Indicators.MovingAverage(MarketSeries.Close, X2, MAType1); } public override void Calculate(int index) { a[index] = (ma1.Result[index] - ma2.Result[index]); b[index] = 1 / a[index]; Result[index] = b[index]; } } }