Always errors code 130 and 4051

 

could someone please help.

I am trying to test my EA and I always get errors 130 and 4051.

this is the part of my EA which deals with sending and modifying orders.

could anyone please help.




 

     StopLossShort = StopLossShort+Spread;

     StopLossLong = StopLossLong-Spread;

     

     if(ticket == 0)

     {

      if(Close[1]>MA_GREEN&& MAgreentrue == 1)

       {

        ticket =OrderSend(Symbol(),0,Lots,Ask,100,StopLossLong,Ask+10*Point*800);

        MAfilter = true;

       }

       if(Close[1]<MA_GREEN&& MAgreentrue == 2)

       {

        ticket = OrderSend(Symbol(),0,Lots,Bid,100,StopLossShort,Bid-10*Point*800);

        MAfilter = false;

       }       

     }

     else

     {

     if(OrderCloseTime() == 0)

     {

      

     

       if(Close[1]>MA_GREEN&& MAgreentrue == 1)

       {

        OrderClose(ticket,Lots,Ask,100);

        ticket = OrderSend(Symbol(),0,Lots,Ask,100,StopLossLong,Ask+10*Point*800);

        MAfilter = true;

       }

       if(Close[1]<MA_GREEN&& MAgreentrue == 2)

       {

        OrderClose(ticket,Lots,Bid,100);

        ticket = OrderSend(Symbol(),0,Lots,Bid,100,StopLossShort,Bid-10*Point*800);

        MAfilter = false;

       }

       if(MAchange = false && MAfilter == true)

       {

        OrderModify(ticket,Ask,StopLossLong,Ask+10*Point*800,0,Blue);

       }

       if(MAchange = false && MAfilter == false)

       {

        OrderModify(ticket,Bid,StopLossShort,Bid-10*Point*800,0,Blue);

       }

       

     }

     else

     {

      if(Close[1]>MA_GREEN&& MAgreentrue == 1)

       {

        ticket =OrderSend(Symbol(),0,Lots,Ask,100,StopLossLong,Ask+10*Point*800);

        MAfilter = true;

       }

       if(Close[1]<MA_GREEN&& MAgreentrue == 2)

       {

        ticket = OrderSend(Symbol(),0,Lots,Bid,100,StopLossShort,Bid-10*Point*800);

        MAfilter = false;

       }

       if(MAchange = false && MAfilter == true)

       {

        OrderModify(ticket,Ask,StopLossLong,Ask+10*Point*800,0,clrNONE);

       }

       if(MAchange = false && MAfilter == false)

       {

        OrderModify(ticket,Bid,StopLossShort,Bid-10*Point*800,0,clrNONE);

       }

      } 

     }   

    }

   }


 

Please print the values and verify them,

 
Marco vd Heijden:

Please print the values and verify them,


Are you asking about the errors I got?

 

You are using 0 (zero) which is equal to OP_BUY, in all your OrderSend() calls. That can not produce expected results in at lest half of the code that you posted.

The rest is similar  - maybe it would be a good idea to check here https://www.mql5.com/en/docs/trading before proceeding with any further coding

Documentation on MQL5: Trade Functions
Documentation on MQL5: Trade Functions
  • www.mql5.com
Trading functions can be used in Expert Advisors and scripts. Trading functions can be called only if in the properties of the Expert Advisor or script the "Allow live trading" checkbox is enabled.
Reason: