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

On Bar Close

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

    On Bar Close

    I am testing a strategy where the primary time frame is a range bar (50 ticks).

    The exit is up or down an Average True Range.

    The problem is the target or stop is hit but the position isn't closed until the primary bar completes, which can be quite far off.

    I tried to add a secondary 1 minute time series and also tried setting on bar close to on each tick... I am getting the same results.

    Is there any way around this?

    thank you


    #2
    Hello sdauteuil,

    Thanks for your post.

    How are you testing this, in the strategy analyzer, Live data, or playback with Market replay data?

    What exit methods are you using?

    What is the Calculate setting of the strategy?
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Testing with the strategy Analyzer

      I am setting a variable equal to a 14 period average true range when the strategy is flat.

      I have exits set to sell at the average position price Plus or Minus the ATR. This logic works fine.
      The problem is it doesn't close when the exit price is hit it waits till the bar closes after hitting the exit price.


      Click image for larger version

Name:	NT Set Atr.JPG
Views:	259
Size:	57.2 KB
ID:	1105139

      Click image for larger version

Name:	NT Atr Targ.JPG
Views:	222
Size:	57.7 KB
ID:	1105140Click image for larger version

Name:	NT Atr Stop.JPG
Views:	209
Size:	57.3 KB
ID:	1105141

      Comment


        #4
        Hello sdauteuil,

        Thanks for your reply.

        In the strategy analyzer, the strategy will only run as if Calculate.OnBarClose was set regardless of how you have the Calculate set. This is because the strategy analyzer only uses historical data that does not include all of the ticks of the bar and only the OHLC values of the bar to work with. the code then would only execute at the end of the bar and order submitted would be filled on the next bar.

        You could try using Calculate.OnEachTick or Calculate.OnPriceChange with tick replay enabled in the strategy analyzer, however, you would need to ensure that you have historical tick data available for the duration of the analysis period. This will be significantly slower due to the tick data processing so I would suggest just check a few recent days for the test period to see if that helps.

        An alternative would be to unlock the strategy code and set the orders to the 1 minute series instead of the range bars.

        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Graci117, Yesterday, 11:40 PM
        4 responses
        21 views
        0 likes
        Last Post Graci117  
        Started by cmtjoancolmenero, Today, 02:31 PM
        4 responses
        8 views
        0 likes
        Last Post cmtjoancolmenero  
        Started by mintos, 04-02-2024, 08:22 PM
        2 responses
        17 views
        0 likes
        Last Post mintos
        by mintos
         
        Started by Taddypole, Today, 02:25 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by tradebot, Today, 01:25 PM
        2 responses
        11 views
        0 likes
        Last Post tradebot  
        Working...
        X