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

Order Execution Time Stamp

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

    Order Execution Time Stamp

    Hello,

    when I apply a stratgy on a chart and an order gets filled on the historical data, I´m wondwering why the order name gets printed below the following bar.

    Would you please help me to figure out, when the order gets exactly filled, e.g. in the example below at Bar0 (OnExecution was called) or Bar1(Order name was ploted in the chart).

    I created for test purpose a simple dummy strategy (see attached files), which submits a market order and prints CurrentBar and the time stamp in Time[0] on every OnBarUpdate and OnExecution method call.

    As you can see on the screenshot, the strategy plots the blue dot on currentbar 0, but the blue arrow above and the order name at currentbar 1.

    The printing output shows also, that the order gets executed on currentbar 0.

    currentbar 0 , time stamp 01.09.2011 23:00:00
    Order submited at: currentbar 0 , time stamp 01.09.2011 23:00:00
    OnOrderUpdate: CurrentBar 0 at 01.09.2011 23:00:00, orderState PendingSubmit
    OnOrderUpdate: CurrentBar 0 at 01.09.2011 23:00:00, orderState Accepted
    OnOrderUpdate: CurrentBar 0 at 01.09.2011 23:00:00, orderState Working
    OnOrderUpdate: CurrentBar 0 at 01.09.2011 23:00:00, orderState Filled
    OnExecution: CurrentBar 0 at 01.09.2011 23:00:00
    currentbar 1 , time stamp 02.09.2011 23:00:00
    EntryOrder OrderState is Filled Quantity 1
    currentbar 2 , time stamp 05.09.2011 23:00:00
    EntryOrder OrderState is Filled Quantity 1
    ...........
    currentbar 6 , time stamp 09.09.2011 23:00:00
    EntryOrder OrderState is Filled Quantity 1
    OnOrderUpdate: CurrentBar 6 at 09.09.2011 23:00:00, orderState PendingSubmit
    OnOrderUpdate: CurrentBar 6 at 09.09.2011 23:00:00, orderState Accepted
    OnOrderUpdate: CurrentBar 6 at 09.09.2011 23:00:00, orderState Working
    OnOrderUpdate: CurrentBar 6 at 09.09.2011 23:00:00, orderState Filled
    OnExecution: CurrentBar 6 at 09.09.2011 23:00:00

    I´m a little confused about that. I want to implement a trailing stop and visualize it´s actual position via DrawDot. Before using any work-arounds like setting barsAgo to -1, I want to understand your ploting logic and whats the reason behind this mismatch.

    Thank you in advance,
    TUISerge
    Attached Files

    #2
    here for a quick overview the logic of the startegy:

    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    Enabled = true;
    BarsRequired = 0;

    }


    protected override void OnBarUpdate()

    {
    Print("currentbar "+ CurrentBar + " , time stamp " +Time[0]);
    if (entryOrder == null)
    {
    entryOrder = EnterLong(1, "DummyTestOrder");
    Print("Order submited at: currentbar " + CurrentBar + " , time stamp " +Time[0]);
    }
    else
    {
    Print("EntryOrder OrderState is " + entryOrder.OrderState + " Quantity " + entryOrder.Quantity );

    }

    }

    protected override void OnExecution(IExecution execution)

    {
    Print("OnExecution: CurrentBar "+ CurrentBar + " at " +Time[0] );
    DrawDot("Dot" +CurrentBar, true, 0, 2*Low[0]-Close[0], Color.Blue);

    }


    protected override void OnOrderUpdate(IOrder order)

    {
    Print("OnOrderUpdate: CurrentBar "+ CurrentBar + " at " +Time[0] + ", orderState " + order.OrderState );
    }

    Comment


      #3
      Hello TUISerge,

      This is the timing of all orders in a historical or backtest. Conditions are evaluated each bar. If true, the order is submitted to the next bar following the condition. The order placement logic technically happens at the end of the bar, but it's visualized on the next bar. You can see source code for historical fills at:
      Documents\NinjaTrader 7\bin\custom\type\@DefaultFillType and @LiberalFillType.

      You can have immediate submission only in real time with CalculateOnBarClose = false. This is the best place to visualize trail stop mechancis.
      Ryan M.NinjaTrader Customer Service

      Comment


        #4
        Thank you for the explanation.
        I took a look on the FillTypes code. Just to be sure, does NextLow and NextHigh return what I think it should, namely the Low/High of the next (following) Bar?

        To sum up, on close of the current bar the startegy evaluates my entry conditions . If true and it should submit f.e. a stop order, than it aditionaly checks , if the order would get filled during the next bar. This happens also on close of this current bar and NOT on close of the next bar (where the stop order would practically be triggered) Right? (I´m talking about historical and given CalculateOnBarClose = true )

        For the sake of completeness, when do CurrentBar or Time[0] count up? Already on the Close of the previous bar, on the Opening of the actual one or only with it´s Close.

        Thank you for your fast answer, really apretiate it!

        Comment


          #5
          Hello,

          Unfortunately we have no documentation on this to refer too and since there is no documentation this is unfortunately unsupported. This is something that you have to get in there and experiment to find what you can do in here.

          NinjaTrader is incredibly flexible and you can go in and change the internals however this is something our NinjaScript support team is unable to support.

          As far as trying to point you in the right direction, yes I believe your understandings are correct.

          Good Luck!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by TradeSaber, 05-17-2024, 10:33 PM
          2 responses
          15 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by Marklhc1988, 04-19-2023, 11:11 AM
          13 responses
          584 views
          1 like
          Last Post NinjaTrader_BrandonH  
          Started by ttrader23, Today, 09:33 AM
          2 responses
          16 views
          0 likes
          Last Post ttrader23  
          Started by ETFVoyageur, Yesterday, 12:45 AM
          2 responses
          17 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by ETFVoyageur, Yesterday, 10:27 AM
          3 responses
          23 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X