Multi time frames

Custom indicators, trading strategies, data export and recording and more...
IAMMYSELF
Posts: 5
Joined: Thu Aug 13, 2020 6:09 pm
Been thanked: 1 time

Multi time frames

Post by IAMMYSELF » Mon Aug 31, 2020 5:44 am

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...

Andry API support
Posts: 548
Joined: Mon Jul 09, 2018 11:18 am
Has thanked: 25 times
Been thanked: 85 times

Re: Multi time frames

Post by Andry API support » Mon Aug 31, 2020 8:50 am

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.

Code: Select all

     int greatestCommonIntervalMillis = 25;

    @Override
    public long getInterval() {
        return TimeUnit.MILLISECONDS.toNanos(greatestCommonIntervalMillis );
    }
Now, you need a counter for every interval. Example for 75 millis:

Code: Select all

    @Override
    public void onInterval() {
       seventyFiveMillisCount += greatestCommonIntervalMillis;

        if (seventyFiveMillisCount == 75) {
            // do whatever you need
            seventyFiveMillisCount = 0; // reset the counter
        }
    }
    
 

Post Reply