Can anyone look into this code and find out why it doesn't work out after it's inserted?

 

 

 extern double Profit==0.005    

    int cnt;    

    total=OrdersTotal();

   //Close all

    if(AccountProfit()/AccountBalance() >= Profit){
    
    for(cnt=total-1;cnt>=0;cnt--)
    {
       OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
   
     if(OrderType()==OP_SELL)
    {
       OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);
    }
    
     if(OrderType()==OP_BUY)
    {
       OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);
    }
  }
 return(0);
 }

What I want to do is to close all positions when the profit reached a certain percentage and I am editing based on grid trading system, but somehow after I inserted these lines of code, the backtest doesn't work out like the way it should be and the history looks like the picture in the attached file. Can anyone help me edit these lines of code to realize this function or tell me how to fix this problem? Thanks a lot.

Files:
4s.JPG  71 kb
 
zmdfwh001:

 

What I want to do is to close all positions when the profit reached a certain percentage and I am editing based on grid trading system, but somehow after I inserted these lines of code, the backtest doesn't work out like the way it should be and the history looks like the picture in the attached file. Can anyone help me edit these lines of code to realize this function or tell me how to fix this problem? Thanks a lot.


From the pic, it is already close all orders (1,2,3,and 4) at same time., right? If not, what actually your problem
 

You opened 2 buys and 2 sells within 4 pips of each other.

Those positions never made it to a combined 0.5% profit, so they stayed open throughout your test.

At the end of the test, any open positions are closed.

 

hi, Please may i ask if there is a script that automatically inserts a preset SL whenever a Manual instant execution trade is taken? Many times I got caught in a rally even before I am able to set the SL.

 
honest_knave:

You opened 2 buys and 2 sells within 4 pips of each other.

Those positions never made it to a combined 0.5% profit, so they stayed open throughout your test.

At the end of the test, any open positions are closed.


You are right ... I am not conscientious.
 
honest_knave:

You opened 2 buys and 2 sells within 4 pips of each other.

Those positions never made it to a combined 0.5% profit, so they stayed open throughout your test.

At the end of the test, any open positions are closed.


Thanks for your help, but I lowered the profit to 0.1% and it's still the same. Can this be possible?
 
honest_knave: Those positions never made it to a combined 0.5% profit, so they stayed open throughout your test.
Your question was already answered. Of course it is possible, hedging trades cancel each other.
Reason: