why this code doesn't work???
why this code doesn't work???
21 Nov 2018, 13:53
i try to change the color but it doesn't work, why??
using System; using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo.Indicators { [Indicator(IsOverlay = true, AccessRights = AccessRights.None)] public class HMA : Indicator { [Output("HMAup", Color = Colors.Green)] public IndicatorDataSeries hmaup { get; set; } [Output("HMAdown", Color = Colors.Red)] public IndicatorDataSeries hmadown { get; set; } [Parameter(DefaultValue = 21)] public int Period { get; set; } private IndicatorDataSeries diff; private WeightedMovingAverage wma1; private WeightedMovingAverage wma2; private WeightedMovingAverage wma3; public IndicatorDataSeries hma; protected override void Initialize() { diff = CreateDataSeries(); wma1 = Indicators.WeightedMovingAverage(MarketSeries.Close, (int)Period / 2); wma2 = Indicators.WeightedMovingAverage(MarketSeries.Close, Period); wma3 = Indicators.WeightedMovingAverage(diff, (int)Math.Sqrt(Period)); } public override void Calculate(int index) { double var1 = 2 * wma1.Result[index]; double var2 = wma2.Result[index]; diff[index] = var1 - var2; hma[index] = wma3.Result[index]; if (hma[index] > hma[index - 1]) { hmaup[index] = wma3.Result[index]; } if (hma[index] < hma[index - 1]) { hmadown[index] = wma3.Result[index]; } } } }
Replies
fringou.bfe
21 Nov 2018, 15:57
another problem
i change the code, but why i have 2 line now and i would like just 1? thanks for help
using System; using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo.Indicators { [Indicator(IsOverlay = true, AccessRights = AccessRights.None)] public class HMA : Indicator { [Output("HMAup", Color = Colors.Green)] public IndicatorDataSeries hmaup { get; set; } [Output("HMAdown", Color = Colors.Red)] public IndicatorDataSeries hmadown { get; set; } [Parameter(DefaultValue = 21)] public int Period { get; set; } private IndicatorDataSeries diff; private WeightedMovingAverage wma1; private WeightedMovingAverage wma2; private WeightedMovingAverage wma3; protected override void Initialize() { diff = CreateDataSeries(); wma1 = Indicators.WeightedMovingAverage(MarketSeries.Close, (int)Period / 2); wma2 = Indicators.WeightedMovingAverage(MarketSeries.Close, Period); wma3 = Indicators.WeightedMovingAverage(diff, (int)Math.Sqrt(Period)); } public override void Calculate(int index) { double var1 = 2 * wma1.Result[index]; double var2 = wma2.Result[index]; diff[index] = var1 - var2; if (wma3.Result[index] > wma3.Result[index - 1]) { hmaup[index] = wma3.Result[index]; } if (wma3.Result[index] < wma3.Result[index - 1]) { hmadown[index] = wma3.Result[index]; } } } }
@fringou.bfe
PanagiotisCharalampous
21 Nov 2018, 16:02
Hi fringou.bfe,
You have two lines because you have defined two output parameters, HMAup and HMAdown. Can you explain to us what are you trying to do?
Best Regards,
Panagiotis
@PanagiotisCharalampous
fringou.bfe
21 Nov 2018, 16:30
i want to change the color of the line, in red if it down and green if it up
@fringou.bfe
PanagiotisCharalampous
22 Nov 2018, 10:01
Hi fringou.bfe,
You cannot have multiple colors on a single line.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
21 Nov 2018, 15:09
Hi fringou.bfe,
The reason your indicator does not work is because it crashes during execution. hma variable is not initialized therefore it is null when you try to access it. Do you need that variable? It does not seem to be used anywhere.
Best Regards,
Panagiotis
@PanagiotisCharalampous