DataSeries.size() is always 0

tystr

Member
Joined
May 1, 2021
Posts
7
Likes
1
I'm trying to user a different data series than the underlying chart, using the following code inside the `calculateValues(DataContext ctx)` method:

Java:
BarSize barSize = BarSize.getBarSize(
    Enums.BarSizeType.CONSTANT_VOLUME,
    1000
);
DataSeries series = ctx.getDataSeries(barSize);

However, the data series is always empty. What am I doing wrong?
 

igor.s

Well-known member
Joined
May 22, 2019
Posts
283
Likes
152
I tried many times without any success. It seems that is not supported. I think, under the hood, it would be difficult to accomplish.

cheers.
 

Shtick Hustler

Well-known member
Joined
Oct 15, 2020
Posts
105
Likes
46
Is it using linear + non-linear DataSeries that's the problem here?

I see this technique used in MWs 'Composite Sample' study. Check it out in 'Studies' menu, and in the 'MW Default Studies' package.

from ln# 215 in code:
Java:
    BarSize barSize = getSettings().getBarSize(Inputs.BARSIZE);
    DataSeries series2 = ctx.getDataSeries(barSize);

You can choose a linear bar size from the study options. Was able to place 5-min option on my 200-tick char. I then see the price chart @ 200-tick, and the RSI and MACD studies below set to 5-min.

Haven't tried multiple time-frame series yet in my own code, but it's on my list.
 

igor.s

Well-known member
Joined
May 22, 2019
Posts
283
Likes
152
It works if you use a tick chart with a linear bar size. it does not work the other way around a linear bar with tick bar size.
 

Inversionauta

New member
Joined
Nov 25, 2021
Posts
1
Likes
4
For using different data series than the underlying chart you must declare Bar Size Descriptor in the Settings Descriptor. If Bar Size is not declared size it's always 0.

Declaration can be do it with addInvisibleSetting.


Java:
// Required invisible input to declare other barsizes
sd.addInvisibleSetting(
                new BarSizeDescriptor("HOURLY", get("HOURLY"), BarSize.getBarSize(BarSizeType.LINEAR, 60)));
sd.addInvisibleSetting(
                new BarSizeDescriptor("DAILY", get("DAILY"), BarSize.getBarSize(BarSizeType.LINEAR, 1440)));
 
Last edited:

Spin

Well-known member
Joined
May 22, 2019
Posts
477
Likes
191
Very nice @Inversionauta ! :) (how on earth did you discover that ? )

Heading further down the same road:
Suppose I wanted to dynamically change the barsizes of the secondary series in the 'Calculate' class (for when a user changes the TF of the chart), how would I do that ?

Let's say I have a chart on M15 (15 minutes) and I want it to also calculate stuff for a lower TF (5 minutes), and a higher TF (1 hour).
I know I can hard-code those timeframes, like you showed us in the post above, but can I also change them when the user changes the TF ?
So when user selects H1 as main TF, the secondary series switches to M15 (for lower TF) and H4 (for higher TF).

I have code to calculate what the higher / lower TF should be (shown below), but I don't see how to 'write' them onto the Settings that exist already.
(the issue I'm facing is that I need the ctx to calculate higher & lower TF, but you cannot use ctx in 'Initialize', so I'm looking for another way to get this right)

Java:
private int getNextHTF(DataContext ctx) {
        int currentTFInMinutes = ctx.getChartBarSize().getIntervalMinutes();
//                debug ("HTF currentTFInMinutes " + currentTFInMinutes);
        if (currentTFInMinutes < 5) return 5;
        if (currentTFInMinutes < 15) return 15;
        if (currentTFInMinutes < 60) return 60; // H1
        if (currentTFInMinutes < 240) return 240; // H4
        if (currentTFInMinutes < 1440) return 1440; // D
        if (currentTFInMinutes < 10080) return 7200; // W = 5 days
        return 28800; //monthly timeframe
    }

Thanks in advance for all help !
 

Bryan SP

Member
Joined
Aug 5, 2021
Posts
9
Likes
5
I believe the only way to do this is like @Inversionauta suggested. You would need to use the BarSizeDescriptor because it is used to load the available time frames in the DataSeries. Otherwise there is no way to access this data. I remember checking with Motivewave support a while back and this is what they directed. All needed timeframe data would need to be loaded this way. Otherwise you could perhaps load the smallest timeframe and build them yourself if you didn't want to make several BarSizeDescriptor fixed settings.
 

tystr

Member
Joined
May 1, 2021
Posts
7
Likes
1
Wow, great find @Inversionauta. I don't know why this isn't better documented...

Does anyone know if there a way to do with with other bar types? E.G. I want to use a CONSTANT_VOLUME bar type to calculate the study and display it on a 30 min chart. I am still unable to get this particular scenario to work.
 

Spin

Well-known member
Joined
May 22, 2019
Posts
477
Likes
191
Ok, so with @Inversionauta's help and some fiddling around I succeeded in getting what I needed.

As a reference I will say that I added into 'Initialize':
Java:
// Required invisible input to declare other barsizes
        sd.addInvisibleSetting(
                new BarSizeDescriptor(M1_TF, "M1", BarSize.getBarSize(Enums.BarSizeType.LINEAR, 1)));
        sd.addInvisibleSetting(
                new BarSizeDescriptor(M5_TF, "M5", BarSize.getBarSize(Enums.BarSizeType.LINEAR, 5)));
        sd.addInvisibleSetting(
                new BarSizeDescriptor(M15_TF, "M15", BarSize.getBarSize(Enums.BarSizeType.LINEAR, 15)));
        sd.addInvisibleSetting(
                new BarSizeDescriptor(H1_TF, "H1", BarSize.getBarSize(Enums.BarSizeType.LINEAR, 60)));
        sd.addInvisibleSetting(
                new BarSizeDescriptor(H4_TF, "H4", BarSize.getBarSize(Enums.BarSizeType.LINEAR, 240)));
        sd.addInvisibleSetting(
                new BarSizeDescriptor(D_TF, "D", BarSize.getBarSize(Enums.BarSizeType.LINEAR, 1440)));
        sd.addInvisibleSetting(
                new BarSizeDescriptor(W_TF, "W", BarSize.getBarSize(Enums.BarSizeType.LINEAR, 7200)));
        sd.addInvisibleSetting(
                new BarSizeDescriptor(M_TF, "M", BarSize.getBarSize(Enums.BarSizeType.LINEAR, 28800)));

