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

Can't add indicator to indicator

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

    Can't add indicator to indicator

    I would like to add an indicator to an existing indicator. I tried doing this in Initailize()
    Add(SMA(20));,
    but I get an error: Can't convert NinjaTrader.Indicator.SMA to NinjaTrader.GUI.Chart.Line.
    Can someone give me an idea why this won't work?
    Thanks.

    #2
    Hello,

    Thank you for the question.

    In this case, using Add() specifically to add an indicator can only be used from a Strategy.

    If you are adding an indicator using an indicator, you would want to add a Plot instead and then set the Plot from OnBarUpdate to the value of the indicator. This may not produce the desired result in case the indicator has multiple plots, drawing objects or custom rendering.

    The SMA does not have multiple plots, custom rendering or drawing objects so this would be very simple to replot.

    You can use the example of Add to add a Plot: https://ninjatrader.com/support/help...ghlightsub=Add

    Then the remainder of the syntax would just be to add the OnBarUpdate code:

    Code:
    Value.Set(SMA(20)[0]);
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks Jesse,
      I've been adding indicators in the manner you described for single plot indicators. However now I have an indicator I'd like to add that has multiple plots. I read through the documentation, but I'm still having issues understanding the process. Do you have any sample code for adding a multiple plot indicator? Thanks.

      Comment


        #4
        Hello CaptainAmericaXX,

        A Multi plot indicator is the exact same process, you would just need to define the number of plots that indicator has.

        For example, if you used the Bollinger, you would use Add() 3 times to add 3 new plots. the logic could then look like the following:

        Code:
        protected override void Initialize()
        {
            Add(new Plot(Color.Red, "Upper"));
            Add(new Plot(Color.Blue, "Middle"));
            Add(new Plot(Color.Green, "Lower"));
        }
        
        protected override void OnBarUpdate()
        {
            Values[0].Set(Bollinger(0.5,12).Upper[0]);
            Values[1].Set(Bollinger(0.5,12).Middle[0]);
            Values[2].Set(Bollinger(0.5,12).Lower[0]);
        }



        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          From my understanding adding plots in this way will add these plots to a separate pane. Is it possible to add these plots, in code, to the price panel?
          I read the DisplayInDataBox() doc. Is there a way to place some lines in the data box and some in an individual pane (NT 7)?
          Last edited by CaptainAmericaXX; 11-15-2017, 02:07 PM.

          Comment


            #6
            Hello CaptainAmericaXX,

            Add will actually use the same panel for all plots that come from a single indicator, only a Strategy would have the capability to add multiple indicators which could be placed in multiple panels.

            If you are using Overlay = false; from the main indicator, the plots would be placed in a new panel, you could instead use Overlay = true; to place all plots from this indicator in the price panel. Please keep in mind if you change this, you would need to remove the indicator from the chart and re-add it instead of just refreshing the chart to see it change.

            regarding the DataBox, it will display specifically Plots. If you only want a Line on the chart, I would suggest using the Drawing tools instead to just draw a Line which will not show up in the DataBox.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thank you for the help.
              I now have my individual indicator in a separate panel and I'm able to draw on the price panel with DrawOnPricePanel = true, but when I use BackColor I want it to print on the price panel but it is printing in the indicator panel. I am also using a DrawLine() that won't print in the indicator panel but does print in the price panel if I select "same as input series". How might I solve these issues? Thanks.

              Comment


                #8
                Hello CaptainAmericaXX,

                BackColor will affect the panel that the indicator is applied to. If Overlay is set to false, BackColor will be applied to the indicator's own panel. If Overlay is set to true, BackColor will affect the price panel.

                You could accomplish the desired behavior by creating separate indicators for drawing and plotting on the price panel, and another for the indicator panel.

                Please let us know if we can be of further help.
                JimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by bmartz, 03-12-2024, 06:12 AM
                5 responses
                32 views
                0 likes
                Last Post NinjaTrader_Zachary  
                Started by Aviram Y, Today, 05:29 AM
                4 responses
                12 views
                0 likes
                Last Post Aviram Y  
                Started by algospoke, 04-17-2024, 06:40 PM
                3 responses
                28 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by gentlebenthebear, Today, 01:30 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by cls71, Today, 04:45 AM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X