EA not to open a trade at bar it has closed a trade

 

Hi,

I guess this is an easy common question: How can I tell the EA to not open a trade in a bar where it has closed a trade at void OnTick?

It is opening with if(CountTrades()<1) but I cannot add if(IsNewCandle()), as it does not open trades.

I have tried this but it opens either way

int BarsCount = 0;
if (Bars>BarsCount) {
Do the algo and then
BarsCount = Bars;
}

Kindest regards

 

Algorithm: opened a position -> remembered the opening time of the bar.

If you want to open a new position, compare the saved time with the opening time of the current bar.

 
  1. YThi MJ: I guess this is an easy common question: How can I tell the EA to not open a trade in a bar where it has closed a trade at void OnTick?

    You don't know how to code, but the changes are easy? That's like saying "I don't know how to build engines but adding another cylinder should be easy; it's just one more."
              Is it easy (or difficult) to …? - General - MQL5 programming forum #2 2017.08.31

  2. You code it that way. Perhaps you save the bar time when you close and check the saved versus current bar time before opening?

  3. 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.
              Running EA once at the start of each bar - MQL4 programming forum 2011.05.06

Reason: