Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Modding Existing Indicator?

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

    Modding Existing Indicator?

    Is it possible to modify this indicator
    Al Brooks style Bar Counter which places the number of the bar below every other bar starting at 1 for the first bar of each session. You can change the text size, color, place text below or above price bars, change the distance below/above a price bar, show either odd or even numbers. This is […]


    To display the range of ticks between the open and the close of each bar?

    Any advice on code changes would be appreciated.

    Much appreciated!

    #2
    Hello Bob-Habanai,

    Thanks for your post.

    Yes, you could use custom logic to calculate the range of ticks between the open price and close price of a bar, save that value to a variable, and use that variable when calling the Draw.Text() method to draw the value on the chart.

    See this help guide page for more information about accessing the PriceSeries (Open and Close prices): https://ninjatrader.com/support/help...riceseries.htm

    See this help guide page for more information about using the Draw.Text() method: https://ninjatrader.com/support/help.../draw_text.htm

    Let me know if I may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thank you for your reply Brandon.

      I went to:



      and


      But I'm still unsure of what the string should look like, thank you for trying though.


      Originally posted by NinjaTrader_BrandonH View Post
      Hello Bob-Habanai,

      Thanks for your post.

      Yes, you could use custom logic to calculate the range of ticks between the open price and close price of a bar, save that value to a variable, and use that variable when calling the Draw.Text() method to draw the value on the chart.

      See this help guide page for more information about accessing the PriceSeries (Open and Close prices): https://ninjatrader.com/support/help...riceseries.htm

      See this help guide page for more information about using the Draw.Text() method: https://ninjatrader.com/support/help.../draw_text.htm

      Let me know if I may assist further.

      Comment


        #4
        Hello Bob-Habanai,

        Thanks for your note.

        An example of finding the difference between the Open price and Close price and drawing that value as text on a chart could be seen below. Note that this is an example demonstrating a programming concept and is not a copy/paste solution.

        Create a variable called something like MyDifference and assign the Open price - Close price to that variable. Then, call your Draw.Text() method and use that variable for the 'string text' property.

        Draw.Text(NinjaScriptBase owner, string tag, string text, int barsAgo, double y, Brush textBrush)

        Example code:

        //class level variable
        private double MyDifference;


        //OnBarUpdate()
        protected override void OnBarUpdate()
        {
        MyDifference = Open[0] - Close[0];

        Draw.Text(this, "difference", MyDifference.ToString(), 0, High[0] + 10 * TickSize, Brushes.Pink);
        }


        Let me know if I may assist further.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          Hi Brandon,

          Because of your recent replies, I was able to do this one successfully and add several extra features,
          but it's displaying the range in points, not ticks. i.e. instead of 1, it'll draw 0.25.

          Any idea why that is?

          Thanks again.

          Originally posted by NinjaTrader_BrandonH View Post
          Hello Bob-Habanai,

          Thanks for your note.

          An example of finding the difference between the Open price and Close price and drawing that value as text on a chart could be seen below. Note that this is an example demonstrating a programming concept and is not a copy/paste solution.

          Create a variable called something like MyDifference and assign the Open price - Close price to that variable. Then, call your Draw.Text() method and use that variable for the 'string text' property.

          Draw.Text(NinjaScriptBase owner, string tag, string text, int barsAgo, double y, Brush textBrush)

          Example code:

          //class level variable
          private double MyDifference;


          //OnBarUpdate()
          protected override void OnBarUpdate()
          {
          MyDifference = Open[0] - Close[0];

          Draw.Text(this, "difference", MyDifference.ToString(), 0, High[0] + 10 * TickSize, Brushes.Pink);
          }


          Let me know if I may assist further.

          Comment


            #6
            Without knowing Ninjascript properly, I found a quick workaround by going:

            MyDifference = Close[0] - Open[0] + Close[0] - Open[0] +Close[0] - Open[0] +Close[0] - Open[0];

            Then I did MyDifference = (Close[0] * 4) - (Open[0] * 4); which is much better.

            But how do you write if (Close[0] = Open[0]) ?
            i.e. a Doji candle? I tried and it wouldn't compile.

            Ok, I did more research and found you have to write = twice.
            Problem solved!
            Last edited by Bob-Habanai; 08-25-2022, 04:28 AM.

            Comment


              #7
              Hi Bob-Habanai,

              Just a quick answer to your question about obtaining ticks rather than points. There's a property provided by Ninja Trader called TickSize. It represent the price value of 1 tick for the primary data series. That is...

              For the MES, the tick is 0.25 points, so the TickSize is 0.25. This allows you to quickly get ticks from a difference in prices. For example,

              Range Ticks = (High - Low) / TickSize
              Range Ticks = (4148.75 - 4145.50) / 0.25 = 3.25 / 0.25 = 13 ticks

              Hope that helps!
              Matt

              Comment


                #8
                Thanks for the reply, Stealth.

                Ninja keeps saying the name 'ticksize' does not exist in the current context.

                Any idea why?

                Much appreciated!

                Originally posted by StealthM93 View Post
                Hi Bob-Habanai,

                Just a quick answer to your question about obtaining ticks rather than points. There's a property provided by Ninja Trader called TickSize. It represent the price value of 1 tick for the primary data series. That is...

                For the MES, the tick is 0.25 points, so the TickSize is 0.25. This allows you to quickly get ticks from a difference in prices. For example,

                Range Ticks = (High - Low) / TickSize
                Range Ticks = (4148.75 - 4145.50) / 0.25 = 3.25 / 0.25 = 13 ticks

                Hope that helps!
                Matt

                Comment


                  #9
                  Hello Bob-Habanai,

                  Thanks for your note.

                  So that I may accurately assist, how is TickSize being used in the script?

                  Are you using TickSize within the OnBarUpdate() method of your script?

                  See this help guide page for information about TickSize and sample code: https://ninjatrader.com/support/help...8/ticksize.htm

                  I look forward to assisting further.
                  <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                  Comment


                    #10
                    Hi Brandon,

                    Here is the exact code.

                    Code:
                    {
                    public class DrawDistance : Indicator
                    {
                    
                    //class level variable
                    private double MyDifferenceGreen;
                    private double MyDifferenceRed;
                    
                    protected override void OnStateChange()
                    {
                    if (State == State.SetDefaults)
                    {
                    Description = @"Enter the description for your new custom Indicator here.";
                    Name = "DrawDistance";
                    Calculate = Calculate.OnEachTick;
                    IsOverlay = true;
                    DisplayInDataBox = true;
                    DrawOnPricePanel = true;
                    DrawHorizontalGridLines = true;
                    DrawVerticalGridLines = true;
                    PaintPriceMarkers = true;
                    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive = true;
                    }
                    else if (State == State.Configure)
                    {
                    }
                    }
                    
                    protected override void OnBarUpdate()
                    {
                    
                    //assign MyDifference
                    MyDifferenceGreen = (Close[0] * 4) - (Open[0] * 4);
                    MyDifferenceRed = (Open[0] * 4) - (Close[0] * 4);
                    
                    //green ticks
                    if (Close[0] > Open[0])
                    Draw.Text(this, "does this matter" + CurrentBar, MyDifferenceGreen.ToString(), 0, Low[0] - 30 * TickSize, Brushes.ForestGreen);
                    //red ticks
                    if (Open[0] >= Close[0])
                    Draw.Text(this, "does this really matter" + CurrentBar, MyDifferenceRed.ToString(), 0, High[0] + 30 * TickSize, Brushes.Red);
                    
                    } } }
                    If I try to change

                    Code:
                    MyDifferenceGreen = (Close[0] * 4) - (Open[0] * 4);
                    MyDifferenceRed = (Open[0] * 4) - (Close[0] * 4);
                    to
                    Code:
                    MyDifferenceGreen = (Close[0] * Ticksize) - (Open[0] * Ticksize);
                    MyDifferenceRed = (Open[0] * Ticksize) - (Close[0] * Ticksize);
                    I get that error. I also get that error if I remove the MyDifferenceGreen & MyDifferenceRed,
                    and put it (Close[0] * ticksize) - (Open[0] * ticksize) into

                    Draw.Text(this, "does this really matter" + CurrentBar, (Open[0] * ticksize) - (Close[0] * ticksize).ToString(), 0, High[0] + 30 * TickSize, Brushes.Red);

                    Thanks for your help.

                    Comment


                      #11
                      There's another issue Brandon that if the indicator is set to calculate on bar close it works fine,
                      but if it's set to calculate on tick, if the bar retraces, it will draw (for example) above the bar as a seller bar,
                      then if the bar reverses, instead of cancelling the drawing and only drawing the buyer distance,
                      it will keep the former on the screen.

                      Any idea why that is or how to stop that occurring?
                      Here's a picture of what I mean.
                      The red arrows are pointing at text that should've been cancelled when the conditions changed.

                      Thanks again!

                      Click image for larger version

