Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw Horizontal Line on Indicator Panel

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

    Draw Horizontal Line on Indicator Panel

    Hi,

    I am new to NT, and trying to code my own strategies. I simply want to draw a horizontal line on an indicator that I have added to the strategy. The indicator shows up fine when I run the strategy. But no matter what I do, it only draws the line in the price panel and not on the indicator. I also tried the strategy builder, but could not get it to show what I wanted. Here is what I have.

    region State Data Loaded
    else if (State == State.DataLoaded)
    {
    mom = new Series<double>(this);
    LinReg1 = LinRegSlope(mom, 10);
    AddChartIndicator(LinReg1);
    Draw.HorizontalLine(this, "tag1", 0, Brushes.Red);

    ...

    Any help with this would be greatly appreciated.

    Thank you,
    Ray

    #2
    Hello Ray,

    Welcome to the NinjaTrader forums!

    Set DrawOnPricePanel = false; in State.Configure.

    Below is a link to the help guide.
    https://ninjatrader.com/support/help...pricepanel.htm

    When creating a new indicator, the Indicator Wizard Defaults Properties page lists 'Draw objects on price panel' in the More properties section.

    Drawing objects that use BarsAgo values cannot be called in State.DataLoaded.
    You would need to draw this in OnBarUpdate().

    Strategies cannot be added to their own panel the way an indicator can. A strategy will always be in the price panel.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Thank you for the response. Here is what I tried based on your advice.

      ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      else if (State == State.Configure)
      {
      DrawOnPricePanel = false;


      else if (State == State.DataLoaded)
      {
      mom = new Series<double>(this);
      LinReg1 = LinRegSlope(mom, 10);
      AddChartIndicator(LinReg1);


      protected override void OnBarUpdate()
      {
      if(BarsInProgress != 0) return;

      Draw.HorizontalLine(this, "tag1", 00, Brushes.Red);
      ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

      Unfortunately, this still only draws the line on the price panel and not the indicator panel. What am I missing?

      Thanks,
      Ray​​

      Comment


        #4
        Hello Ray,

        AddChartIndicator() can only be used in a Strategy.

        If this is a strategy, strategies cannot be added to their own panel the way an indicator can. A strategy will always be in the price panel.

        Do this in an indicator.

        Drawing objects will only appear in the panel of the script. Not the panel of other indicators called by the script.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Ok, I'm confused. This is a strategy, and I'm adding this indicator inside the strategy. I just want to draw a line in the indicator panel that I added to my strategy. Are you saying I cannot do this?

          Thanks,
          Ray

          Comment


            #6
            Hello Ray,

            You are calling Draw.HorizontalLine() from the strategy. You can ignore that the strategy also calls and adds a indicator. The Draw method has nothing to do with your indicator.

            The strategy is drawing the line. The line will be drawn on the price panel of the script that calls the drawing method. The indicator is not calling the draw method. Ignore the indicator.

            If you want the line drawn from an indicator, call the draw method from the indicator.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              ok, so if I have multiple panels from using AddChartIndicator() in my strategy, there is no way to choose which panel you want to add the line to in that strategy?

              Comment


                #8
                Hello raysinred,

                Yeah, the indicator panels are not where the strategy draws. All scripts can only draw on the panel the script is added to.

                You will need to draw from the indicators. If you have multiple indicators that call draw methods, the drawing objects will appear on the panels of those indicators.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Ok, what is the best way to do that? Do I have to make a custom indicator from the LinRegSlope NT indicator, or can I modify this canned NT indicator? Am I able to pass a parameter from the strategy into this indicator for my desired line value? Seems like this should be easier... This is new to me and I'm just trying to understand.

                  Thanks.

                  Comment


                    #10
                    Hello raysinred,

                    You can make a copy of a system indicator and modify it to draw horizontal lines.
                    Open the indicator, right-click the code, select Save As.

                    You can make a custom indicator that calls another indicator and sets it's plot to the plot values of the hosted indicator plot and also draws horizontal lines.

                    Yes, the strategy can pass parameters in the indicator call. For example the LinReg() defines a Period public property and this is the 10, you are passing as the parameter when you call LinRegSlope(mom, 10).

                    You can define a public NinjaScriptProperty and this will become one of the parameters to the indicator call.
                    Last edited by NinjaTrader_ChelseaB; 11-09-2022, 12:28 PM.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Ok, I created a custom LinRegSlope indicator and was able to get the line to draw in the indicator. But now when I go to my strategy and update the call out to the new name, it gives me this error.

                      Attached Files

                      Comment


                        #12
                        Hello raysinred,

                        Is LinReg1 declared as LineRegSlopeRay?
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Yes, when I change it to this I get the error.

                          LinReg1 = LinRegSlopeRay(mom, 10);

                          Comment


                            #14
                            Never mind, I did not change it in Startup. I fixed it. going to work on the line value now...

                            Comment


                              #15
                              Hello raysinred,

                              I am asking about the declaration.

                              private LinRegSlopeRay LinReg1;
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Yesterday, 05:17 AM
                              0 responses
                              53 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              130 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              70 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              44 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              49 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X