Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

calculated on Bar Close

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

    calculated on Bar Close

    I am working with calculatedOnBarClose = TRUE.
    instrument 0 is on 30minute timeframe
    instrument 1 is on 1minute.

    Orders will be triggered on barClosing every 30 minutes.
    My IF condition compares intrument 0 with intrument 1,

    IF Medians[0][0] -Medians[1][0] < -X
    {
    ifposition == long ->close position
    ifposition ==flat --> sell short
    }
    IF Medians[0][0] -Medians[1][0] > X
    {
    ifposition == short->close position
    ifposition ==flat --> go long
    }

    My problem is I am short and then on Bar close, position is closed and I go short again almost at miliseconds after.
    My question is: how can I avoid double trade and stay short wirhout close my short position? (save commisions). This weird reaction could be due the contrary condition was reacted in the middle of 30 minutes bar?

    #2
    Hello dafonseca,

    Thank you for your inquiry.

    If you wish for your orders to be triggered on the 30 minute time frame, you'll want to ensure that you are utilizing BarsInProgress == 0.

    Without a BarsInProgress check, all of your logic will run either when the primary Bars object (30 minute time frame) or if the secondary Bars object (1 minute time frame) calls OnBarUpdate().

    More information about working with multiple time frames can be found in the help guide at this link: https://ninjatrader.com/support/help...nstruments.htm

    Just to clarify, are both time frames the same instrument?
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      let me try to understand this:

      I am using 30 minutes timeframe on instrument 0.
      when the Bar closes. I have this inside the IF condition:

      CONDITION
      if position == long ->close position
      if position ==flat --> sell short

      is the systemable to close the position (inverted direction) and order the new short position on the same Bar?
      Or the sell short will need to wait the next Bar..

      Comment


        #4
        Hello dafonseca,

        If the position is not flat by the time your code evaluates to check if you are in a flat position, then the sell short will not occur until the next bar.
        Zachary G.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 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
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X