and I have these two functions the same class somewhere:
Java:
private BarSize getBarSizeHTF(DataContext ctx) {
        int currentTFInMinutes = ctx.getChartBarSize().getIntervalMinutes();
//                debug ("HTF currentTFInMinutes " + currentTFInMinutes);
        if (currentTFInMinutes < 5) return getSettings().getBarSize(M5_TF);
        if (currentTFInMinutes < 15) return getSettings().getBarSize(M15_TF);
        if (currentTFInMinutes < 60) return getSettings().getBarSize(H1_TF); // H1
        if (currentTFInMinutes < 240) return getSettings().getBarSize(H4_TF); // H4
        if (currentTFInMinutes < 1440) return getSettings().getBarSize(D_TF); // D
        if (currentTFInMinutes < 10080) return getSettings().getBarSize(W_TF); // W = 5 days
        return getSettings().getBarSize(M_TF); //monthly timeframe
    }
private BarSize getBarSizeLTF(DataContext ctx) {
        int currentTFInMinutes = ctx.getChartBarSize().getIntervalMinutes();
//                debug ("LTF currentTFInMinutes " + currentTFInMinutes);
        if (currentTFInMinutes <= 5) return getSettings().getBarSize(M1_TF);
        if (currentTFInMinutes <= 15) return getSettings().getBarSize(M5_TF);
        if (currentTFInMinutes <= 60) return getSettings().getBarSize(M15_TF);
        if (currentTFInMinutes <= 240) return getSettings().getBarSize(H1_TF);
        if (currentTFInMinutes <= 1440) return getSettings().getBarSize(H4_TF);
        if (currentTFInMinutes <= 10080) return getSettings().getBarSize(D_TF);
        return getSettings().getBarSize(W_TF); //weekly timeframe
    }

And then I can get those timeframes / Barsizes and calculate stuff on them wherever I want, like so:
Java:
barSizeLowerTF = getBarSizeLTF(ctx);
barSizeHigherTF = getBarSizeHTF(ctx);

// just an example for the calculation of an EMA on the higher TF:
int htfTunnelPeriod = barSizeHigherTF.getInterval();
series.setDouble(index, Values.HTF_TUNNEL, series.ma(MAMethod.EMA, index, htfTunnelPeriod, Enums.BarInput.CLOSE));

I need to add that sometimes it takes a second or two for markers / lines / labels to appear, but I guess that is due to MW requesting data for the higher & lower TF's.
I will also admit that sometimes nothing appears at all (and I have no clue why), but opening the Study's menu and clicking 'update' fixes that every time. Ah, the joy's of MotiveWave :LOL:

Thanks again, @Inversionauta !! (y)
:D

@tystr : Try it out with 'constant_volume'. Seems pretty straightforward, no ?
 
Last edited:
  • Like
Reactions: lvm

CraterHead

Member
Joined
Dec 3, 2023
Posts
6
Likes
0
Been trying for a week to figure out how to change the underlying chart's RENKO bar size... I keep ending up back here and have tried every way I can think of to adapt the core of what this solution provides, with no joy. I may be too early on in my learning curve, but I can't believe there is no way to change the RENKO bar size from within a Study. Any direction will be much appreciated.
 

igor.s

Well-known member
Joined
May 22, 2019
Posts
283
Likes
152
Been trying for a week to figure out how to change the underlying chart's RENKO bar size... I keep ending up back here and have tried every way I can think of to adapt the core of what this solution provides, with no joy. I may be too early on in my learning curve, but I can't believe there is no way to change the RENKO bar size from within a Study. Any direction will be much appreciated.
If you're trying to load a non-linear bar of a different size into a study it won't work. It works only for linear bars.
 

CraterHead

Member
Joined
Dec 3, 2023
Posts
6
Likes
0
If you're trying to load a non-linear bar of a different size into a study it won't work. It works only for linear bars.
Thank you for your speedy reply. So I'm getting the feeling the only way I can accomplish what I'm trying to do is to have, let's say 3 charts, set up with RENKO 6, 12 and 18 brick sizes, poll them all for the criteria I am seeking, then automagically switch to that chart? Is something like that even possible with the SDK as it stands?
 

igor.s

Well-known member
Joined
May 22, 2019
Posts
283
Likes
152
I don't know what is your use case to say what is possible. Let me give you my personal experience. In the past I wanted to reduce a number of charts so I was looking for a similar API to get different Renko box sizes. Eventually, I ended up with the following solution: I set the chart to the base brick size, in your case it is 6, then I wrote a study that counted number of base bricks and drew a larger brick (base * X factor). Basically, the idea was to aggregate the base brick to a large one. On the same chart I was able to show 6 brick Renko and 18 brick Renko as a layer below. The color, transparency was set to present larger bricks like watermarks. The only reason I needed it was to keep me from "derailing" when too many smaller bricks are created and to see a "bigger" picture. The MW SDK is good enough to allow you to draw your own bars/candles or whatever shapes you come up with.

cheers.
 
Top