HELP!!!! Expert support needed

 
I'm calculating MACD and the histogram values as such and putting an arrow on the chart. Periodically I will get a false crossover signal. Can anyone tell me why?

Thanks very much in advance,

E

MacdCurrent=iMACD(NULL,0,8,17,9,PRICE_CLOSE,MODE_MAIN,0);
MacdPrevious=iMACD(NULL,0,8,17,9,PRICE_CLOSE,MODE_MAIN,1);

SignalCurrent=iMACD(NULL,0,8,17,9,PRICE_CLOSE,MODE_SIGNAL,0);
SignalPrevious=iMACD(NULL,0,8,17,9,PRICE_CLOSE,MODE_SIGNAL,1);

MacdHist = MacdCurrent - SignalCurrent;

if(MacdHist > 0 && MacdCurrent > SignalCurrent && MacdPrevious < SignalPrevious)
-- Draw Arrow

if(MacdHist < 0 && MacdCurrent < SignalCurrent && MacdPrevious > SignalPrevious)
-- Draw Arrow
 

You are using the current bar in your calculation

The "close" price is the current and still changing price in the current bar, bar 0

Therefore, the calculation of the cross/no cross can change too

 
Thank you very much phy!!! Now how do I fix it? I've seen MACD calculated like this everywhere I've looked.
 

MacdCurrent=iMACD(NULL,0,8,17,9,PRICE_CLOSE,MODE_MAIN,1);
MacdPrevious=iMACD(NULL,0,8,17,9,PRICE_CLOSE,MODE_MAIN,2);

SignalCurrent=iMACD(NULL,0,8,17,9,PRICE_CLOSE,MODE_SIGNAL,1);
SignalPrevious=iMACD(NULL,0,8,17,9,PRICE_CLOSE,MODE_SIGNAL,2);

MacdHist = MacdCurrent - SignalCurrent;

if(MacdHist > 0 && MacdCurrent > SignalCurrent && MacdPrevious < SignalPrevious)
-- Draw Arrow on bar 1

if(MacdHist < 0 && MacdCurrent < SignalCurrent && MacdPrevious > SignalPrevious)
-- Draw Arrow on bar 1

The start of the current bar ( bar 0 ) is when you decide whether or not to take a trade
based on the signal of the just completed bar

 
Thanks, I'll try it out tonight when the London market opens.

Ed
 
phy:

MacdCurrent=iMACD(NULL,0,8,17,9,PRICE_CLOSE,MODE_MAIN,1);
MacdPrevious=iMACD(NULL,0,8,17,9,PRICE_CLOSE,MODE_MAIN,2);

SignalCurrent=iMACD(NULL,0,8,17,9,PRICE_CLOSE,MODE_SIGNAL,1);
SignalPrevious=iMACD(NULL,0,8,17,9,PRICE_CLOSE,MODE_SIGNAL,2);

MacdHist = MacdCurrent - SignalCurrent;

if(MacdHist > 0 && MacdCurrent > SignalCurrent && MacdPrevious < SignalPrevious)
-- Draw Arrow on bar 1

if(MacdHist < 0 && MacdCurrent < SignalCurrent && MacdPrevious > SignalPrevious)
-- Draw Arrow on bar 1

The start of the current bar ( bar 0 ) is when you decide whether or not to take a trade
based on the signal of the just completed bar


Not sure I follow this part:

"The start of the current bar ( bar 0 ) is when you decide whether or not to take a trade
based on the signal of the just completed bar". Can you explain?

Ed
 

Run the code on 1 minute chart and watch for a while.

There will never be a signal on the current bar.

If there is a new signal, it will appear on bar 1 as soon as a new bar 0 occurs.

 
phy:

Run the code on 1 minute chart and watch for a while.

There will never be a signal on the current bar.

If there is a new signal, it will appear on bar 1 as soon as a new bar 0 occurs.

This sounds ok if I was going to based my trades off of a 1 M chart but I want to base my trades off of 5M\15M\30M\1H charts. What should be strategy be when trading in those timeframes?

Thanks,

Ed
 

Same.

I mentioned 1m chart so you could watch how it works in less than a week.

 
Sorry, but you're obviously leap years ahead of me at this. If a valid crossover happens sometime during Bar 1 how do I catch it? Won't it be an old signal?
 

I give up. Anyone else care to comment?

Reason: