script is skipping code

 

I'm creating my first scripts.

I created an "include" file, that has a function that places an order (int PlaceOrder()), and a script (PlaceBuyOrder()) that calls PlaceOrder() in the included file. It works fine unless I run the script a 2nd time while the "OrderSend()" is still on the screen. The 2nd time I run PlaceBuyOrder() it just skips over the section in PlaceOrder() that is supposed to wait until the OrderSend() is closed. I put some Alerts in to show me what is going on.

int PlaceOrder()
   {
      string sOrdering = "ggbOrdering";
      int ERR_GLOBAL_VARIABLE_NOT_FOUND = 4058;            
      if (!GlobalVariableCheck(sOrdering))
         GlobalVariableSet(sOrdering,0);
      // my Code

Alert("1)  " + GlobalVariableGet(sOrdering));               
            while(!IsStopped())
               {
                  if (GlobalVariableSetOnCondition(sOrdering,1,0) == true)
                     break;
                  if (GetLastError() == ERR_GLOBAL_VARIABLE_NOT_FOUND)  
                     return(0);
                  Sleep(500);
               }
Alert("2)  " + GlobalVariableGet(sOrdering));               
            OrderSend(sSymbol,iType,dLots,dPrice,iSlippage,dSL,dTP,sType,iMagic,dtExpire,DodgerBlue);
            GlobalVariableSet(sOrdering,0);
Alert("3)  " + GlobalVariableGet(sOrdering));               
   }


When I run PlaceBuyOrder() the first time, my Alerts are:

1) 0

2) 1

then the OrderSend() window comes up (the 3rd Alert waits until I close the OrderSend() window, just like I expect). I run PlaceBuyOrder again while the OrderSend() window is still on my screen and it goes right to MT4's message asking me if I really want to close the Buy Order to do the next Buy Order. I never get the Alerts. The 2nd run just skips over all my code that is supposed to have it wait until the OrderSend() window is closed.


What am I doing wrong?

 

Your code is similar to mine

Try having Two charts open and drag the script to the second chart

 
WHRoeder:

Your code is similar to mine

Try having Two charts open and drag the script to the second chart

Thanks. It never occurred to me during testing to run the script on 2 different pairs. That makes a little sense, but I would still like to know why it skipped over my Alerts when I ran it the 2nd time on the same pair.
Reason: