Trying to calculate EMA on different timeframe to chart

gambcl

Member
Joined
Jul 4, 2025
Posts
10
Likes
5
This is my first attempt at developing on MW, although I have a fair bit of experience on several other platforms.

I have a chart, say 4H, and I would like to plot the EMA calculated on a different bar size, specified by the user, for example 1H.

I have managed to get the input settings working so I can specify the period and bar size for the EMA.
I have also fetched a data series for that bar size, and it does seem to have data.

I'm a bit stumped on how to index into the data-series for the other bar-size during the calculate() method, which is based on the chart's bar size,
so presumably the chart's index parameter is useless to me here.

I can get something plotting, but the values are way off when I compare them to TradingView, so I must be indexing incorrectly into the other data series.

Has anyone else had any experience with this?

int emaPeriod = getSettings().getInteger(EMA_PERIOD);
BarSize emaBarSize = getSettings().getBarSize(EMA_BAR_SIZE);
var emaBars = ctx.getDataSeries(emaBarSize);
if (emaBars != null)
{
var emaValue = emaBars.ema(index, emaPeriod, Enums.BarInput.CLOSE); // PROBABLY WRONG!!! - How do I know what index to use with the emaBars data series?
series.setDouble(index, Values.EMA, emaValue);
}
 
Why would you reinvent the wheel when this is already possible with the stock EMA indicator?2025-07-10 165541.jpg
 
Why would you reinvent the wheel when this is already possible with the stock EMA indicator?

I need it as part of a larger study, and after scouring this forum it seems like one study cannot read the values from another study, so I would have to calculate the EMA inside my study.
 
Top