Name:	Screenshot 2022-08-30 160301.png
Views:	182
Size:	8.9 KB
ID:	1213676

                      Comment


                        #12
                        Hi Bob-Habanai,

                        Allow me to assist...
                        • Since you're checking for Close > Open in the if statements, you only need a single value for the difference: double MyDifferentTicks = Math.Abs(Close[0] - Open[0]) * TickSize;
                        • Also, I believe you want division by TickSize, not multiplication to get the number of ticks. (Corrected below)
                        • For TickSize, you must use "TickSize" and not "Ticksize" - variables are case sensitive; otherwise, you'll get the error you're seeing.
                        • The reason you're getting two labels on a bar is because you have two different text strings for each Draw statement. Use the same string when concatenating CurrentBar.

                        Here's an update on your code that might help.

                        Code:
                        protected override void OnBarUpdate()
                        {
                        
                        //assign MyDifference
                        int MyDifferenceTicks = (int)((Close[0] - Open[0]) / TickSize);
                        
                        //green ticks
                        if (Close[0] > Open[0])
                        Draw.Text(this, "MyMarker" + CurrentBar, MyDifferenceTicks, 0, Low[0] - 30 * TickSize, Brushes.ForestGreen);
                        //red ticks
                        if (Open[0] >= Close[0])
                        Draw.Text(this, "MyMarker" + CurrentBar, MyDifferenceTicks, 0, High[0] + 30 * TickSize, Brushes.Red);
                        
                        }
                        Hope that helps! I'm sure Brandon will provide more insight.

                        Kind regards,
                        Matt

                        Comment


                          #13
                          Thanks for those helpful tips Stealth.

                          Do you have any idea how to get rid of the DimGray outline around the text and make it transparent? in the code below?

                          Code:
                          Draw.Text(this, "MyMarker" + CurrentBar, MyDifferenceTicks, 0, Low[0] - 30 * TickSize, Brushes.ForestGreen);

                          Click image for larger version

