Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Rectangle between range

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

    Rectangle between range

    Hello,
    I'm trying to create a rectangle between the open and close within the one hour interval on the 1 minute timeframe. My problem is with the closing, as the 60 1-minute candlesticks are not totaling, candlestick 60 is the one in the BLUE color band as shown in the attached image.​​



    Click image for larger version

Name:	rec.png
Views:	161
Size:	9.1 KB
ID:	1281037


    Click image for larger version

Name:	mnq.png
Views:	182
Size:	22.4 KB
ID:	1281036

    #2
    Hello diatrader,

    Thanks for your post.

    Close[60] would refer to the Close price 60 bars prior to the CurrentBar on the chart, not the Close price 60 bars after the first bar of the session. Close[int barAgo] uses a barsAgo value which is the number of bars from the current bar on the chart. BarsAgo 0 refers to the current bar on the chart.

    You would have to do custom calculations in your script to get the barsAgo value of that specific bar on the chart and pass that barsAgo value into Close[int barsAgo] to get that close price.

    Something you could consider is creating a condition that checks if Bars.IsFirstBarOfSession is true and saving the CurrentBar value to an int variable called something like 'firstBarOfSessionBar' and saving the Open[0] price to a double variable called something like 'firstBarOfSessionOpen'.

    Then, a condition could be made that checks if firstBarOfSessionBar + 60 == CurrentBar and save the CurrentBar to a different int variable like 'bar60' and save the Close price to another double variable called like 'bar60Close'.

    Next, calculate the barsAgo for the Draw.Rectangle() startBarsAgo argument by calculating CurrentBar - firstBarOfSessionBar. And, calculate the endBarsAgo argument by doing something like CurrentBar - bar60. This will give you those barAgo Values.

    Then, call your Draw.Rectangle() method by passing your calculated barsAgo for startBarsAgo and endBarsAgo, and use the 'firstBarOfSessionOpen' and 'bar60Close' variables for your startY and endY arguments.

    Draw.Rectangle: https://ninjatrader.com/support/help..._rectangle.htm
    CurrentBar: https://ninjatrader.com/support/help...currentbar.htm
    IsFirstBarOfSession: https://ninjatrader.com/support/help...rofsession.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
      Hello man, thanks for the tip, I did it a little differently, but I managed to get the result. Now my problem is that I can't get all the sessions open in the window, in this example with 2 days loaded I was only able to add the images on the first day, I don't understand.
      Do you have any tips?

      Click image for larger version

Name:	Captura de tela 2023-12-06 201214.png
Views:	153
Size:	67.4 KB
ID:	1281084

      Comment


        #4
        Hello diatrader,

        Thanks for your notes.

        To have the rectangle draw object draw more than once on the chart window you should supply a unique Tag name when calling the Draw.Rectangle() method.

        From the Draw.Rectangle() help guide page the Tag parameter states:

        "A user defined unique id used to reference the draw object.

        For example, if you pass in a value of "myTag", each time this tag is used, the same draw object is modified. If unique tags are used each time, a new draw object will be created each time."


        Draw.Rectangle(): https://ninjatrader.com/support/help..._rectangle.htm

        Further, if the script is not behaving as expected then debugging prints would need to be added to the script to understand how the logic is processing.

        In the script add debugging prints one line above the conditions used to call the Draw.Rectangle() method and print out all the values used for the condition along with the Time[0]. And, add a print inside the condition to confirm the logic is triggering.

        Prints will appear in a New > NinjaScript Output window.

        Below is a link to a forum post that demonstrates how to use prints to understand behavior.
        https://ninjatrader.com/support/foru...121#post791121
        <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

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        637 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        366 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        107 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        569 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        571 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X