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

Using indicator values in Multiple Timeseries (same instrument) as input for Strategy

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

    Using indicator values in Multiple Timeseries (same instrument) as input for Strategy

    Hello,

    I want to build a strategy based on indicator values of a multiple time series.

    1.) I added 3 different time series of the same instrument on a chart and added for each of them the same indicator, but each with different periods to consider.
    This seems to work fine, but trying to reflect this in a strategy, I am somehow stuck, as I cannot make the plot to work correctly (the indicators are shown, but with different, unexpected values).

    2.) For the Strategy, I added 3 Data series for the same instrument (Tick) in the Configure state.
    In the Data Loaded state, I assigned the indicator variables to the corresponding (different) Bar Series. When trying to plot the indicator (different periods) for each of the different Bar series, only one is plotted correctly (Bar series 0). The other Indicators based on the other Bar Series differ from the values shown from the chart + added indicators above, as per 1.). - > compare attached image.

    Is this an expected behavior or am I missing something?​

    Below the relevant code I used:


    else if (State == State.Configure)
    {
    AddDataSeries("FDAX 03-24", Data.BarsPeriodType.Tick, 100, Data.MarketDataType.Last);
    AddDataSeries("FDAX 03-24", Data.BarsPeriodType.Tick, 200, Data.MarketDataType.Last);
    AddDataSeries("FDAX 03-24", Data.BarsPeriodType.Tick, 400, Data.MarketDataType.Last);
    }
    else if (State == State.DataLoaded)
    {
    CCI1 = CCI(Closes[1], 44);
    CCI2 = CCI(Closes[2], 22);
    CCI3 = CCI(Closes[3], 11);​

    CCI1.Plots[0].Brush = Brushes.Lime;
    AddChartIndicator(CCI1);

    CCI2.Plots[0].Brush = Brushes.Blue;
    AddChartIndicator(CCI2);

    CCI3.Plots[0].Brush = Brushes.Red;
    AddChartIndicator(CCI3);


    //Panel
    CCI1.Panel = 3;
    CCI2.Panel = 3;
    CCI3.Panel = 3;​

    #2
    Hello Holzratte23,

    Thank you for your post.

    What you have described is expected behavior. There is a note on the help guide page for AddChartIndicator() that states the following:
    • "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)​"
    Since you are using the CCI indicator, you could consider creating a copy of the CCI indicator that adds the additional series or you could create a separate custom indicator that adds the desired series and plots based on each series, then call AddChartIndicator() for that custom indicator with the 3 plots to your strategy:


    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Dear Emily,

      thank you for your answer. This explains the deviating indicator values in the plot. Above it is mentioned explicitly "when added via AddChartIndicator()". Does this mean that the indicator values for the different Bar Series would still be "correct" for calculation in the strategy if not added to the Chart? (Despite being wrongly displayed in the Chart if they are added?). Or is the only reliable method to reference those indicator values in a strategy by creating indicators containing the data series as you described above?

      Comment


        #4
        Originally posted by Holzratte23 View Post
        Dear Emily,

        thank you for your answer. This explains the deviating indicator values in the plot. Above it is mentioned explicitly "when added via AddChartIndicator()". Does this mean that the indicator values for the different Bar Series would still be "correct" for calculation in the strategy if not added to the Chart? (Despite being wrongly displayed in the Chart if they are added?). Or is the only reliable method to reference those indicator values in a strategy by creating indicators containing the data series as you described above?
        Yes, the indicator values will still be correct and be calculated based on the designated Closes series. This may be confirmed by adding Print() statements in your strategy and reviewing the printed values to determine that it is calculating as expected. For more information about using prints:


        We have a page about multi-series scripts in the help guide here:


        Please let us know if we may be of further assistance.
        Emily C.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by futtrader, 04-21-2024, 01:50 AM
        5 responses
        56 views
        0 likes
        Last Post NinjaTrader_Eduardo  
        Started by PeakTry, Today, 10:49 AM
        0 responses
        2 views
        0 likes
        Last Post PeakTry
        by PeakTry
         
        Started by llanqui, Today, 10:32 AM
        0 responses
        5 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by StockTrader88, 03-06-2021, 08:58 AM
        45 responses
        3,992 views
        3 likes
        Last Post johntraderuser2  
        Started by TAJTrades, Today, 09:46 AM
        0 responses
        8 views
        0 likes
        Last Post TAJTrades  
        Working...
        X