Please edit your post and
use the code button (Alt+S) when pasting code
Keith Watford:
Thank you for the help, and can you answer my question?
Please edit your post and
use the code button (Alt+S) when pasting code
hoangnam009:
Hi. I have a code of close all order and I want, after close all, EA will stop for a certain period of time. someone help me?
Sleep()
//+------------------------------------------------------------------+ //| Haskayafx Finance Company | //| http://www.haskayayazilim.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2005-2020, HaskayaFx Yazılım" #property link "http://www.haskayayazilim.net" #property version "1.0" #property strict input int BeklemeZamani=5000;// Waiting Time Use 1,000 for 1 second //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- CloseOrders(); Sleep(BeklemeZamani); ExpertRemove(); } //+------------------------------------------------------------------+ int CloseOrders() { int total = OrdersTotal(); for(int i=total-1;i>=0;i--) { bool rst=OrderSelect(i, SELECT_BY_POS); int type = OrderType(); bool result = false; switch(type) { //Close opened long positions case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, CLR_NONE ); break; //Close opened short positions case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, CLR_NONE ); break; //Close pending orders case OP_BUYLIMIT : case OP_BUYSTOP : case OP_SELLLIMIT : case OP_SELLSTOP : result = OrderDelete( OrderTicket() ); } if(result == false) { if (GetLastError()>0) Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() ); Sleep(3000); } } return(0); }
Mehmet Bastem:
Thanks for your help, is there any other option besides choosing ExpertRemove? eg EA paused for 3 hours.
hoangnam009:
Thanks for your help, is there any other option besides choosing ExpertRemove? eg EA paused for 3 hours.
Thanks for your help, is there any other option besides choosing ExpertRemove? eg EA paused for 3 hours.
For this you need to use GlobalVariableSet and GlobalVariableGet or be followed from the last closed order. (OrdersHistoryTotal ())
//+------------------------------------------------------------------+ //| Haskayafx Finance Company | //| http://www.haskayayazilim.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2005-2020, HaskayaFx Yazılım" #property link "http://www.haskayayazilim.net" #property version "1.0" #property strict input int DelayMinute=30;// Waiting Time Minutes //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- CloseOrders(); Sleep(DelayMinute*60000); } //+------------------------------------------------------------------+ int CloseOrders() { int total = OrdersTotal(); for(int i=total-1;i>=0;i--) { bool rst=OrderSelect(i, SELECT_BY_POS); int type = OrderType(); bool result = false; switch(type) { //Close opened long positions case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, CLR_NONE ); break; //Close opened short positions case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, CLR_NONE ); break; //Close pending orders case OP_BUYLIMIT : case OP_BUYSTOP : case OP_SELLLIMIT : case OP_SELLSTOP : result = OrderDelete( OrderTicket() ); } if(result == false) { if (GetLastError()>0) Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() ); Sleep(3000); } } return(0); }
Mehmet Bastem:
thank you very much!!!

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi. I have a code of close all order and I want, after close all, EA will stop for a certain period of time. someone help me?