The reason of this order sent by my first EA?

coderelease  

Today my first EA sent its first order, which was at the place of the blue arrow, Buy order EURUSD @1.08420.

What I confused is, why my EA sent this two order?

The design logic of this EA is, when MA35 crossed MA20, the buy order can be send.

But as I can see from picture, there is no any MA cross happened near EURUSD1.08420 in period_M5 time_frame chart.

Who can help me to tell me why the system post the buy order?


By the way, the red arrow is set by myself. I finally closed these two odd positions manually. two orderes

closed positions


bool Buy_Condition = (maxiaoVal[0]>madaVal[0] && maxiaoVal[1]<madaVal[1]);

   bool Sell_Condition = (maxiaoVal[0]<madaVal[0] && maxiaoVal[1]>madaVal[1]);

   

   if(Buy_Condition)     

     {

      if(PositionSelect(_Symbol)==true)    

        {

         if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)    

           {

            trade.PositionClose(PositionGetInteger(POSITION_TICKET));   

            mrequest.action = TRADE_ACTION_DEAL;                        

            mrequest.price = NormalizeDouble(latest_tick.ask,_Digits);

            //mrequest.sl = NormalizeDouble(latest_tick.ask-STP*_Point,_Digits);

            //mrequest.tp = NormalizeDouble(latest_tick.ask+TKP*_Point,_Digits);

            mrequest.symbol = _Symbol;

            mrequest.volume = Lot;

            mrequest.magic = EA_Magic;

            mrequest.type = ORDER_TYPE_BUY;

            mrequest.type_filling = ORDER_FILLING_FOK;

            mrequest.deviation = 0;

            OrderSend(mrequest,mresult);

            if(mresult.retcode==10009 || mresult.retcode == 10008)

              {

               Alert("Buy Order Successed. Order number is ",mrequest.order,"!!");

              }

            else

              {

               Alert("Buy Order cannot complete. Wrong :", GetLastError());

               ResetLastError();

               return;

              }

           }    

         }

      else                        

           {

            mrequest.action = TRADE_ACTION_DEAL;

            mrequest.price = NormalizeDouble(latest_tick.ask,_Digits);

            //mrequest.sl = NormalizeDouble(latest_tick.ask-STP*_Point,_Digits);

            //mrequest.tp = NormalizeDouble(latest_tick.ask+TKP*_Point,_Digits);

            mrequest.symbol = _Symbol;

            mrequest.volume = Lot;

            mrequest.magic = EA_Magic;

            mrequest.type = ORDER_TYPE_BUY;

            mrequest.type_filling = ORDER_FILLING_FOK;

            mrequest.deviation = 0;

            OrderSend(mrequest,mresult);

            if(mresult.retcode==10009 || mresult.retcode == 10008)

              {

               Alert("Buy Order Successed. Order number is ",mrequest.order,"!!");

              }

            else

              {

               Alert("Buy Order cannot complete. Wrong :", GetLastError());

               ResetLastError();

               return;

              }

           }

        }

        

   if(Sell_Condition)

     {

      if(PositionSelect(_Symbol)==true)

        {

         if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)

           {

            trade.PositionClose(PositionGetInteger(POSITION_TICKET));

            mrequest.action = TRADE_ACTION_DEAL;

            mrequest.price = NormalizeDouble(latest_tick.bid,_Digits);

            //mrequest.sl = NormalizeDouble(latest_tick.bid+STP*_Point,_Digits);

            //mrequest.tp = NormalizeDouble(latest_tick.bid-TKP*_Point,_Digits);

            mrequest.symbol = _Symbol;

            mrequest.volume = Lot;

            mrequest.magic = EA_Magic;

            mrequest.type = ORDER_TYPE_SELL;

            mrequest.type_filling = ORDER_FILLING_FOK;

            mrequest.deviation = 0;

            OrderSend(mrequest,mresult);

            if(mresult.retcode==10009 || mresult.retcode == 10008)

              {

               Alert("Sell Order Successed. Order number is ",mrequest.order,"!!");

              }

            else

              {

               Alert("Sell Order cannot complete. Wrong :", GetLastError());

               ResetLastError();

               return;

              }

           }

         }

       else

          {

            mrequest.action = TRADE_ACTION_DEAL;

            mrequest.price = NormalizeDouble(latest_tick.bid,_Digits);

            //mrequest.sl = NormalizeDouble(latest_tick.bid+STP*_Point,_Digits);

            //mrequest.tp = NormalizeDouble(latest_tick.bid-TKP*_Point,_Digits);

            mrequest.symbol = _Symbol;

            mrequest.volume = Lot;

            mrequest.magic = EA_Magic;

            mrequest.type = ORDER_TYPE_SELL;

            mrequest.type_filling = ORDER_FILLING_FOK;

            mrequest.deviation = 0;

            OrderSend(mrequest,mresult);

            if(mresult.retcode==10009 || mresult.retcode == 10008)

              {

               Alert("Sell Order Successed. Order number is ",mrequest.order,"!!");

              }

            else

              {

               Alert("Sell Order cannot complete. Wrong :", GetLastError());

               ResetLastError();

               return;

              }

           }

        }

     }
Keith Watford  
Please edit your post and use the code button (Alt+S) when pasting code.
EDIT your original post, please do not just post the code correctly in a new post.

coderelease  

And I find an important thing - when I do back test, this EA was working right!

In back test, this EA executed well according to its code - open positions when MA20 upcrosses MA35 and close positions when MA20 downcross MA35.

But when I put this EA into my demo account to do real data demo trading, this EA did odd.

Who can tell me why?