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

Printing number of ticks between Hi/Lo and current price

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

    Printing number of ticks between Hi/Lo and current price

    How would I go about to achieve the following:

    At a certain price my conditions are met. At that moment I would like it to look for the High (or Low) of the candle and tell me numerically how many ticks lie between the current price and the High(or Low). So, going short, I would like it to calculate "Close minus High" and print the result in ticks into the chart. I enclose an image to show what I have in mind.

    Perhaps there is already an indicator that does this or something similar or a reference that you could refer me to. I already tried searching the forum but could not find anything.

    sandman

    Attached Files

    #2
    Hello sandman,

    Thank you for your post.

    SharpDX would need to be used to draw the Close[0] - High[0] (or Low[0]) in Ticks on a chart. To accomplish this you would need to create a double variable and assign that variable Math.Abs(Close[0] - High[0])/TickSize; followed by using that variable in RenderTarget.DrawText() in OnRenderUpdate() to draw the text on the chart.

    Please see the documentation below for more information about using RenderTarget.DrawText and SharpDX. You may also see the SampleCustomRender script that comes with NinjaTrader for more information.

    SharpDX - https://ninjatrader.com/support/help..._rendering.htm
    RenderTarget.DrawText - https://ninjatrader.com/support/help...t_drawtext.htm

    Also, please see the attached example script that demonstrates how to accomplish this.

    Let us know if you have further questions and we will be happy to assist.
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hi Brandon. Thanks. When trying to import the file it gives me an error message, probably corrupt etc. Could it be that what you suggested is for NT8? I am using NT7 which is why I posted my request in the NT7 section of the forum. That being said, is there a way to do the same thing of what you laid out also in NT7?

      sandman

      Comment


        #4
        Hello sandman,

        Thank you for your note.

        I had provided instructions for NinjaTrader 8. In NinjaTrader 7 you would create a double variable and assign that variable Close[0] - High[0] (or Low[0]) followed by calling that variable in DrawText. Please see the help guide link below for more information about DrawText.

        DrawText - https://ninjatrader.com/support/help...7/drawtext.htm

        Also, please see the attached example script that demonstrates using DrawText to draw to Close[0]-High[0] in ticks above the current High of the bar.

        Let us know if we may assist further.
        Attached Files
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Awesome. Thanks Brandon. The sample you included gives me enough to work with.


          sandman

          Comment


            #6
            Brandon H,

            Allow me to come back with another question on the same subject.
            Basically you provided me with:

            (private double valueInTicks; )

            Print("valueInTicks: " + valueInTicks);
            DrawText("valueInTicks", valueInTicks.ToString(),0, High[0]+ 5*TickSize, Color.Black);
            valueInTicks = Math.Abs(Close[0] - High[0])/.25;

            I experimented also using Open and Low instead of High and all works fine as long as I use the NQ instrument.

            But when I switch to RTY or ES, I get a whole slew of fractional digits instead of the expected natural number.
            Does that have something to do with the .25? How do I get rid of all the digits to the right of the decimal point?

            sandman

            Comment


              #7
              Hello sandman,

              Thank you for that information.

              If we change the valueInTicks variable to an int instead of a double followed by adding (int) to our calculation, valueInTicks = (int)Math.Abs((Close[0] - High[0])/.25); , then we are able to draw only whole numbers on the chart.

              I have attached a modified version of the previously posted example script that demonstrates how this is accomplished.

              Please let us know if we may assist further.
              Attached Files
              Brandon H.NinjaTrader Customer Service

              Comment


                #8
                Works nicely, so thank you. I have also experimented using EMAs instead of Close, Open, High and that works well too, for example:

                valueInTicks = (int)Math.Abs((EMA(200] - EMA(20])/.25);

                DrawText("valueInTicks", valueInTicks.ToString(),9, Low[0]-5*TickSize, Color.Black);


                The remaining question is placement of the output number using the output. Let's say the difference between the two EMAs is 248 ticks. I'd like to place that number half way between these two EMAs i.e. at EMA(20)+124 ticks. How do I get that into the code in the DrawText line?


                sandman






                Comment


                  #9
                  Hello sandman,

                  Thank you for that information.

                  If you are already calculating a difference in ticks, you could use whichever the lower EMA is and TickSize. The code would look something like this.

                  DrawText("valueInTicks", valueInTicks.ToString(),9, EMA(20) + 124 * TickSize, Color.Black);

                  Please let us know if we may assist further.

                  Brandon H.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi Brandon,

                    Thanks. That's clear and would work on a single bar. While starting to reply to you, I tried something else and it seems to work. Replacing the +124*TickSize:

                    DrawText("valueInTicks", valueInTicks.ToString(), 1, EMA(20)+(valueInTicks/2)*TickSize, Color.Black);

                    I'll see how it works out and will get back to you as needed.

                    sandman

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by bmartz, 03-12-2024, 06:12 AM
                    5 responses
                    32 views
                    0 likes
                    Last Post NinjaTrader_Zachary  
                    Started by Aviram Y, Today, 05:29 AM
                    4 responses
                    12 views
                    0 likes
                    Last Post Aviram Y  
                    Started by algospoke, 04-17-2024, 06:40 PM
                    3 responses
                    28 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by gentlebenthebear, Today, 01:30 AM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by cls71, Today, 04:45 AM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Working...
                    X