script stops executing automatically

 

Hi, I'm playing around with scripts, and I have the following -very useless- script (for testing). T

int start()
{
for (int i = 0; i < 200; i++)
{
OrderSend(Symbol(), OP_BUY, 0.01, Ask, 0, Ask-500*Point, Ask+500*Point);
}

return(0);

}

Obviously, this is supposed to create 200 orders. However, after about 10 orders, the script is exited. No errors or warnings, simply exited with the message "script: useless_script EURUSD,H1: removed

Anybody have an idea why this happens? The script is exited before the for-loop ends.

Thanks


 

Try sleeping it each cycle Sleep(100); for fastest solution.

Otherwise GetLastError() will tell you what went wrong.

 
  1. GetLastError() will tell you what went wrong. Always log errors.
            oo.ticket = OrderSend(  Symbol(),   op.code,    size,
                    now.open,       Slippage.Pips*pips2points,
                    NO_SL,          NO_TP,          order.comment,
                    magic.number,   NO_EXPIRATION,  op.color);
            if (oo.ticket < 0){     Alert( "OrderSend(type=",   op.code,
                " (",   op.text,    "), lots=", size,
                ", price=", PriceToStr(now.open),
                " (", DeltaToPips(now.open-Bid),
                "), SL=0, TP=0, '", order.comment, "', ...) failed: ",
                                                    GetLastError() );
    
  2. Sending many orders that fast will return ERR_TOO_FREQUENT_REQUESTS. Adding a sleep would help. Some brokers have a maximum order count of 100.
  3. You MUST RefreshRates() between any two server calls or after sleep