Only trade once per bar

 
How do I code a trade only once per bar. 
I cannot seem to get it
 
micobez :
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.

 
micobez: How do I code a trade only once per bar.  I cannot seem to get it
  1. 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.04

    I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.

  2. Or remember the last bar time you opened a trade. Test for it before opening another.

  3. "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 code

    Do 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 problem

    We 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

 
  1. 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.
  2. Don't use NULL.
    1. 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.
    2. 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.
    3. Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
    4. MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
    5. Cloud Protector Bug? - MQL4 programming forum 2020.07.25
 
I tried to use the NewBar code lines from the study however it still just places 100s of trades without only iterating once. 
I cant find any helpful tools on how to fix this.
Reason: