I want to develop an indicator that show me Volumes statistics with different time frames in the same indicator.
Should I use the IntervalListener and ovveride getInterval() for every different time frames? Or is there another way?
Thank you...
Multi time frames
-
- Posts: 548
- Joined: Mon Jul 09, 2018 11:18 am
- Has thanked: 25 times
- Been thanked: 85 times
Re: Multi time frames
Hi IAMMYSELF!
You need to find the greatest common diviser and build bigger intervals from smaller ones.
Assume you need intervals of 50, 75 and 500 millis in your module.
50 == 2 * 5 * 5
75 == 3 * 5 * 5
500 == 2 * 2 * 5 * 5 * 5
So 5*5 = 25 is the greatest common diviser in this case.
Now, you need a counter for every interval. Example for 75 millis:
You need to find the greatest common diviser and build bigger intervals from smaller ones.
Assume you need intervals of 50, 75 and 500 millis in your module.
50 == 2 * 5 * 5
75 == 3 * 5 * 5
500 == 2 * 2 * 5 * 5 * 5
So 5*5 = 25 is the greatest common diviser in this case.
Code: Select all
int greatestCommonIntervalMillis = 25;
@Override
public long getInterval() {
return TimeUnit.MILLISECONDS.toNanos(greatestCommonIntervalMillis );
}
Code: Select all
@Override
public void onInterval() {
seventyFiveMillisCount += greatestCommonIntervalMillis;
if (seventyFiveMillisCount == 75) {
// do whatever you need
seventyFiveMillisCount = 0; // reset the counter
}
}