Need Help With Modify Pending Orders. Anyone?

 

Hello to whoever is reading this. Hope that someone out that is able to help me with this. Kinda Beginner myself.

I was hoping to create a script that does 2 pending order after i double click it. But this script that i wrote only opens the pending order but doesnt modify it. Hope that there is someone can help me add those codes that is missing. Havent been able to figure out how to code for the 2nd pending order though. Coz there is no error and my MT4 doesnt shows me any errors also. Need to work on ECN brokers.

//+------------------------------------------------------------------+
//|                                                 BuyPendingECN.mq4 |
//|                      Copyright ?2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
#property show_confirm

//+------------------------------------------------------------------+
//| script "send pending order with expiration data"                 |
//+------------------------------------------------------------------+
int start()
  {
   int    BuyPendTicket1 = -1,Expiration;
   int    MagicNumberEnt1 = 111;
   int    BuyPendPrice = Ask;
   
   double PFEP = 15;
   double StopLoss = 10;
   double TakeProfit = 20;
   double EntPoint;
//----
   EntPoint = PipPoint(Symbol());//MarketInfo(Symbol(),MODE_POINT);
   Expiration = 0;
//----
//   while(true)
     while(BuyPendTicket1 < 0)
     {
      BuyPendTicket1=OrderSend(Symbol(),OP_BUYSTOP,1.0,Ask+PFEP*EntPoint,0,0,0,"some comment",MagicNumberEnt1,Expiration,Lime);
      
      if (BuyPendTicket1 <= 0)
         
         Print ("Error = ",GetLastError());   
                 
      else 
         {  
            OrderSelect(BuyPendTicket1,SELECT_BY_TICKET);
            
            BuyPendPrice = OrderOpenPrice();
            
            double StopLevel = MarketInfo(Symbol(),MODE_STOPLEVEL * (Ask+PFEP*EntPoint));
            
            RefreshRates();
            double UpperStopLevel = Ask + StopLevel;
            double LowerStopLevel = Bid - StopLevel;
            
            double MinStop = 5 * EntPoint;
            
            double BuyPendSL, BuyPendTP;
            
            if(StopLoss > 0) BuyPendSL = BuyPendPrice - (StopLoss * EntPoint);
            if(TakeProfit > 0) BuyPendTP = BuyPendPrice + (TakeProfit * EntPoint);
// Wong place         }   
            if(BuyPendSL > 0 && BuyPendSL > LowerStopLevel)
               {
                  BuyPendSL = LowerStopLevel - MinStop;
               }
            if(BuyPendTP > 0 && BuyPendTP < UpperStopLevel)
               {
                  BuyPendTP = UpperStopLevel + MinStop;
               }
               
            if(IsTradeContextBusy()) Sleep(10);
            
            if(BuyPendSL > 0 || BuyPendTP > 0)
               {
// Added code to make sure order is modified
                  bool TicketMod = false;
                  while (TicketMod == false)
                  {
                     TicketMod = OrderModify(BuyPendTicket1,BuyPendPrice,BuyPendSL,BuyPendTP,0);
                  }
               }
// If using while (true) you need to add break; here to exit the while loop
// You reach this point only if the trade was placed
          }     
           
                    
            
      //---- 10 seconds wait
      Sleep(10000);
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

double PipPoint(string Currency)
   {
      int CalcDigits = MarketInfo(Currency,MODE_DIGITS);
      if(CalcDigits == 2 || CalcDigits == 3) double CalcPoint = 0.01;
      else if(CalcDigits == 4 || CalcDigits == 5) CalcPoint = 0.0001;
      return(CalcPoint);
   }

2 Pending orders

Both 15 pips away from price.

1st has a SL of 15 TP of 20

2nd has a SL of 15 Trail of 20

Anyone out there able to help me.....Thanks in advance.

 

A script runs once . . . and EA has it's start function run for each tick. Is this a Script or an EA ?

Why aren't you checking and printing any error generated as a result of the OrderModify ?

 
RaptorUK:

A script runs once . . . and EA has it's start function run for each tick. Is this a Script or an EA ?

Why aren't you checking and printing any error generated as a result of the OrderModify ?


Ummm.....to tell u the truth. Im a noob.....lol started. Still dont quite sure where to put which important codes. All i know that there is no error when i compile this script. So i really dont know what went wrong. Only after i try the script on the chart....i saw uninit error 0 marketinfo something like that.
 
Spawn1980:

Only after i try the script on the chart....i saw uninit error 0 marketinfo something like that.

Ah . . . this is the problem.

double StopLevel = MarketInfo(Symbol(),MODE_STOPLEVEL * (Ask+PFEP*EntPoint));

what are you trying to do here ?

 
RaptorUK:

Ah . . . this is the problem.

what are you trying to do here ?


Seriously......i dont know. lol.....was trying all sorts of way. Forgive my stupidity.....ive just started no longer den a mth. I thought of at least writing my first script before i move on to writing an EA.....but i guess what i want to achieve is kinda too far stretch for me.

Still not sure how to do a 2 pending order with 1 to modify the SL and TP....the other to modify the SL and add in trailing.....sigh.....

Any Advice for a newbie like me?

 
Spawn1980:


Seriously......i dont know.

Well how do you expect anyone to help you do something when you don't know what it is you are trying to do . . . I can only help with the syntax so far . . . didn't you write this code ?
 
I think i need to rephrase that. lol.....what i meant was. Coz there is no error when compiling and i dont know how to solve the uninit 0 marketinfo issue....so i dont know what changes to make to the script in order to let it modify the pending orders.
 
OK, I'll rephrase my question . . . what is StopLevel supposed to equal ?
 
Ummm.....the amount of pips away from the price by indiviidual broker?
 

If you just want stoplevel all you need is this . ..

double StopLevel = MarketInfo(Symbol(),MODE_STOPLEVEL);

if you want it as a price do this . . .

double StopLevel = MarketInfo(Symbol(),MODE_STOPLEVEL) * EntPoint;
 
But that still doesnt makes the script changes the SL and TP for the pending order rite?
Reason: