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

Hiding a plotted DataSeries in an indicator

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

    Hiding a plotted DataSeries in an indicator

    I have an indicator which calculates support/resistance levels and displays them with DrawHorizontalLine. These "levels" are not "Plotted", therefore they are not used in AutoScale.

    However, as prices approach one of these levels I would like the S/R line to come on screen prior to the currentbar actually reaching that line, so I can observe price behaviour as it approaches S/R.

    I can do this by adding a plot, and letting AutoScale=true make the S/R line visible. This would then make public those plotted values, and there is no reason, since they are used only for controlling "white space" on the chart.

    Ideas?

    #2
    imported post

    You can control the chart white space by override the GetMinMaxValues() function,
    let me know if you need help.

    Muly
    Final
    http://fin-alg.com/

    Comment


      #3
      imported post

      Thanks for the reply. I'm not a good enough programmer to take this nugget of wisdom and run.

      If the market is at 801.1 and I have a Resistance at 802.5 (15 ticks away), I want to make the Resistance Line appear on screen (if it is not already visible).

      More help please.

      Comment


        #4
        imported post

        Why not go with your second approach, and try something like:
        AutoScale = Math.Abs(Close[0] - supportLineValue)/ TickSize> 14 ? true: false;
        I have never tried this but I believe that AutoScale property can be set dynamically.

        Ray
        RayNinjaTrader Customer Service

        Comment


          #5
          imported post

          Thanks Ray,

          I was trying to make the S/R lines visible without making public useless data.

          If I understand your code sample, it will only work if there is a plotted element that AutoScale can process. If I do that, those values are made public, but they have no value to the public.

          Is there a way to Plot without making the plotted values public, and still have those values considered by AutoScale?

          I get the idea that AutoScale evaluates all plots (Where AutoScale is true) and produces the values held by GetMinMaxValues(), Raditz was proposing to Directly set GetMinMaxValues(), effectively bypassing AutoScale. This approach (if I understand it right) will do what I want. However I still can't figure out the Syntax.


          Comment


            #6
            imported post

            Adding a plot always increments the Values[] array by adding an object. The Values array is always public.

            GetMinMaxValues() will work as Muly suggested but this is outside of what NinjaTrader will support at this time. Muly might be able to provide you with a sample that will point you in the right direction.

            Ray
            RayNinjaTrader Customer Service

            Comment


              #7
              imported post

              Use this as a psedo code, it is not complete nor tested code

              Code:
              public override void GetMinMaxValues(ChartControl chartControl, ref double min, ref double max)
              {
               //Go over all the visible bars in the chart
               for (int i = 0; i < ChartControl.BarsPainted; i++)
               {
                int barNo = ((chartControl.LastBarPainted - chartControl.BarsPainted) + 1) + i;
                if (barNo>= 0) && (barNo< Bars.Count)
                {
                 if (R2.Get(num3) - max < 5 * TickSize)
                 {
                  //R2 is within 5 ticks from the visible area of the chart, make it visible
                  max = Math.Max(max, R2.Get(num3)+2*TickSize);
                 }
              
                 if (min - R2.Get(num3) < 5 * TickSize)
                 {
                  //R2 is within 5 ticks from the visible area of the chart, make it visible
                  min = Math.Min(min, R2.Get(num3)-2*TickSize);
                 }
                 
                }
               }
              }
              Muly
              Final
              http://fin-alg.com/

              Comment


                #8
                imported post

                Muly Thanks,

                This is the code I ended up with. I removed your loops checking all bars on the chart, evidently AutoScale does this. Working well so far.
                [line] OnBarUpdate()
                {
                (FoundValue)= Next Resistance above Close[0]
                (FoundIncr)=Distance from FoundValue to Support below Close[0]
                }

                public override void GetMinMaxValues(ChartControl chartControl, ref double min, ref double max)
                {
                // define variables using values from OnBarUpdate()
                if (Math.Abs(ChartControl.LastBarPainted-Bars.Count)<10)
                {
                double above=FoundValue;
                double below=FoundValue-FoundIncr;
                if (above - High[0] < FoundIncr/ 2 )
                max = Math.Max(max, above + 2*TickSize);
                if (Low[0] - below < FoundIncr/ 2 )
                min = Math.Min(min, below - 2*TickSize);
                }
                }

                [line]

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by gravdigaz6, Today, 11:40 PM
                0 responses
                4 views
                0 likes
                Last Post gravdigaz6  
                Started by MarianApalaghiei, Today, 10:49 PM
                3 responses
                9 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by XXtrader, Today, 11:30 PM
                0 responses
                3 views
                0 likes
                Last Post XXtrader  
                Started by love2code2trade, Yesterday, 01:45 PM
                4 responses
                28 views
                0 likes
                Last Post love2code2trade  
                Started by funk10101, Today, 09:43 PM
                0 responses
                9 views
                0 likes
                Last Post funk10101  
                Working...
                X