- David Salem: I need to set the counter on 0 every time I close a trade...
static int counter=0; static int nTrades=0; int prevTrades=nTrades; nTrades=OrdersTotal(); if(nTrades < prevTrades) counter=0; // A trade closed.
-
if(hour!=iTime(NULL, PERIOD_H1,0)) {counter++; hour=iTime(NULL, PERIOD_H1,0)II
How To Ask Questions The Smart Way. (2004)
The XY ProblemNo need for a counter; just compute how many bars has passed.
if(OrderSelect(orderID,SELECT_BY_TICKET)){ int counter = iBarShift(_Symbol, _Period, OrderOpenTime();
-
Remember:
-
If you select by ticket, you must check if the order has closed.
-
EAs must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global ticket variables will have been lost. You will have an open order but don't know it, so the EA will never try to close it, trail SL, etc. How are you going to recover?
Use a OrderSelect / Position select loop to recover, or persistent storage (GV+flush or files) of ticket numbers required.
-
-
How To Ask Questions The Smart Way. (2004)
The XY ProblemNo need for a counter; just compute how many bars has passed.
-
Remember:
-
If you select by ticket, you must check if the order has closed.
-
EAs must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global ticket variables will have been lost. You will have an open order but don't know it, so the EA will never try to close it, trail SL, etc. How are you going to recover?
Use a OrderSelect / Position select loop to recover, or persistent storage (GV+flush or files) of ticket numbers required.
-
Hey William, thanks for ur reply.
Im pretty new coding and with my scarce resources im trying to make an EA. I take all the scenarios you are mentioned and will try to think in something else!
Again thanks for ur time!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I need to set the counter on 0 every time I close a trade...
I tried to do this... but i think when the trade close, also the if statement...
Thanks for the help.