Need Help with OrderModify Coding

 

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());
         }
 

OrderSelect returns a bool, not a ticket number.

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

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

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);
 
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.