Potential BUG, inconsistency in onBarClose() call: linear vs. tick interval

Shtick Hustler

Well-known member
Joined
Oct 15, 2020
Posts
105
Likes
46
This is related to a question I posted in a previous thread;

Creating a new thread after investigating the issue further and feel it may be a bug (unless I'm missing something).

How I discovered the issue
I built a simple filter in my study that just counts the number of complete bars that close outside a moving average.
When the bar count exceeds a certain threshold, an action is taken (like buy, sell, etc.).

This filter works fine in linear, 1-min + charts.
But, on any tick chart, it's counting exactly 2 bars for each 1 bar that completes.

I thought putting my counting code in onBarClose() instead of calculate() might solve the problem; but no, I get the same behavior.

Seems logical to me that onBarClose() should be called exactly once on each bar close, and that's not happening.

Testing

I used a study from the study_examples package, SimpleMACD.java, for testing.

Instrument info:
Mar 19, 2021​
MYM Dow Micro Futures​

I added an onBarClose() call, and put println statements both in calculate() on onBarClose().


output:

1-min chart
this outputs as expected from onBarClose(), with one println statement for each 1-minute bar.

Notice that calculate() gets called 5 times per minute.

Code:
--------- SimpleMACD calculate() - series.getEndTime(index) = 03/19/2021 10:00:00.000
 --------- SimpleMACD calculate() - series.getEndTime(index) = 03/19/2021 10:00:00.000
 --------- SimpleMACD calculate() - series.getEndTime(index) = 03/19/2021 10:00:00.000
 --------- SimpleMACD calculate() - series.getEndTime(index) = 03/19/2021 10:00:00.000
 --------- SimpleMACD calculate() - series.getEndTime(index) = 03/19/2021 10:00:00.000
 
 --------- SimpleMACD onBarClose - series.getEndTime(index) = 03/19/2021 10:00:00.000

 --------- SimpleMACD calculate() - series.getEndTime(index) = 03/19/2021 10:01:00.000
 --------- SimpleMACD calculate() - series.getEndTime(index) = 03/19/2021 10:01:00.000
 --------- SimpleMACD calculate() - series.getEndTime(index) = 03/19/2021 10:01:00.000
 --------- SimpleMACD calculate() - series.getEndTime(index) = 03/19/2021 10:01:00.000
 --------- SimpleMACD calculate() - series.getEndTime(index) = 03/19/2021 10:01:00.000

 --------- SimpleMACD onBarClose - series.getEndTime(index) = 03/19/2021 10:01:00.000


600-tick chart

Here we get calculate() called 600 times per bar (once each tick), but, onBarClose() gets called twice per bar, and each call has the same timestamp.
I included just a few of the 600 prints from calculate(). The interleaving between onBarClose() and calculate() is how the output printed.

Code:
 --------- SimpleMACD onBarClose - series.getEndTime(index) = 03/19/2021 10:00:28.864
 --------- SimpleMACD calculate() - series.getEndTime(index) = 03/19/2021 10:00:28.864
 --------- SimpleMACD onBarClose - series.getEndTime(index) = 03/19/2021 10:00:28.864
 --------- SimpleMACD calculate() - series.getEndTime(index) = 03/19/2021 10:00:28.864
 --------- SimpleMACD calculate() - series.getEndTime(index) = 03/19/2021 10:00:29.020
 --------- SimpleMACD calculate() - series.getEndTime(index) = 03/19/2021 10:00:29.020
 --------- SimpleMACD calculate() - series.getEndTime(index) = 03/19/2021 10:00:29.020
 --------- SimpleMACD calculate() - series.getEndTime(index) = 03/19/2021 10:00:29.020


I can certainly work around this issue by having the study grab the interval type, and dividing my counting code by two.

But it seems that methods like onBarClose(), onBarOpen() should only be called once per bar.

If I'm missing something here, please let me know.
 

Shtick Hustler

Well-known member
Joined
Oct 15, 2020
Posts
105
Likes
46
In case anyone would like to test this and see if they get the same result, attached is my modified version of 'Simple MACD.java'
 

Attachments

  • SimpleMACD.java.zip
    2.6 KB · Views: 10
Top