Download MetaTrader 5
To add comments, please log in or register
Use the Pocket to paste your content. It is convenient!
Tsering Dawa Lama
260
Tsering Dawa Lama 2014.09.07 11:44 

HOW TO CLOSE all the remaining openorders of the same symbol when the first trade is closed?

Here is the ordersend for the first trade with unique takeprofit and comment. OrderSend(Symbol(),0,b_lot,Ask,3,0,Ask+tp,"L"+1,magic,0,Blue);

i thought for a long time but could not find a way. best way i guess is to use the unique comment L1 with orderselect. the idea or logic is that if the trade with comment L1 is not found in the opentrades then all the other trades of the same symbol should be closed. trade one is closed because takeprofit is hit. the other trades cannot be assigned with the same takeprofit unfortunately. i could not write the code for how to do that. can anybody help me please. thanks

Keith Watford
Moderator
7948
Keith Watford 2014.09.07 12:36  

Not compiled or tested and no error checking

  
  string gvname="First"+Symbol()+(string)magic;
  
  int ticket = OrderSend(Symbol(),0,b_lot,Ask,3,0,Ask+tp,"L"+(string)1,magic,0,Blue);
  if(ticket>0)
     {
     GlobalVariableSet(gvname,ticket);
     GlobalVariablesFlush();     
     }
  //
  //
  //
  //
  if(OrderSelect((int)GlobalVariableGet(gvname),SELECT_BY_TICKET))
     {
     if(OrderCloseTime()!=0)
        {
        //CloseAllOrders
        }
     }
Tsering Dawa Lama
260
Tsering Dawa Lama 2014.09.08 12:28  
GumRai:

Not compiled or tested and no error checking

 



thanks gumrai, but its not working. ea opens too many trades at the same time
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.09.08 14:11  

Other options ...

https://www.mql5.com/en/job

Keith Watford
Moderator
7948
Keith Watford 2014.09.08 21:34  
tsedawa:


thanks gumrai, but its not working. ea opens too many trades at the same time

Your query was

HOW TO CLOSE all the remaining openorders of the same symbol when the first trade is closed? 

 not

How to prevent the EA from opening too many orders at the same time. 

Tsering Dawa Lama
260
Tsering Dawa Lama 2014.09.11 16:01  
GumRai:

Your query was

HOW TO CLOSE all the remaining openorders of the same symbol when the first trade is closed? 

 not

How to prevent the EA from opening too many orders at the same time. 

 

 



i dont know why but when i remove your code ea works fine but when i put your code the ea sends multiple trades
Keith Watford
Moderator
7948
Keith Watford 2014.09.13 01:35  
tsedawa:


i dont know why but when i remove your code ea works fine but when i put your code the ea sends multiple trades


You didn't just copy and paste my example code straight into the EA did you?

It was an example. You need to combine it with your code. 

  string gvname="First"+Symbol()+(string)magic;
  
  //Your code to calculate whether to send and order and not to open a repeat order

  int ticket = Your OrderSend
  if(ticket>0)
     {
     GlobalVariableSet(gvname,ticket);
     GlobalVariablesFlush();     
     }
  //
  //
  //
  //
  if(OrderSelect((int)GlobalVariableGet(gvname),SELECT_BY_TICKET))
     {
     if(OrderCloseTime()!=0)
        {
        //Your code to CloseAllOrders
        }
     }
/
To add comments, please log in or register