Download MetaTrader 5

Is there any free script to close trade with with comment

To add comments, please log in or register
1000 paid orders are executed in Freelance service. Sign up!
Abd Almouhemen Haj Madoun
506
Abd Almouhemen Haj Madoun 2015.07.14 21:40 
Hello i need any script to close trade have same comments ? as you see in the image attachment i have trades with comment H1 and others with comment H2 What i am looking for to close all trades with comment H1 only and keep trades with comment H2 open
Files:
comment.jpg 23 kb
Marco vd Heijden
Moderator
4704
Marco vd Heijden 2015.07.14 21:54  
if(OrderComment()=="H1")
 {
  //Do something
 }

else if(OrderComment()=="H2")
 {
  //Do something else
 }
Osama Shaban
1448
Osama Shaban 2015.07.15 01:55  

Salam, Brother Abd Almouhemen ... Remember me ?

No problem, it can be done, Insha Allah ...

Give me an hour or less and I will post it here ...

Osama Shaban
1448
Osama Shaban 2015.07.15 02:12  

Here we go ...

The code is not tested, but it should work ...

It closes all type of orders ... Market + Pendings.

You need to specify the comment of the orders to close once you drag the script on chart.

 Let me know if there is any trouble 1.

#property copyright "Copyright © 2015, http://oshaban.blogspot.com"
#property link      "Email: shabano@gmail.com"

#property show_inputs

input string Comment_to_close = "H1";

int start(){

   for(int i=OrdersTotal()-1;i>=0;i--){
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         continue;
      
      RefreshRates();
      
      if(OrderType()==OP_BUY && OrderComment()==Comment_to_close)           
         bool res1 = OrderClose(OrderTicket(),OrderLots(),Bid, 3,White);
      if(OrderType()==OP_SELL && OrderComment()==Comment_to_close)    
         bool res2 = OrderClose(OrderTicket(),OrderLots(),Ask, 3,White);
      
         
      if((OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT || OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT) && OrderComment()==Comment_to_close)
         bool res4 = OrderDelete(OrderTicket());
   }   
   return(0);
  }
Abd Almouhemen Haj Madoun
506
Abd Almouhemen Haj Madoun 2015.07.16 12:02  
Osama Shaban:

Here we go ...

The code is not tested, but it should work ...

It closes all type of orders ... Market + Pendings.

You need to specify the comment of the orders to close once you drag the script on chart.

 Let me know if there is any trouble 1.

Salam How are you 

Where are you Bro

can you send your contact details pleas

To add comments, please log in or register