ORDER SEND !

 

hi guys , do u know how this could happen? i tested my strategy in strategy tester then i expected  only one sell there but it open some sells and some buys, price didnt reach to the buy 

position even

 if(where==1)
             {
               if(Bid>bala_hemayat)
                 {
                  open(pain_hemayat,bala_moghavem2);
                  
                 }
                  if(Bid<bala_moghavem)
                 {
                  open(bala_moghavem2,pain_hemayat);
                 }
             }
              if(where==2)
             {
               if(Bid>pain_hemayat)
                 {
                  open(pain_hemayat2,bala_moghavem);
                  
                 }
                  if(Bid<pain_moghavem)
                 {
                  open(bala_moghavem,pain_hemayat2);
                  
                 }
             }
void open (double stp,double tp)
{

 if(jahat==true)
   {
    int cick =OrderSend(Symbol(),OP_BUY,lot(),Ask,0,0,0,NULL,1111,0,clrGreen);
    jahat=false;
   }
   if(jahat==false)
   {
    int tick =OrderSend(Symbol(),OP_SELL,lot(),Bid,0,0,0,NULL,2222,0,clrRed);
    jahat=true;
   }
   if(OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES))
   {
     bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),stp,tp,0,clrWhite);
     if(mod==false)
       {
        Comment(GetLastError());
       }
   }
   
}


 
ejmin ejoni:
void open (double stp,double tp)
{

 if(jahat==true)
   {
    int cick =OrderSend(Symbol(),OP_BUY,lot(),Ask,0,0,0,NULL,1111,0,clrGreen);
    jahat=false
   }
   if(jahat==false)
   {
    int tick =OrderSend(Symbol(),OP_SELL,lot(),Bid,0,0,0,NULL,2222,0,clrRed);
    jahat=true;
   }
   if(OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES))
   {
     bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),stp,tp,0,clrWhite);
     if(mod==false)
       {
        Comment(GetLastError());
       }
   }
   
}

1. You should check the returned value of OrderSend() for errors. OrderSend() returns a Ticket or -1.

2. You have 0 Slippage Tolerance; any differences in price between the request and the current market will cancel your transaction. Use 30 as a baseline. Slippage is in Points.

3. OrderSend returns a Ticket; why use OrderSelect with OrdersTotal - 1, its dangerous to do so because other trades can be open or closed meanwhile.
    Just use OrderSelect with the Ticket Number gathered above.

4. For the issue about the EA not Triggering Orders the way you expected; its really hard to tell by the code you shared. I would Print() my Trigger Logic (your first block of code) and ensure it really trade as I expect before including Trade Functions.

OrderSend - Trade Functions - MQL4 Reference
OrderSend - Trade Functions - MQL4 Reference
  • docs.mql4.com
OrderSend - Trade Functions - MQL4 Reference
 
Jeremie Courchesne #:

1. You should check the returned value of OrderSend() for errors. OrderSend() returns a Ticket or -1.

2. You have 0 Slippage Tolerance; any differences in price between the request and the current market will cancel your transaction. Use 30 as a baseline. Slippage is in Points.

3. OrderSend returns a Ticket; why use OrderSelect with OrdersTotal - 1, its dangerous to do so because other trades can be open or closed meanwhile.
    Just use OrderSelect with the Ticket Number gathered above.

4. For the issue about the EA not Triggering Orders the way you expected; its really hard to tell by the code you shared. I would Print() my Trigger Logic (your first block of code) and ensure it really trade as I expect before including Trade Functions.

thank u bro, i solve it. i didnt notice to the spread and thank u for your addition explains 

Reason: