Download MetaTrader 5

Need Help with OrderModify Coding

To add comments, please log in or register
ThemBonez
37
ThemBonez  

In my EA, I am placing a pending stop order to enter based on indicator criteria.

If after placing the pending order, price moves against me, I want to modify my pending entry price to the high/low (depending on Long/Short) of the last bar.

I am getting errors 4108 and 4501 and can't figure out why.

Can someone look at my code for my order modification and let me know what I am doing wrong?   Thank You


     if (Mas_Tip[0]==0 && Mas_Tip[4]==1 &&
         Bid > High[1])  //Is Order BuyStop (Mas_Tip[4]==1)
         {int ModTicket=OrderSelect(Ticket,SELECT_BY_TICKET);
         
          LowestBar = iLowest(Symbol(),PeriodLong,MODE_LOW,RSI_Length_L,1);
         StopLoss = Low[LowestBar]-10*UsePoint;
         SL=StopLoss;      // StopLoss   
           Price=High[1]+5*UsePoint;
         Open_Modify=OrderModify(ModTicket,Price,SL,0,0,0);
            if(Open_Modify == false) 
                 Print("Error modifying long entry ", Ticket, " Err#:", GetLastError());
         }
       if (Mas_Tip[1]==0 && Mas_Tip[5]==1 &&
         Ask < Low[1])   Is Order SellStop(Mas_Tip[5]==1) 
        {ModTicket=OrderSelect(Ticket,SELECT_BY_TICKET);
      
          HighestBar = iHighest(Symbol(),PeriodLong,MODE_HIGH,RSI_Length_L,1);
         StopLoss = High[HighestBar]+10*UsePoint;
          SL= StopLoss;      // StopLoss  
         Price=Low[1]-5*UsePoint;
         Open_Modify=OrderModify(ModTicket,Price,SL,0,0,0);
            if(Open_Modify == false) 
                 Print("Error modifying short entry ", Ticket, " Err#:", GetLastError());
         }
Alain Verleyen
Moderator
31476
Alain Verleyen  

OrderSelect returns a bool, not a ticket number.

Error 4501 ? Are you sure, this error doesn't exist in documentation.

whroeder1
15026
whroeder1  
angevoyageur: Error 4501 ? Are you sure, this error doesn't exist in documentation.
Appears only here GlobalVariableSetOnCondition - MQL4 Documentation
Raffaele
3
Raffaele  

ERR_GLOBALVARIABLE_NOT_FOUND (4501)

 

I guess just looking like this.. where you declare:

 

int ModTicket=OrderSelect(Ticket,SELECT_BY_TICKET);

 

You should re-declare afterwards where you do it on the second if:

 

// Replace: ModTicket=OrderSelect(Ticket,SELECT_BY_TICKET); 

int ModTicket=OrderSelect(Ticket,SELECT_BY_TICKET);
Alain Verleyen
Moderator
31476
Alain Verleyen  
WHRoeder:
angevoyageur: Error 4501 ? Are you sure, this error doesn't exist in documentation.
Appears only here GlobalVariableSetOnCondition - MQL4 Documentation

Ah, I missed that.

Thank you.

To add comments, please log in or register