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 add horizontal line to an indicator via strategy?

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

    How to add horizontal line to an indicator via strategy?

    In State = State.Configure

    I am trying to add a horizontal line to my custom indicator:

    Code:
     AddChartIndicator(BDS());
    ChartIndicators[0].Lines[0].Value = 310;
    Indicator adds well (if I remove 2nd line), but when I add code for Lines[0], I get this error:
    Code:
    Error on calling 'OnStateChange' method: Index was outside the bounds of the arra
    What is the way to add a horizontal line to an indicator via strategy code?

    #2
    Hello UltaNIX,

    Thanks for your post.

    The Lines collection would be populated when a line is added with AddLine. This is generally used to add a horizontal line in addition to the plot lines added in an indicator (also can be done in a strategy)

    You could use AddLine in the strategy to add a line in the strategy, but this would reside in the panel owned by the Strategy where the strategy plots would go (controlled by IsOverlay property.) This could not be used to add a line to an indicator from a strategy.

    If you want to add a line in a indicator from a strategy, I suggest instantiating that indicator, adding it with AddChartIndicator, and then to use Draw.HorizontalLine to draw the line. However, instead of using this as the NinjaScript object for Draw.HorizontalLine, use the instantiated indicator.

    Draw.HorizontalLine - https://ninjatrader.com/support/help...zontalline.htm

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jim View Post
      Hello UltaNIX,

      Thanks for your post.

      The Lines collection would be populated when a line is added with AddLine. This is generally used to add a horizontal line in addition to the plot lines added in an indicator (also can be done in a strategy)

      You could use AddLine in the strategy to add a line in the strategy, but this would reside in the panel owned by the Strategy where the strategy plots would go (controlled by IsOverlay property.) This could not be used to add a line to an indicator from a strategy.

      If you want to add a line in a indicator from a strategy, I suggest instantiating that indicator, adding it with AddChartIndicator, and then to use Draw.HorizontalLine to draw the line. However, instead of using this as the NinjaScript object for Draw.HorizontalLine, use the instantiated indicator.

      Draw.HorizontalLine - https://ninjatrader.com/support/help...zontalline.htm

      We look forward to assisting.
      I opened Draw.HorizontalLIne, and only thing I could find with panels was " bool drawOnPricePanel".

      What I want:

      First panel of the window is CHART. then below it is indicator panel 2, like RSI/Stochastics/MACD. I want to add the line to panel 2.

      Comment


        #4
        Hello UltraNIX,

        You will need to change the first parameter of the DrawingTool method that asks for an owning NinjaScript object to tell the strategy to draw in that indicator's panel.

        Code:
        Draw.HorizontalLine([B]NinjaScriptBase owner[/B], string tag, bool isAutoscale, double y, Brush brush, bool drawOnPricePanel)
        
        Draw.HorizontalLine([B]MyEmptyIndicator1[/B], @"DrawInIndicatorExample Horizontal Line_1", true, Close[0], Brushes.CornflowerBlue, false);
        Please see the snippets above when referencing the code attached. Please also note that the indicator must also have DrawOnPricePanel set to false, but we can also set this indicator's property to false from within the strategy.

        Please let me know if you have any additional questions.
        Attached Files
        JimNinjaTrader Customer Service

        Comment


          #5
          the line:

          Code:
          private BDS BDS1;
          produces this error:
          Code:
          'NinjaTrader.NinjaScript.Strategies.Strategy.BDS()' is a 'method' but is used like a 'type'
          BDS is my indicator, it is within a folder TSX.

          I tried private TSX.BDS BDS1; but it also gave an error.

          Comment


            #6
            Hello UltraNIX,

            Keep in mind that you can use the Strategy Builder to generate syntax for instantiating indicators.

            If you create a condition using your indicator in the Strategy Builder and use the View Code button to see the resulting syntax, what does it give you? Are you doing anything different than the syntax generated from the Strategy Builder?
            JimNinjaTrader Customer Service

            Comment


              #7
              I would love to have an opportunity to do it, but some time ago, whenever I click "new strategy", I don't see options to add entry/exit logic. And, therefore, instantiate indicators. Here, take a look. What could be wrong?
              Attached Files

              Comment


                #8
                EDIT: Used Strategy Builder, instead of New Strategy in NinjaScript Editor. All works well! Thanks Jim for assistance!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by lightsun47, Today, 03:51 PM
                0 responses
                4 views
                0 likes
                Last Post lightsun47  
                Started by 00nevest, Today, 02:27 PM
                1 response
                8 views
                0 likes
                Last Post 00nevest  
                Started by futtrader, 04-21-2024, 01:50 AM
                4 responses
                44 views
                0 likes
                Last Post futtrader  
                Started by Option Whisperer, Today, 09:55 AM
                1 response
                13 views
                0 likes
                Last Post bltdavid  
                Started by port119, Today, 02:43 PM
                0 responses
                8 views
                0 likes
                Last Post port119
                by port119
                 
                Working...
                X