MovingAverage of another two moving average results
            
                 03 Mar 2023, 04:46
            
                    
I'd like to calculate a moving average of the difference of two other moving averages' results like below.
            _emaFast = Indicators.MovingAverage(MarketSeries.Close, 10, MovingAverageType.Exponential);
            _emaSlow = Indicators.MovingAverage(MarketSeries.Close, 20, MovingAverageType.Exponential);            
            _emaSignal = Indicators.MovingAverage(_emaFast.Result - _emaSlow.Result, 9, MovingAverageType.Exponential);
However, this code doesn't compile with a "Operator '-' cannot be applied to operands of type 'IndicatorDataSeries' and 'IndicatorDataSeries'" error.
How can I get the _emaSignal correctly in here?
Thank you very much.
Replies
                     ys2310
                     03 Mar 2023, 10:14
                                    
Hello Panagiotis,
Thank you for the indicator! But when I tried use it from cBot like below, I got a run-time error:
26/10/2020 07:00:00.210 | Crashed in OnStart with NullReferenceException: Object reference not set to an instance of an object.
26/10/2020 07:00:00.210 | CBot instance [Test, XAUUSD, m1] crashed with error "Crashed in OnStart with NullReferenceException: Object reference not set to an instance of an object."
---
 private MovingAverage _emaSignal;
 private NewIndicator7 _emaDiff;
 protected override void OnStart()
 {
      _emaSignal = Indicators.MovingAverage(_emaDiff.Result, 9, MovingAverageType.Exponential);
 }
---
What might be wrong in here?
Thank you gain in advance.
@ys2310
                     PanagiotisChar
                     03 Mar 2023, 11:14
                                    
Hi there,
You need to initialize the _emaDiff indicator. Also _emaSignal is not necessary. The result is already contained in _emaDiff.Result.
Need help? Join us on Telegram
Need premium support? Trade with us
@PanagiotisChar

PanagiotisChar
03 Mar 2023, 09:05
Hi there,
Here is an example
Aieden Technologies
Need help? Join us on Telegram
Need premium support? Trade with us
@PanagiotisChar