Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to display a strategy's EMA from secondary series on primary chart.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to display a strategy's EMA from secondary series on primary chart.

    I know this should be a simple thing, but I can't seem to get it to work.

    I am developing a strategy, and the display is based on 1-minute chart. I want to display the 5-minute EMA and SMA on the 1-minute chart when the strategy is enabled.

    This is what I have so far.

    Declared the Indicators.

    private EMA goldLine5m = null;
    private SMA redLine5m = null;​


    In OnStateChange, I have the following code added.

    When State == State.Configure

    AddDataSeries(BarsPeriodType.Minute, 5);


    ​When State == State.DataLoaded

    goldLine5m = EMA(Closes[1], 9);
    goldLine5m.Plots[0].Brush = Brushes.Yellow;
    goldLine5m.Plots[0].DashStyleHelper = DashStyleHelper.DashDot;
    goldLine5m.Plots[0].Width = 3;
    goldLine5m.PaintPriceMarkers = false;
    goldLine5m.Panel = 0;
    AddChartIndicator(goldLine5m);

    redLine5m = SMA(Closes[1], 21);
    redLine5m.Plots[0].Brush = Brushes.Red;
    redLine5m.Plots[0].DashStyleHelper = DashStyleHelper.DashDot;
    redLine5m.Plots[0].Width = 3;
    redLine5m.PaintPriceMarkers = false;
    redLine5m.Panel = 0;
    AddChartIndicator(redLine5m);​


    I thought that adding the .Panel = 0 would cause it to display in the main window. In fact, I do see "SMA(RTY 12-23 (5 minute),21)" at the top of the chart, just no lines.

    If I change "Closes[1]" to "Closes[0]" the line shows up ok, but of course, it is displaying the wrong series data.

    I saw another post that said to use EMASecondarySeries instead of EMA, but I don't see that indicator available anywhere.

    I do see the bullet item in the AddChartIndicator() documentation that states:
    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)​

    Is this talking about the EMASecondarySeries? Do I need to create my own indicator for this to work?

    #2
    Hello d3whiteley,

    Thanks for your post.

    From the AddChartIndicator() help guide page:

    "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)​"

    This means that you would need to create two custom indicators, one for the EMA calculating from an added 5-minute series, and one for the SMA calculating from an added 5-minute series. Then you could use those custom indicators in your strategy using the AddChartIndicator() method.

    See this help guide page for more information about AddChartIndicator(): https://ninjatrader.com/support/help...tindicator.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    50 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X