MACD onBar / HasCrossed issue

Created at 11 Dec 2012, 19:42
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!
ER

ErykSosenka

Joined 22.09.2012

MACD onBar / HasCrossed issue
11 Dec 2012, 19:42


Hi All,


I'm runnig a robot that uses the HasCrossedAbove/ Below function to check whether Main series of the MACD Histogram has crossed the Signal series (periods = 4). It's set to run on EURUSD 1H onBar.

The problem I have is that it tends to take into account the bar that has just opened. This is an issue as on occasion the first tick of a new bar (i.e. onBar) takes the MACD Main above or below the Signal, thus causing the robot to open a position. Eventually the bar closes in such a way that the two series end up 'uncrossed'.

Example: The attached pic @ 10:00 today when my robo opened a sell order - Main = 0.000531; Signal = 0.000539. On close of this bar the values were 0.00056 and 0.00055


So my q is: is there a way to have the same functionality as the HasCrossedAbove/ Below function but have it ignore the bar that has just opened so that false signals are filtered out?

Cheers


@ErykSosenka
Replies

ErykSosenka
11 Dec 2012, 19:45

sorry don't seem to be able to attach it to the post...

----->   http://fxpro.ctrader.com/c/DfP5n


@ErykSosenka

admin
12 Dec 2012, 14:28

You may insert images by clicking on the last button of this editor and entering the Image URL in the Remote tab. In this case it would be http://fxpro.ctrader.com/images/screens/DfP5n.png

 

 


@admin

ErykSosenka
12 Dec 2012, 18:09

Thanks for the tip...

Any suggestions with regards to the actual problem?

Cheers


@ErykSosenka

admin
13 Dec 2012, 16:07

You could use a for loop

For example:

 

            for(int i = 1; i < 4; i++)
            {
                if (_macdHistogram.Histogram[index - i] > _macdHistogram.Signal[index - i])
                {
                    // do something
                    break;
                }
            }




@admin