Help me! Why doesn't ea stop?

 
Help me, pls!
//+------------------------------------------------------------------+
//|                                                         Test.mq4 |
//|                                                       Nguyen Huy |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Nguyen Huy"
#property link      ""
extern bool Nonstop = False;
extern int TimeSleep = 0;
extern int LimitOrders = 5;
extern double VolumeOrder = 0.01;
extern int TakeProfit = 15;
extern int StopLoss = 150;

int start()
        {
          if(Nonstop == False)
         {
            for(int i=0;i<LimitOrders;i++)
               {
               OrderSend(Symbol(),OP_BUY,VolumeOrder,Ask,2,Ask-150*Point,Ask+TakeProfit*Point,NULL,0,0,NULL);
                                   OrderSend(Symbol(),OP_SELL,VolumeOrder,Bid,2,Bid+150*Point,Bid-TakeProfit*Point,NULL,0,0,NULL);
                                   }
              }
          else
                        {
                                OrderSend(Symbol(),OP_BUY,VolumeOrder,Ask,2,Ask-StopLoss*Point,Ask+TakeProfit*Point,NULL,0,0,NULL);
                                OrderSend(Symbol(),OP_SELL,VolumeOrder,Bid,2,Bid+StopLoss*Point,Bid-TakeProfit*Point,NULL,0,0,NULL);
                                Sleep(TimeSleep);
                        }
   }
        
 

Why doesn't ea stop?

start(){ open orders; sleep; return}

Each tick will open 2 more orders. Why do you expect anything else?

 
I expect the Ea will stop after it repeated 5 times but it didn't stop. I don't know why it didn't stop. Can you help me?
 
HuyTitan:
I expect the Ea will stop after it repeated 5 times but it didn't stop. I don't know why it didn't stop. Can you help me?
The start() function is called on each incoming tick. See here -> https://docs.mql4.com/runtime/start.
 

So you will get 5 orders per tick...

See a typical complete EA https://www.mql5.com/en/code/8714

as an example for controlling number of orders

-BB-

 
Tks! Everyone
 

i hope you didnt run that on your trading account ...

 
HuyTitan:
Help me, pls!

You should cap it off with this

//----

return(0);

}

//+------------------------------------------------------------------+

Reason: