Download MetaTrader 5

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

To add comments, please log in or register
zmdfwh001
13
zmdfwh001  

 

 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
Irwan Adnan
932
Irwan Adnan  
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
honest_knave
Moderator
2322
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.

Fxcanman
5
Fxcanman  

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.

Irwan Adnan
932
Irwan Adnan  
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.
zmdfwh001
13
zmdfwh001  
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?
whroeder1
16764
whroeder1  
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.
To add comments, please log in or register