Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Segwin, 05-07-2018, 02:15 PM
    14 responses
    1,789 views
    0 likes
    Last Post aligator  
    Started by Jimmyk, 01-26-2018, 05:19 AM
    6 responses
    837 views
    0 likes
    Last Post emuns
    by emuns
     
    Started by jxs_xrj, 01-12-2020, 09:49 AM
    6 responses
    3,293 views
    1 like
    Last Post jgualdronc  
    Started by Touch-Ups, Today, 10:36 AM
    0 responses
    13 views
    0 likes
    Last Post Touch-Ups  
    Started by geddyisodin, 04-25-2024, 05:20 AM
    11 responses
    63 views
    0 likes
    Last Post halgo_boulder  
    Working...
    X