How do I code a trade only once per bar.
I cannot seem to get it
The main thing in this approach is to remember and compare the opening time of the bar.
For example: you have issued a trade order -> until you receive confirmation of the operation, you cannot issue a new trade order -> if you have received confirmation (POSITION was opened), remember the opening time of the bar (iTime (...)
Before issuing a new trade order, compare the saved time and the opening time of the current bar -> if they are equal, then a trade order cannot be issued.
- Or test for a new bar.
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
New candle - MQL4 programming forum #3 2014.04.04I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
-
Or remember the last bar time you opened a trade. Test for it before opening another.
-
"Doesn't work" is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
How To Ask Questions The Smart Way. 2004
When asking about codeDo you really expect an answer? There are no mind readers here and our crystal balls are cracked.
How To Ask Questions The Smart Way. 2004
Be precise and informative about your problemWe can't see your broken code.
Fix your broken code.
With the information you've provided — we can only guess. And you haven't provided any information for that.
if(iTime(NULL,NULL,0)==TimeCurrent()){
This doesnt seem to work either. I still place thousands of trades and its destroying all my working strategies
- Of course, it doesn't work. What part of "remember the last bar time you opened a trade" was unclear to you? If you aren't going to follow instructions, why are you posting? You are certainly not thinking.
- Don't use NULL.
- On MT4, you can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not. OrderSend does not.
- Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
- Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
- MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
- Cloud Protector Bug? - MQL4 programming forum 2020.07.25
I cant find any helpful tools on how to fix this.

- 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 cannot seem to get it