Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

fine fill emulation and orders hit order backtest

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

    fine fill emulation and orders hit order backtest

    Very often this example is used to answer how NinjaTrader implements fine fill emulation,

    You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by


    in back testing. The request usually relates to how NT implements "look inside the bar" or bar "magnifier" capability which are methods used to implement the feature in other trading platforms.

    If I'm reading this code example correctly then this approach only implements open of next bar market order fill emulation. Given that the open of the large bar and the open of the smaller bar are always the same, then this method does not really solve any issue (even for market orders).

    The requirement and reason for "Look Inside the bar" backtesting, when using managed intra bar order methods (limit and stop market, stop limit) that are in force for the period of the large bar. The issue is not fill price (although that is important) its really to ascertain the order in which intra bar orders are hit, in the case where both stops and targets are active. BTW LIB also vital if trailing stop with percent give back is used too, as just using the OHLC on large bars will be overly optimistic results.

    How can NT implement, with managed orders (limit and stop) with Time to Live the same as the large bar, but use a lower time-frame bars to see if they are hit in back testing?
    Last edited by lavalampmj; 12-17-2013, 01:25 AM.

    #2
    Hello lavalampmj,

    The example is just basically that, an example of how you can add a smaller series to your strategy and set your orders to submitted on the smaller series to have better fills. You would just change the "EnterLong(1, 1, "Long: 1min");" and the Conditions to what your conditions are. For example:

    Code:
    protected override void OnBarUpdate()
    {
    			
    	if (BarsInProgress == 0)
    	{
    		if (//TradeContitions)
    		{
    			/* The entry condition is triggered on the primary bar series, but the order is sent and filled on the secondary bar series. The way the bar series is determined is by the first parameter: 0 = primary bars, 1 = secondary bars, 2 = tertiary bars, etc. */
    
    			EnterLongLimit(1, true, 1, Low[0]-8*TickSize, "Long: 1min");					
    		}
    //rest of code


    This way it will submit the order on the 1 minute time frame which you can do with the Stop and Target orders as well. We also have another example of how to submit stop and targets orders at the following link.
    The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()


    But in this example you would change the order from for example: "ExitLongStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - 4 * TickSize, "MyStop", "MyEntry");"

    To "ExitLongStop(1, true, execution.Order.Filled, execution.Order.AvgFillPrice - 4 * TickSize, "MyStop", "MyEntry");"

    To make sure that it is on the right BIP.

    Let me know if you have any questions.
    JCNinjaTrader Customer Service

    Comment


      #3
      what is the TTL when placing on second bar series?

      I'm still confused how this code provides the equivalent of LIB when using "managed orders" for the following reason:

      What is the TTL for the managed intrabar order types (limit or stop) when placed on secondary bars? In our example, where the primary bar is 5 min and secondary bar is 1 min, doesn't the order expire at the end of the 1 st minute, if not hit?

      If that's the case, then this is not the same as placing an order that has a TLL the same as the primary bar as the barsinprogress == 0 will execute exactly once every 5 mins.

      I understand that I can use unmanaged order types and implement whatever TTL directly in my code. This question relates to managed order types.

      Thanks for clearing this up. I obviously don't get something.

      Comment


        #4
        Hello lavalampmj,

        I am not sure what "TTL" stands for but using the EnterLongLimit() method that I showed you an example of it sets the "liveUntilCancelled" order to "true" so that the order will not expire.

        EnterLongLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, string signalName)

        Please view our Help Guide below for a list of different overload method for the EnterLongLimit().
        JCNinjaTrader Customer Service

        Comment


          #5
          TTL = Time to Live. Its a common order parameter in other trading platforms.

          I get it now, you need to implement the control yourself using events to cancel and replace. It's not available under "managed orders" approach, where the heavy work is done for you.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          656 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          371 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          579 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X