Demo Vs Live difference! need help please!

 

Dears friends,

i have checked the following EA both on demo and live. In demo it works fine. But in live account it opens over 30 pending orders at one go at the same price and time and they all get executed when the price is reached. i have tried every possible settings from the input parameters. it did not work. please help me find out where the error is in the code. thanks in advance

Files:
stopahunter.mq4  16 kb
 

count_position() incompatible with multiple charts or multiple EAs/manual trading.

Beyond that add your print statements and find out why.

 
tsedawa:

Dears friends,

i have checked the following EA both on demo and live. In demo it works fine. But in live account it opens over 30 pending orders at one go at the same price and time and they all get executed when the price is reached. i have tried every possible settings from the input parameters. it did not work. please help me find out where the error is in the code. thanks in advance



i have to edit my problem, sorry. i mean strategy tester not demo.
 
tsedawa:

i have to edit my problem, sorry. i mean strategy tester not demo.

Why break ? why not continue ?

//--------
void count_position()
{
    POS_n_BUY  = 0;
    POS_n_SELL = 0;
    
    POS_n_BUYSTOP = 0;
    POS_n_SELLSTOP = 0;
    
    for( int i = 0 ; i < OrdersTotal() ; i++ ){
        if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) == false || OrderMagicNumber() != magic){
            break;                                                                                   //  why ?
        }
 
RaptorUK:

Why break ? why not continue ?


thankyou RaptorUk. i will try that.
 
RaptorUK:

Why break ? why not continue ?


i have no idea! but i will try continue instead of break, thank you Raptor.
 
RaptorUK:

Why break ? why not continue ?


so far it looks like u r right! i tried continue and it worked fine. then i changed back to break and it started opening many buystops. then again i changed back to continue and its behaving nicely. thanks a lot RaptorUK, u saved me.
Reason: