Hi
I'm looking for a code which closes all open orders ( long and short ) for the current pair, when one of the orders hits TP or gets manually closed
Right now i'm struggling with the spread which causes not all orders to close due to the difference, and to me adding that code could be a solution.
can anyone help me out? providing the code?
thnx
I've been over that multiple times, and i see alot of scripts passing by that closes trades when:
SL is hit
TP is hit
Time is achieved etc etc.
It all doesn't do what i need...
It needs to be a script that counts the open trades on a pair on that chart, and closes all long and short trades when the nr of the trades is below the nr of trades 2 seconds ago.The nr of trades will increase,
in basic:
10:30:00 nr of trades on pair EURGBP = 6 closeall = no
10:30:01 nr of trades on Pair EURGBP = 7 closeall = no
10:30:02 nr of trade on pair EUR GBP = 6 close all = yes
I hope you understand, as i am not a die hard programmer :P
hope anyone can help me out.
thnx
I've been over that multiple times, and i see alot of scripts passing by that closes trades when:
SL is hit
TP is hit
Time is achieved etc etc.
It all doesn't do what i need...
It needs to be a script that counts the open trades on a pair on that chart, and closes all long and short trades when the nr of the trades is below the nr of trades 2 seconds ago.The nr of trades will increase,
in basic:
10:30:00 nr of trades on pair EURGBP = 6 closeall = no
10:30:01 nr of trades on Pair EURGBP = 7 closeall = no
10:30:02 nr of trade on pair EUR GBP = 6 close all = yes
I hope you understand, as i am not a die hard programmer :P
hope anyone can help me out.
thnx
Sounds like a part time job.
Maybe you can try freelance https://www.mql5.com/en/job
was hoping anyone can help me out over here.
toch bedankt :P
//+------------------------------------------------------------------+ //| tictactoe.mq4 | //| Copyright 2016,Marco vd Heijden, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2016,Marco vd Heijden, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict int i,New,Old; bool result; double profit; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- create timer EventSetMillisecondTimer(1000); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- destroy timer EventKillTimer(); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- } //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ void OnTimer() { //--- tic New=0; for(i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) { if(OrderSymbol()==Symbol()) { New++; } } } //--- tac if(New<Old) { for(i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) { if(OrderSymbol()==Symbol()) { switch(OrderType()) { case OP_BUY: result=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5,Red); if(result==false) { Alert("Order ",OrderTicket()," failed to close. Error:",GetLastError()); } break; case OP_SELL: result=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5,Red); if(result==false) { Alert("Order ",OrderTicket()," failed to close. Error:",GetLastError()); } break; } } } } } //--- toe Old=0;profit=0; for(i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) { if(OrderSymbol()==Symbol()) { profit=profit+OrderProfit(); Old++; } } } Comment(Symbol()+" "+IntegerToString(Old)+" Orders, Profit: ",DoubleToString(profit,2)); } //+------------------------------------------------------------------+
for(i=0;i<OrdersTotal();i++)
You always have to count down or you will have some surprises.
You always have to count down or you will have some surprises.
I know.
//+------------------------------------------------------------------+ //| tictactoe.mq4 | //| Copyright 2016,Marco vd Heijden, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2016,Marco vd Heijden, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict int i,New,Old; bool result; double profit; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- create timer EventSetMillisecondTimer(1000); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- destroy timer EventKillTimer(); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- } //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ void OnTimer() { //--- tic New=0; for(i=OrdersTotal();i>0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) { if(OrderSymbol()==Symbol()) { New++; } } } //--- tac if(New<Old) { for(i=OrdersTotal();i>0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) { if(OrderSymbol()==Symbol()) { switch(OrderType()) { case OP_BUY: result=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5,Red); if(result==false) { Alert("Order ",OrderTicket()," failed to close. Error:",GetLastError()); } break; case OP_SELL: result=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5,Red); if(result==false) { Alert("Order ",OrderTicket()," failed to close. Error:",GetLastError()); } break; } } } } } //--- toe Old=0;profit=0; for(i=OrdersTotal();i>0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) { if(OrderSymbol()==Symbol()) { profit=profit+OrderProfit(); Old++; } } } Comment(Symbol()+" "+IntegerToString(Old)+" Orders, Profit: ",DoubleToString(profit,2)); } //+------------------------------------------------------------------+
I know.
for(i=OrdersTotal()-1;i>=0;i--)
OrdersTotal
Returns the number of market and pending orders.
int OrdersTotal(); |
Returned value
Total amount of market and pending orders.
Example:
int handle=FileOpen("OrdersReport.csv",FILE_WRITE|FILE_CSV,"\t"); |
Even in the reference ++ is used in many examples.
Normally i do not call the function OrdersTotal() in the for loop this was just a quick sketch to give Mr. Biesheuvel some inspiration.
I know from experience that it does not work because there is the risk not all orders get closed.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
I'm looking for a code which closes all open orders ( long and short ) for the current pair, when one of the orders hits TP or gets manually closed
Right now i'm struggling with the spread which causes not all orders to close due to the difference, and to me adding that code could be a solution.
can anyone help me out? providing the code?
thnx