Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

error in Bars.GetOpen(0)

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

    error in Bars.GetOpen(0)

    Hello. I want to capture the value of Bars.GetOpen(0) in a variable and when I print it it gives me the value 13228.25 when its actual value is 13108.25. It is in a renko chart but in a candlestick chart it gives me the same error. What am I doing wrong? thank you.

    #2
    GetOpen(0) is asking for the open of the bar at index 0 in the chart, which is not the most recent bar (unless this is the first bar of the chart). Use Open[0] to get the open of the bar that is zero bars back.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Hello julifro,

      Thanks for your post.

      QuantKey_Bruce is correct. Bars.GetOpen(0) would get the open price of the bar for bar index 0 which is the first bar on the chart window.

      This is because the GetOpen() method takes a bar index argument and not a barsAgo argument. The bar index is the number of the bar on the chart. A bar index of 0 refers to the first bar on the chart since that bar has a bar index of 0.

      BarsAgo refers to the number of bars back from the current processing bar on the chart. A barsAgo value of 0 refers to the current processing bar on the chart.

      You could use Open[0] with the barsAgo value of 0 to get the open price of the current building bar on the chart.

      See the help guide documentation below.

      Bars.GetOpen(): https://ninjatrader.com/support/help...t8/getopen.htm
      Open: https://ninjatrader.com/support/helpGuides/nt8/open.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


        #4
        Thanks for the reply. I really want to place an order with a custom button. When I press the button, the order is sent correctly 15 ticks from Open[0] but when EnterLongStopLimit is the order and a new bar is created, the order moves. What I want is for the order not to move once I launch it and I don't know how to do it

        Comment


          #5
          Hello julifro,

          If the order price is changing, this would be because the order method is being called again.

          Change the logic to submit the order and then not evaluate as true until you want to submit a new order.

          One way to do that would be to use a bool. Require the bool to be false in the condition that submits the order. In the action block set the bool to true and submit the order. Set the bool back to false in another condition when you are ready for a new order.

          Be sure you are using IsLiveUntilCancelled as true so the order does not automatically cancel.
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          639 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
          572 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X