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

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:	71
Size:	9.1 KB
ID:	1281037


    Click image for larger version

Name:	mnq.png
Views:	92
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
    Brandon H.NinjaTrader Customer Service

    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:	73
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
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Haiasi, 04-25-2024, 06:53 PM
        2 responses
        17 views
        0 likes
        Last Post Massinisa  
        Started by Creamers, Today, 05:32 AM
        0 responses
        5 views
        0 likes
        Last Post Creamers  
        Started by Segwin, 05-07-2018, 02:15 PM
        12 responses
        1,786 views
        0 likes
        Last Post Leafcutter  
        Started by poplagelu, Today, 05:00 AM
        0 responses
        3 views
        0 likes
        Last Post poplagelu  
        Started by fx.practic, 10-15-2013, 12:53 AM
        5 responses
        5,408 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Working...
        X