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

Plot MA's for 2nd Data Series from Strategy

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

    Plot MA's for 2nd Data Series from Strategy

    Click image for larger version

Name:	ma plot failure.png
Views:	56
Size:	197.3 KB
ID:	1287435 I was trying to create a strategy that uses 4 MA's, 2 on the 1min time frame and 2 on the 5min timeframe. When using builder I can select the MA's but when I select the 5min data series, the option to add it to the chart disappears. When I code it manually, the MA's using the 2nd data series do not show up on the chart, even though they are visible in the indicator settings UI.

    I've attached a screenshot showing what's happening. You can see only 2 MA's on the chart but 4 in the Settings UI. They are all loaded from the strategy.

    #2
    Hello Trader146,

    Thank you for your post.

    In your strategy, have all 4 MAs been added to the chart using AddChartIndicator()?

    Please note, from the Help Guide:

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



    If you want to use the added data series for the indicator's input, you would have to hard code the added series in the indicator, make calculations using the secondary series, and then set plot values on the primary series.

    Please let us know if we can assist further.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Gaby View Post
      Hello Trader146,

      Thank you for your post.

      In your strategy, have all 4 MAs been added to the chart using AddChartIndicator()?

      Please note, from the Help Guide:

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



      If you want to use the added data series for the indicator's input, you would have to hard code the added series in the indicator, make calculations using the secondary series, and then set plot values on the primary series.

      Please let us know if we can assist further.
      Thank you!

      Comment


        #4
        Ok, I am now trying to create an indicator that contains the 4 MA's and the additional data series. I think I have the code correct, but the two MA's for the 5 minute data series are invisible. Please look at the screen shot. Those bubbles are the 5 minute MA's. I'll also attach the code.

        Click image for larger version

Name:	image.png
Views:	43
Size:	169.6 KB
ID:	1287587

        Comment


          #5
          Here's a text file of the script just in case.
          Attached Files

          Comment


            #6
            Click image for larger version

Name:	image.png
Views:	41
Size:	41.0 KB
ID:	1287593

            This is the UI in case it's helpful.​

            Comment


              #7
              Ok, since the sample was displaying correctly in my chart, I just added 2 more MA's to it. Now again, the 2nd data series is not displaying in the chart. What the heck is going on?

              I will attach a txt file containing the script, and a screenshot.

              Click image for larger version

Name:	image.png
Views:	39
Size:	226.6 KB
ID:	1287604

              Comment


                #8
                I have an interesting discovery. It seem my strategy is displaying the indicators after all, but not where expected. It seems that they are being display on the 1 minute chart as if it was a 5 minute chart so it runs out of data before reaching the current bar. I made a video showing what I'm talking about if I'm not making myself clear. Surely somebody knows how to correct this. Please help!

                Comment


                  #9
                  Hello,

                  As mentioned, indicators added by a strategy via AddChartIndicator() can only use the strategy's primary data series.

                  To use a different series for the indicator's input, a custom indicator can call AddDataSeries() to add the series internally in its code (the hosting script also has to have the same AddDataSeries() call) and reference that series explicitly in its code, however the plots and drawing objects will only be on the primary series of the strategy.

                  Plots need to have a value assigned on every primary bar or they won't show. If the added series is larger than the primary series, it is necessary to assign the current bar's value to the previous bar's value to carry the value forward, which causes the stair stepping which is expected.

                  Please see this forum post below which has an example script demonstrating plotting an indicator from a higher time frame on a lower time frame chart (HigherTimeFrameIndicatorPlotExample).



                  If you have any further questions, please let us know.
                  Gaby V.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks Super Mod! I was able to create the indicator suite containing the 4 differ MA's on two different data series. I used the sample as a template and added the additional MA's there.

                    Now to see what happens when I try to use this indicator in my stratgegy. I'll report back when I know. Thanks!

                    Click image for larger version

Name:	image.png
Views:	30
Size:	177.2 KB
ID:	1287650

                    Comment


                      #11
                      Ok, I created a indicator with the 4 moving averages I wanted to use in my strategy, but I'm confused as to how I would access each individual moving average of the suite from within strategy builder, much less from within the editor. Am I supposed to just use the regular EMA and SMA indicators in the strategy and then plot the indicator suite on the chart? Please forgive me for my ignorance, but I'm new to coding. Thanks!

                      Comment


                        #12
                        Ok, I got it.

                        var myIndicator = myBAGLSuitev01(9, 21, 9, 21);
                        AddChartIndicator(myIndicator);

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by StockTrader88, 03-06-2021, 08:58 AM
                        44 responses
                        3,966 views
                        3 likes
                        Last Post jhudas88  
                        Started by rbeckmann05, Today, 06:48 PM
                        0 responses
                        4 views
                        0 likes
                        Last Post rbeckmann05  
                        Started by rhyminkevin, Today, 04:58 PM
                        4 responses
                        54 views
                        0 likes
                        Last Post dp8282
                        by dp8282
                         
                        Started by iceman2018, Today, 05:07 PM
                        0 responses
                        5 views
                        0 likes
                        Last Post iceman2018  
                        Started by lightsun47, Today, 03:51 PM
                        0 responses
                        8 views
                        0 likes
                        Last Post lightsun47  
                        Working...
                        X