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

Using Enter Stop Market with Tick Replay and Bar Index

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

    Using Enter Stop Market with Tick Replay and Bar Index

    Hey guys,

    I could use some help understanding why my orders don't fill on backtests when I use the Tick Replay checkbox. I have a custom indicator that needs to have 2 additional data series loaded and it needs Tick Replay. So, when I go to run my simple strategy, I can see the strategy attempting to place EnterLongStopMarket orders 1 or 2 ticks above the current High but they do not fill. I've tried changing that Bar Index from 0 - 2 and it didn't change. Can you help clarify?
    I've attached my simple strategy and if need be, the indicators required to run it.
    Attached Files

    #2
    Hello PN720,

    Thank you for the post.

    One way to determine what is going on would be to use TraceOrders. I suspect from the syntax you used that the order is being expired.


    You are currently using EnterLongStopMarket(0, false, 1, High[0] + 1 * TickSize, "Long1");

    isLiveUntilCancelled is false so this order can be expired after 1 bar elapses unless the order method is called again on the next bar, if your condition fails to continue to be true it should be expiring the order.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,

      I changed that from false to true and I can see orders being placed now. But, I thought that under Managed Orders, if the next bar doesn't fill the order, then it is cancelled, right? For my other strategies, this works:

      EnterLongStopMarket(1, EntryPrice , "Long1");

      Can you help me understand why?

      Comment


        #4
        Hello PN720,

        Correct under the managed approach if the next bar is processed and the entry method was not called again or the order did not fill it would be expired. With tick granularity added and secondary series, this would decrease the time the order stays active if your condition fails to remain true. this could also decrease the ranges of prices the order will see before expired preventing fills. I can't really speak of differences between your scripts as I don't have the full context however I would estimate it is likely a granularity difference if the other script had different series or was not being used with TickReplay.

        I look forward to being of further assistance.



        JesseNinjaTrader Customer Service

        Comment


          #5
          Since I'm going to change over any of my scripts that use Tick Replay to IsLiveUntilCancelled = True, how can I cancel the order if the close of the next bar doesn't fulfill it? I'm using Calculate.OnBarClose for my strategy if that makes a difference.

          Comment


            #6

            Hello PN720,

            You would need to use Order objects as that is what CancelOrder requires. In the sample that you provided that is the very minimum code required to place an order with targets, however, that does not account for all use cases mainly just the case where prices will fill the order within 1 bar. The managed approach cleans up for you in case the order did not fill. When you have finer granularity such as 1 tick the prices may not fill that order which then requires IsLiveUntilCancelled. Because of this, you may need to add some more logic to account for the now active order.

            We have a sample of using CancelOrder here: https://ninjatrader.com/support/help...thod_to_ca.htm

            Depending on your goal, you would need to call CancelOrder when appropriate. The sample you provided is a multi-series but you do not use BarsInProgress to know which series is currently calling OnBarUpdate. This means OnBarUpdate is being called for each 1 tick(tick replay), 3 minutes, 9 minutes and whatever the primary series is. 1 bar is currently at the granularity of 1 tick, so additional logic is needed to make the script understand what 1 bar should be. There are some examples of working with multiple series in the following page, you would likely need a condition for one of the BarsInProgress or to also use IsFirstTickOfBar to denote when a bar closes: https://ninjatrader.com/support/help...lightsub=multi

            I would also suggest reading the tick replay documentation if you have not, this is not generally to be used in a backtest as it does not add any extra accuracy. You can also look at using the higher order fill resolution:




            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by love2code2trade, Yesterday, 01:45 PM
            4 responses
            28 views
            0 likes
            Last Post love2code2trade  
            Started by funk10101, Today, 09:43 PM
            0 responses
            7 views
            0 likes
            Last Post funk10101  
            Started by pkefal, 04-11-2024, 07:39 AM
            11 responses
            37 views
            0 likes
            Last Post jeronymite  
            Started by bill2023, Yesterday, 08:51 AM
            8 responses
            45 views
            0 likes
            Last Post bill2023  
            Started by yertle, Today, 08:38 AM
            6 responses
            26 views
            0 likes
            Last Post ryjoga
            by ryjoga
             
            Working...
            X