0
votes

I'm trying to write an Ea with 2 moving averages, and I want it to send an order when they cross. Sell orders seem fine, but for Buy orders in 1-min chart, the Ask price which I use to send the order is not in the candle price range. Actually I did Print("Ask=",Ask) right before my OrderEntry function and right after OrderSend(). They are equal to some price way above the candle-[High] and previous candle-[close] But when I try higher time frames, it get closer to the candle and in daily time frame, the Ask price for orders would be in the candle range (High-Low). Does anybody know why this is happening?

void CheckForMaTrade(){
   
   double PreviousFast = iMA(NULL,0,FastMaPeriod,FastMaShift,FastMaMethod,FastMaAppliedTo,2);
   double CurrentFast = iMA(NULL,0,FastMaPeriod,FastMaShift,FastMaMethod,FastMaAppliedTo,1);   
   double PreviousSlow = iMA(NULL,0,SlowMaPeriod,SlowMaShift,SlowMaMethod,SlowMaAppliedTo,2);   
   double CurrentSlow = iMA(NULL,0,SlowMaPeriod,SlowMaShift,SlowMaMethod,SlowMaAppliedTo,1);
   
   if(PreviousFast<PreviousSlow && CurrentFast>CurrentSlow)
      OrderEntry(0);       
   if(PreviousFast>PreviousSlow && CurrentFast<CurrentSlow)
      OrderEntry(1);
}

void OrderEntry(int direction){
   if(direction == 0){
      double bsl=0;
      double btp=0;
         if(StopLoss != 0)
            bsl = Ask-(StopLoss*pips);   
         if(TakeProfit != 0)
            btp = Ask+(TakeProfit*pips);
         if(OpenOrdersThisPair(Symbol()) < 10 )
            OrderSend(NULL,OP_BUY,LotSize,Ask,0,bsl,btp,NULL,MagicNumber,0,Gold);        
   } 

enter image description here

1

1 Answers

0
votes

In MT4, the candles are drawn by BID prices only. ASK prices are not taken into consideration. So it is possible that Ask > highest bid.