Every n bars pass once at the start when it shouldnt
-
Hi,
I'm using the block Every "n" bars in my project, and it seems the first time it is executed, it will pass no matter the number of bars. I use it in live mode not in backtest mode.
After that, if it is executed again, then it seems to work as expected.Here is a little test i made:
https://fxdreema.com/shared/RAe5HW65cThe EA displays a message "2 bars counted" every 2 bars.
I ran it on the 1M chart, and as you can see, the message is displayed as soon as the EA is started.
Then the message is displayed every 2 minutes as intended.
When i check the code, it seems the value bartime is set to 0, therefore this condition will always set pass to true:

Does it work as intended or am i mistaken somewhere? Can you fix this ?
Thank you in advance,
Valentin -
@vhager Firstly, that 'pass' block is unnecessary. You can remove it. Then I'm not completely sure what you exactly need. If I understand it correctly, you want a log to be printed once every two candles. Correct? If so, you will not get it the way you did it, because those blocks are on the 'on tick' tab. This means every tick both blocks will be executed no matter what. You need to add a 'once per bar' block on top for that to be checked just once every time a new bar is created. However, I guess that will no be enough because you will need additional conditions to be checked, right?
-
Hi,
Thank you for your reply.Yes I understand about the on tick tab, that it will trigger only if there is a tick happening, in this case, I'm using EURUSD on regular hours, so I'm pretty sure, there will be at least one tick on the 1 minute chart.
This example is merely just to show about the block Every "n" bar.My expectation, is this block shouldn't pass until "n" bars have been detected, right? To demonstrate that, i ran a small EA:
If i set n = 2, then it should not pass on the first bar, because the block only detected one bar (the bar where it was executed), then when the next bar arrives, on the tick event, the block now counts a second bar, and now it should pass.
This is confirmed in the log, as you can see the EA passes every two bars.The issue I have is why the block Every N bars, passes as soon as the EA is executed for the first time. It hasn't detected two bars yet, so it shouldn't pass.
If you see the log, at 12:24:30.484 the EA is initialized, then at 12:24:30.546 the message "2 bars counted" is displayed. This message shouldn't appear, as two bars should not have been detected.That's why i think there is a bug in the Every N bars block.
-
@vhager said in Every n bars pass once at the start when it shouldnt:
Hi,
I'm using the block Every "n" bars in my project, and it seems the first time it is executed, it will pass no matter the number of bars. I use it in live mode not in backtest mode.
After that, if it is executed again, then it seems to work as expected.Here is a little test i made:
https://fxdreema.com/shared/RAe5HW65cThe EA displays a message "2 bars counted" every 2 bars.
I ran it on the 1M chart, and as you can see, the message is displayed as soon as the EA is started.
Then the message is displayed every 2 minutes as intended.
When i check the code, it seems the value bartime is set to 0, therefore this condition will always set pass to true:

Does it work as intended or am i mistaken somewhere? Can you fix this ?
Thank you in advance,
ValentinYou could create a variable counting candles, and place a condition like this:

-
@vhager Didn't tried that exercise. Maybe you're right. I recomnend you should contact the admin to let him know.
-
Hi,
Thank you both for your help.
I'm indeed passing by this bug with the use of variables.How to contact the admin ? do they fix this kind of bugs ?
-
@vhager It's not a bug. Eg.: If you use "once per bar", should you start counting the current candle right? This is because in the candle ID1 maybe we have a triggered condition, so a possible trade failure because we have not counted the current candle. If you don't want to count the first candle simply skip it.