MACD compared to multiple past bars

Created at 20 Feb 2016, 23:16
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
CT

ctid214650

Joined 20.02.2016

MACD compared to multiple past bars
20 Feb 2016, 23:16


This should be simple to do, but I must be overlooking something.  What is the easiest way to see if the current MACD histogram value is greater (or less than) it has been for the last 300 or more bars?  I know I can compare it to (1) or (10) individually, but I can't compare it to (1-300) in one line like I need to.  I would also like to compare its current value to a range of previous bars like (5-300) previous bars.  Thanks for your help.


@ctid214650
Replies

Spotware
24 Feb 2016, 16:55

Dear Trader, 

You could write a loop to compare the values. However, we kindly ask you to be careful when writing loops in the Calculate method. The Calculate method is called for each historic bar starting from the beginning of the series up to the current bar and then on each incoming tick. In the case of multi-symbol / multi-timeframe implementation, it will be called on each tick of each symbol that is used in the indicator.

In other words, a loop in the Calculate method may consume a lot of memory and CPU usage according to the frequency the Calculate method is called.


@Spotware

croucrou
24 Feb 2016, 17:18

Hi,

 

use "for" loop to do this.

 

        for (int bar = 1; bar <= 300; bar++)
        {
            if (MacdHistogram.Histogram.Last(0) > MacdHistogram.Histogram.Last(bar))
            {
                //your logic here, 'break;' to stop the loop
            }
        }

@croucrou