EA wont work at MA levels.

 
extern double LotSize = 1;
extern double StopLoss = 0;
extern double TakeProfit = 0;
extern double MALength = 5;
extern double TrailingLimit = 0;
extern double TrailingStep = 0;
extern int MagicNumber = 1;
extern double Buffer = 3;

//============= Global Variables
int LongTicket;
int ShortTicket;
double Tickpoint;


//============= Initialization function
int init()
        {
      Tickpoint = RealPipPoint(Symbol());
   }

//============== Start function
int start()
        {

//Variables      
double MALow = iMA(NULL, 0, MALength, 0, MODE_SMA, PRICE_LOW, 0);
double Move = Buffer * Tickpoint;
       
//==== Long Order
        
        OrderSelect(LongTicket,SELECT_BY_TICKET);
        if(OrderCloseTime() != 0 || LongTicket == 0)
                {
bool buy_condition_1 = Ask <= MALow - Move; 

        if( buy_condition_1 )
                        {
                        LongTicket = OrderSend(Symbol(),OP_BUY,LotSize,Ask,0,0,0,"Buy Order",MagicNumber,0,Green);
                        OrderSelect(LongTicket,SELECT_BY_TICKET); 
                        double OpenPrice = OrderOpenPrice();
                          
            if(StopLoss >= 0) double LongStopLoss = OpenPrice - (StopLoss * Tickpoint);
            if(TakeProfit >= 0) double LongTakeProfit = OpenPrice + (TakeProfit * Tickpoint);
            
            if(LongStopLoss > 0 || LongTakeProfit > 0) 
                        {
                        bool LongMod = OrderModify(LongTicket,OpenPrice,LongStopLoss, LongTakeProfit,0);
                        }                       
                        }
                }
         
Why doesnt my above code execute trades at the moving average value? They always trade several pips above or below....seems quite random. According to the above code, if the Ask price falls 3 pips below the 5 day MA, i want to trigger a buy. But as i said before, the bys get triggered randomly, sometimes as much as 50 pips away..
 
bondstrader: Why doesnt my above code
  1. There are no mind readers here. Add Print statements with variable values and find out why.
  2. Check your return codes (OrderSend and OrderModify) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Reason: