MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
MacdPrevious2=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,2);
MacdPrevious3=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,3);
SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
SignalPrevious2=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,2);
MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,0);
MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1);
// check for long position (BUY) possibility
if(MacdCurrent>0 && MacdPrevious<0 && MacdPrevious2<0)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"macd sample",16384,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
Apparently it "jumped" above 0 on this chart.
indicator/signals that use Bar 0 do not give a stable signal
if(MacdCurrent>0 && MacdPrevious<0 && MacdPrevious2<0)
Looks like that condition could have been acheived, opening the trade, even though the final result for that bar
did not conform to the signal requirements.
Is there anyway that these "jumps" can be avoided? Is there programming language that could make sure the tester only uses the completed bars? Or would you recognize that I use period 1 instead of period 0 to make sure this doesn't happen?
thanks for your response.
Take your signal on the first ticks of the new current bar...
MacdCurrent=CD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
MacdPrevious=CD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,2);
MacdPrevious2=CD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,3);
MacdPrevious3=CD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,4);
SignalCurrent=CD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
SignalPrevious=CD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,2);
SignalPrevious2=CD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,3);
MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1);
MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,2);
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
thanks.