I'm having some trouble in programing a line. I'm looking to have among the opening requirements be the 12 EMA be not greater than the open of the bar. I'm doing transactions to try and not open at a sideways market.
The ema12gt;ema24 code works just fine, but the Open[1] gt; ema12 does not do the job. In back testing there are occasions where there is a trade opened below the ema12.
1 Attachment(s) Ronald - I tried adding a shift to the EMA, but only ended up with an error response from it unexpected [ .
I have attached a picture showing how the machine is supposed to work in the first commerce exhibited. The second trade should not have occurred because the [1] is under the 12 ema line.
// check for buy or sell signal
bool buy = false;
bool sell = false;
// If the asking price in the current bar is greater than 2 pips than the second previous candle and the 12ema
// is over the 24 ema then it is a buy signal
if((Ask == High[2] 3*Point) (ema12 gt; ema24)) buy = true;
// If the bidding price in the current bar is less than 2 pips than the second previous candle and the 12ema
// is below the 24 ema then it is a buy signal
if(((Low[2] == Bid) gt; 2*Point) (ema24 gt; ema12)) sell = true;
It's a work in progress, and there are things that I'm already slating to change. I am aware there is no coding for a conditionI'm just using the SL or TP levels.
The problem is probably in the fact that you're calculating the EMA on the current candle and using the start of the previous candle to determine entrance point. Change your ema settings to Examine the previous candle as well: