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 do I adapt the constant line indicator?

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

    How do I adapt the constant line indicator?

    I am new at this. I thought i would take the Constant Line indicator and adapt it a little bit. I made it a constant line indicator with 8 lines, which was nice.
    Now I want to plot numerous lines but I want to have lines 4-8 be calculated based on the constants I key in for lines 1-3. I wanted to key in high, low, close in first 3 lines. Then for example have line 4 plotted as the value for line 1 (which would be the high I input) plus 2.
    I am missing something. I took the current Constant line indicator and left the first three alone and put equations in for Line4Value = LineValue1 +3 and so on. But its not plotting. When I pull up the indicator it still isnt plotting values 4-8 but only the lines i input the constants for. Can someone help? thanks.

    #2
    Hi winJR,

    If you could post up the code you have currently I would be glad to assist you determine the problem.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh...here is what I have

      Here is the constant lines indicator with just a minor modification, but cant seem to get it to work. For example, in this example I was trying to make it so that I only have to key in the value for Line1, and then the indicator would draw the lines for line1 and all the others. The other lines would be a function of the value in line1. In this example, I wanted line2 to plot the value I keyed in for line1 plus 3, line3 was going to be line1 plus 4, etc. Even though it compiles, it only plots line1 which is the value I keyed in. The other lines are not plotting. I am new at this and appreciate the patience and help.
      Thanks.

      I only posted the few lines of the indicator that I changed since it said posting the whole thing was too large.


      Add(new Plot(Color.Navy, PlotStyle.Line, "Line1"));
      Add(new Plot(Color.Green, PlotStyle.Line, "Line2"));
      Add(new Plot(Color.DarkViolet, PlotStyle.Line, "Line3"));
      Add(new Plot(Color.Firebrick, PlotStyle.Line, "Line4"));
      Line1Value = 0;
      Line2Value = Line1Value +3;
      Line3Value = 0;
      Line4Value = 0;
      ChartOnly = true;
      AutoScale = false;
      CalculateOnBarClose = true;
      DisplayInDataBox = false;
      Overlay = true;
      PriceTypeSupported = false;
      }
      ///<summary>
      /// Called on each bar update event (incoming tick)
      ///</summary>
      protectedoverridevoid OnBarUpdate()
      {
      if (Line1Value != 0) Line1.Set(Line1Value);
      if (Line2Value != (Line1Value +3)) Line2.Set(Line2Value);
      if (Line3Value != 0) Line3.Set(Line3Value);
      if (Line4Value != 0) Line4.Set(Line4Value);
      }

      Comment


        #4
        Ok winJR. Basically what you want to do is remove the user definability of Line2 and Line3.

        If you expand the "Properties" section of your code you will see these:
        Code:
        [Description("Line 2 value")]
        [Category("Parameters")]
        public double Line2Value
        {
            get { return line2Value; }
            set { line2Value = value; }
        }
        
        [Description("Line 3 value")]
        [Category("Parameters")]
        public double Line3Value
        {
            get { return line3Value; }
            set { line3Value = value; }
        }
        You want to remove those to remove the user definable options when you add the indicator for those lines.

        In the Initialize() method leave the value of Line2Value alone. Set it back to 0. Then in the OnBarUpdate() method is where you will set Line2 to take on line1 + 3. So here you want to change the line to represent this:
        Code:
        Line2.Set(Line1Value + 3);
        No need for that if statement before it in this instance.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks Josh, I have been trying to implement what you suggested...

          Josh, I appreciate your help. I am still not getting it to work. I did what you suggested but still not working. I probably misunderstood something you suggested. Here are the changes in red I made but still cant get it to compile. I get errors such as "The name 'Line3Value' does not exist in the current context. Maybe I should also mention that I realized I needed lines 1 and 2 where i enter the value, then the other lines plot equidistant from those lines. Maybe thats why its not working.

          region variables....left unchanged
          #region Variables
          // Wizard generated variables
          privatedouble line1Value = 0; // Default setting for Line1Value
          privatedouble line2Value = 0; // Default setting for Line2Value
          privatedouble line3Value = 0; // Default setting for Line3Value
          privatedouble line4Value = 0; // Default setting for Line4Value

          Under Initialize, left unchanged

          Add(new Plot(Color.Navy, PlotStyle.Line, "Line1"));
          Add(
          new Plot(Color.Green, PlotStyle.Line, "Line2"));
          Add(
          new Plot(Color.DarkViolet, PlotStyle.Line, "Line3"));
          Add(
          new Plot(Color.Firebrick, PlotStyle.Line, "Line4"));

          Line1Value = 0 ;
          Line2Value =
          0 ;
          Line3Value =
          0 ;
          Line4Value =
          0 ;

          I expanded the properties section and deleted the code you said and left only this for lineValue 1 and 2...
          [Description("Line 1 value")]
          [Category(
          "Parameters")]
          publicdouble Line1Value
          {
          get { return line1Value; }
          set { line1Value = value; }
          }

          [Description(
          "Line 2 value")]
          [Category(
          "Parameters")]
          publicdouble Line2Value
          {
          get { return line2Value; }
          set { line2Value = value; }
          }

          then I made the change under OnBarUpdate....
          if (Line1Value != 0) Line1.Set(Line1Value);
          if (Line2Value != 0) Line2.Set(Line2Value);
          Line3.Set((Line2Value-Line1Value) + Line2Value);
          Line4.Set((Line2Value-Line1Value)+Line3Value);

          I have been trying it many different ways for hours, just cant seem to get it right.

          Comment


            #6
            We deleted Line3Value and Line4Value so you need to remove that from the Initialize() section. Then in the OnBarUpdate() method you will need to remove your references to Line3Value and Line4Value as well.

            For Line4 you could do this:
            Code:
            [FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]Line4.Set((Line2Value-Line1Value)+Line3[0]);[/SIZE][/FONT][/SIZE][/FONT][/COLOR][/SIZE][/FONT]


            Also in the variables region you no longer need these two lines:
            Code:
            [FONT=Courier New][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] line3Value = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]; [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]// Default setting for Line3Value
            [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] line4Value = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]; [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]// Default setting for Line4Value[/COLOR][/SIZE][/FONT]
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Thanks Josh....you the man

              That did it, thanks a bunch...you guys are awesome! Works great. I am learning a lot the more I do. Your guys willingness to help is such a tremendous blessing. Thanks a million.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by alifarahani, Today, 09:40 AM
              0 responses
              1 view
              0 likes
              Last Post alifarahani  
              Started by Gerik, Today, 09:40 AM
              0 responses
              1 view
              0 likes
              Last Post Gerik
              by Gerik
               
              Started by RookieTrader, Today, 09:37 AM
              0 responses
              5 views
              0 likes
              Last Post RookieTrader  
              Started by KennyK, 05-29-2017, 02:02 AM
              3 responses
              1,282 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Started by AttiM, 02-14-2024, 05:20 PM
              11 responses
              184 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X