Name:	Screenshot 2022-08-30 172635.png
Views:	193
Size:	41.8 KB
ID:	1213688




                          Originally posted by StealthM93 View Post
                          Hi Bob-Habanai,

                          Allow me to assist...
                          • Since you're checking for Close > Open in the if statements, you only need a single value for the difference: double MyDifferentTicks = Math.Abs(Close[0] - Open[0]) * TickSize;
                          • Also, I believe you want division by TickSize, not multiplication to get the number of ticks. (Corrected below)
                          • For TickSize, you must use "TickSize" and not "Ticksize" - variables are case sensitive; otherwise, you'll get the error you're seeing.
                          • The reason you're getting two labels on a bar is because you have two different text strings for each Draw statement. Use the same string when concatenating CurrentBar.

                          Here's an update on your code that might help.

                          Code:
                          protected override void OnBarUpdate()
                          {
                          
                          //assign MyDifference
                          int MyDifferenceTicks = (int)((Close[0] - Open[0]) / TickSize);
                          
                          //green ticks
                          if (Close[0] > Open[0])
                          Draw.Text(this, "MyMarker" + CurrentBar, MyDifferenceTicks, 0, Low[0] - 30 * TickSize, Brushes.ForestGreen);
                          //red ticks
                          if (Open[0] >= Close[0])
                          Draw.Text(this, "MyMarker" + CurrentBar, MyDifferenceTicks, 0, High[0] + 30 * TickSize, Brushes.Red);
                          
                          }
                          Hope that helps! I'm sure Brandon will provide more insight.

                          Kind regards,
                          Matt

                          Comment


                            #14
                            Hi Bob-Habanai,

                            See here for the different Draw.Text() method specifications.


                            For my scenarios, similar to yours, I'm using:
                            Draw.Text(NinjaScriptBase owner, string tag, bool isAutoScale, string text, int barsAgo, double y, int yPixelOffset, Brush textBrush, SimpleFont font, TextAlignment alignment, Brush outlineBrush, Brush areaBrush, int areaOpacity);

                            As you can see, there are parameters that set the outline and area brushes and opacity.

                            Here's a sample from the strategy I'm currently developing.
                            Draw.Text(this, newChartMarker, true, pChartSymbol + pTradeCode, 0, pPrice, 0, pColor, ChartMarkerFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);

                            Where newChartMarker, pChartSymbol, pTradeCode, pPrice, pColor, and ChartMarkerFont are variables defined elsewhere.

                            Kind regards,
                            Matt

                            Comment


                              #15
                              Hi Matt,

                              Does this mean we must put in values for the in-betweens and there's no way to just skip them like:

                              Code:
                              Draw.Text(this, "MyMarker" + CurrentBar, MyDifferenceTicks, 0, Low[0] - 30 * TickSize, Brushes.ForestGreen),,,,,Brushes.Transparent);

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              661 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              375 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              110 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              574 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              580 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X