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

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 mattbsea, Today, 05:44 PM
        0 responses
        1 view
        0 likes
        Last Post mattbsea  
        Started by RideMe, 04-07-2024, 04:54 PM
        6 responses
        31 views
        0 likes
        Last Post RideMe
        by RideMe
         
        Started by tkaboris, Today, 05:13 PM
        0 responses
        2 views
        0 likes
        Last Post tkaboris  
        Started by GussJ, 03-04-2020, 03:11 PM
        16 responses
        3,281 views
        0 likes
        Last Post Leafcutter  
        Started by WHICKED, Today, 12:45 PM
        2 responses
        19 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Working...
        X