I have read a bunch of forum posts on the subject and tried a few ways of coding this, but I still can't make it work.
Here is what I am trying to do:
I am trying to create a strategy that will use AND display multiple time frame indicators. To be exact, the strategy should display the same indicator but with different data series as input.
So, for example, I would like to run my strategy on a 15 minutes chart (primary series) and display the EMA indicator based on this data series. This works, the EMA is displayed correctly using the 15 minute series as input. Additionally, I would also like to plot the EMA based on a 60 minute time frame, on the same 15 minute chart, and also be able to use this indicator for my calculations.
To do this, I followed this advice from the "AddChartIndicator" page of the help guide, where it says : "An indicator being added via AddChartIndicator() cannot use any additional data series hosted by the calling strategy, but can only use the strategy's primary data series. If you wish to use a different data series for the indicator's input, you can add the series in the indicator itself and explicitly reference it in the indicator code (please make sure though the hosting strategy has the same AddDataSeries() call included as well)". So, I created a copy of the EMA indicator (HourlyEMA) which uses an additional data series (60 minutes) and changed all calculations of that indicator to use this new 60 minutes data series. In my strategy, I also added the 60 minutes data series and tried plotting/referencing my indicator like this:
var hourlyEma = HourlyEMA(Closes[1], 9); hourlyEma.Plots[0].Brush = Brushes.Red; hourlyEma.Plots[0].Width = 1; AddChartIndicator(hourlyEma);
I believe this problem is referenced in the "Multi-Time Frame & Instruments" page of the help guide, where it says : "A multi-series indicator will hold the same number of data points for plots as the primary series. Setting values to plots should be done in the primary series in OnBarUpdate(). If you are using calculations based off of a larger secondary series, it may plot like a step ladder because there are more data points available than there are actual meaningful data values."
I guess that when plotting the 60 minutes indicator, the strategy still uses the data points of the 15 minutes chart, which makes the 60 minutes EMA plotted only at the beginning of the chart.
How could I solve this problem, and have my 60 minutes indicator plotted correctly on my 15 minutes chart AND be able to use this 60 minutes indicator for my calculations?
Thanks a lot,
Alex
Comment