Remember the time when you lost, open only when current time elapsed 60 seconds.
datetime TimeLastLoss=0; void OnTick() { if(CheckForALossTrade()) TimeLastLoss=TimeCurrent(); if(TimeCurrent()-TimeLastLoss>60) CheckForOpeningATrade(); }
Thank you lippmaje but I don't know how remember the time when lost. Could you help me if you have little bit time?
The code sample above contains all you need to know to fix your EA. If you are not sure how to do it consider asking a freelancer in the job section.
Alican Selcuk:
Hi. I am trying to add delay between 2 trades after a loss trade without use sleep(). How can I do this?
ex: wait 60 second for open a new trade after a lost trade
#define ALL_SYMBOLS "ALL-SYMBOLS" #define ALL_MAGICS INT_MAX void OnStart() { if (cool_down_after_loss(60)) Print("Can trade!"); } bool cool_down_after_loss(const int seconds, const string symbol=ALL_SYMBOLS, const int magic=ALL_MAGICS) { datetime time = WRONG_VALUE; for (int i=OrdersHistoryTotal()-1; i>=0; --i) { if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && OrderType() < 2 && (symbol == ALL_SYMBOLS || symbol == OrderSymbol()) && (magic == ALL_MAGICS || magic == OrderMagicNumber()) && (time == WRONG_VALUE || OrderCloseTime() > time) ){ time = OrderCloseTime(); } } return (TimeCurrent() - time >= seconds); }
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 am trying to add delay between 2 trades after a loss trade without use sleep(). How can I do this?
ex: wait 60 second for open a new trade after a lost trade