Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Range calculation CL

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

    Range calculation CL

    Hello,

    as I´m transcribing my codes from NT7 to NT8 these days I´m experiencing some strange issues when testing.

    I have in the code to determine the range of a bar
    TxRangeHL0 = High[0]-Low[0];
    TxRangeOC0 = Math.Abs(Open[0]-Close[0]);
    Open[1]...
    [2]....


    This shows correct for ES and NQ but with CL I get numbers like 0.070000000000000003 or 0.009999999999999999999801....

    Same results with
    TxRangeHL0 = (High[0]-Low[0])*TickSize;
    TxRangeOC0 = Math.Abs(Open[0]-Close[0])*TickSize;

    Thank you!
    Tony

    #2
    Hello tonynt,

    Thank you for the post.

    It is possible to have a large remainders when doing floating point arithmetic, how are you currently viewing this number? If you are not specifically rounding the number to a tick size after doing your calculations this could be possible depending on how you are outputting the number. For example, Printing or using a Drawing object could display remainders where a Plot would not. You would likely need to use some rounding syntax to make this back into a TickSized number.





    Please let me know if I may be of additional assistance.

    Comment


      #3
      Hello,

      I plot the important numbers directly on my chart:

      Draw.TextFixed(this,"str1",str1,TextPosition.Botto mLeft); (str1 contains the doubles, bools and ints I want to see)

      Thank you for your support!

      Best regards
      Tony

      Comment


        #4
        Hello tonynt,

        Yes in this case because you are using Draw.TextFixed, you would need to format the number yourself if it has a remainder after you do a calculation. You are just outputting the raw value of the number that was calculated by using DrawText. Unline a plot, DrawText has no concept of rounding the value you have used. The value being used seems to have calculated to have a remainder.

        You could use either of the rounding methods I had linked to in the prior message to round the number back to a tick size if that was the intention. To understand why you are seeing this value calculated in this way, you could use Print statements to output the values used in your math to see what specifically is being calculated that results in this value.

        Please let me know if I may be of further assistance.



        Comment


          #5
          Hello,

          I modified in my code and now I have as result 0.05 for CL from
          TxRangeHL0 = Instrument.MasterInstrument.RoundToTickSize(High[0] - Low[0]);

          with CL High 54.06 and Low 54.01

          Is 0.05 correct for 5 Ticks from High to Low?

          Thank you!
          Tony

          Comment


            #6
            Hello tonynt,

            You can figure this out by using the information you have available to the script.

            In order to know if this is right, you need to know the TickSize of the instrument. One way to know the TickSize would be to print the TickSize property:

            Code:
            Print(TickSize);
            The Tick Size can also be found in the instrument manager by viewing the CL.

            The default TickSize defined for CL is 0.01. If the range was 0.05 cents and the tick size is 0.01, that would go into the range five times or would equal 5 ticks based on the tick size being used.

            If you wanted to make this decimal number into a whole number of ticks, you could use the result divided by the TickSize or 0.05 / 0.01 = 5.






            Please let me know if I may be of further assistance.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            563 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            329 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            547 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            548 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X