Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting Range of Candle in Strategy

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

    Getting Range of Candle in Strategy

    How do we get Current Candle Range?

    I tried:

    return (High[0] - Low[0])

    and I get 0;

    I already changed to EachTick and I get the same thing.

    #2
    Hello r3n3v,

    Thanks for your notes.

    You could create a variable in the script, assign the High[0]-Low[0] to the variable, and then print out the variable to see the difference in prices.

    For example:

    double candleRange = High[0]-Low[0];
    Print("candleRange value is: " + candleRange);


    Prints will appear in a New > NinjaScript Output window.

    Note that you must be connected to a data feed connection in the Control Center > Connections menu prior to running the script on the chart.

    High: https://ninjatrader.com/support/helpGuides/nt8/high.htm
    Low: https://ninjatrader.com/support/helpGuides/nt8/low.htm
    Print(): https://ninjatrader.com/support/help.../nt8/print.htm
    <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

      Thanks for your response:

      I get this

      Click image for larger version

Name:	image.png
Views:	258
Size:	1.9 KB
ID:	1277383


      Originally posted by NinjaTrader_BrandonH View Post
      Hello r3n3v,

      Thanks for your notes.

      You could create a variable in the script, assign the High[0]-Low[0] to the variable, and then print out the variable to see the difference in prices.

      For example:

      double candleRange = High[0]-Low[0];
      Print("candleRange value is: " + candleRange);


      Prints will appear in a New > NinjaScript Output window.

      Note that you must be connected to a data feed connection in the Control Center > Connections menu prior to running the script on the chart.

      High: https://ninjatrader.com/support/helpGuides/nt8/high.htm
      Low: https://ninjatrader.com/support/helpGuides/nt8/low.htm
      Print(): https://ninjatrader.com/support/help.../nt8/print.htm

      Comment


        #4
        Anyone know how to do this?

        Comment


          #5
          Hello r3n3v,

          Please attach a sample of the script that you are testing this in. The code that Brandon provided is correct, subtracting the low from the high of the bar would give you its range. This code should be inside OnBarUpdate in your script.

          Comment


            #6
            Forgot to mention that I use two series:

            AddDataSeries(BarsPeriodType.Tick, 1);


            So I'm using the code here:
            ==========================



            if (BarsInProgress == 1)
            {
            double candleRange = High[0]-Low[0];
            Print("candleRange value is: " + candleRange);​
            }

            Comment


              #7
              Hello r3n3v,

              Thanks for your notes.

              So I may accurately assist, please answer all the questions below.
              • What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)
              • Are you running the strategy on realtime data, using the Playback connection, or in the Strategy Analyzer window?
              • Who are you connected to? This is displayed in green on the lower-left corner of the Control Center window.
              • ​What instrument symbol (and expiry if applicable) have you selected? For example, ES 03-22, AAPL, EURUSD, etc.
              • (For a chart) what interval is selected? For example, 5 minute, 1 day, 2000 volume, 4 Renko, etc.​
              As NinjaTrader_Jesse requested, please attach a sample of the script that you are testing this in.

              To export your script to share, go to Tools > Export > NinjaScript AddOn.


              <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


                #8
                Hi r3n3v,

                Another thing to consider is when are you making this calculation? If you're doing it on the First Tick of Bar, then you will always get 0 (zero). Are you looking for the range of the just closed bar? If so, use High[1] - Low[1] for the calculation.

                Hope this helps!
                Matt

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                46 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                126 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                66 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                42 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                46 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X