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

strategy enters trade one candle too late

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

    strategy enters trade one candle too late

    Hello guys,

    my strategy is set to "Calculate.OnEachTick". To define my entry I use "IsFirstTickofBar" as I need a bar closure for that. After the entry is defined I want to enter whenever my level is reached.
    See screenshot attached. Horizontal blue line is the entry trigger to go short. Even so the short is triggered at 14:45 - as shown in the output log, the entry only occurs at 14:48.
    Is there something I am missing here?

    Thanks
    Florian

    #2
    Hello Florian,

    Thank you for your post.

    I recommend reviewing the reference sample that demonstrates how to separate logic between calculating on bar close or on each tick that may be found here:


    If you would like to review more information about when your order is submitted, you could enable TraceOrders in your script in State.SetDefaults and review that additional output to better understand when your order is being submitted. For more information regarding TraceOrders:



    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Hello Emily,

      thanks for the quick reply.
      With TraceOrders enabled:

      --------------------------
      SIGNAL 28/02/2023 11:36:00
      VWAP AT: 3981,75415073587
      ENTRY: 3990,25
      STOP LOSS: 3989,25
      --------------------------
      28/02/2023 11:45:00 Strategy 'ICT002/267644109': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Long1' Mode=Price Value=3989,25 IsSimulatedStop=False IsMarketIfTouched=False
      28/02/2023 11:45:00 Strategy 'ICT002/267644109': Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Long1' Mode=Ticks Value=12 IsSimulatedStop=False IsMarketIfTouched=False
      28/02/2023 11:45:00 Strategy 'ICT002/267644109': Entered internal SubmitOrderManaged() method at 28/02/2023 11:45:00: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3990,25 StopPrice=0 SignalName='Long1' FromEntrySignal=''
      28/02/2023 11:45:00 Strategy 'ICT002/267644109': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Long2' Mode=Price Value=3989,25 IsSimulatedStop=False IsMarketIfTouched=False
      28/02/2023 11:45:00 Strategy 'ICT002/267644109': Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Long2' Mode=Ticks Value=16 IsSimulatedStop=False IsMarketIfTouched=False
      28/02/2023 11:45:00 Strategy 'ICT002/267644109': Entered internal SubmitOrderManaged() method at 28/02/2023 11:45:00: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=3990,25 StopPrice=0 SignalName='Long2' FromEntrySignal=''
      --------------------------
      LONG AT: 28/02/2023 11:45:00
      VWAP AT: 3982,17709949129
      TAKE PROFIT: 4
      --------------------------

      It looks like the order was filled at 11:45:00 to me. That would mean it simply paints it wrong on the chart? As there the entry is one candle later.
      But it seems suspicious that the entry is at second 00...I would expect the order to be filled when we cross the level and not at 00.

      What is your opinion on that?​

      Comment


        #4
        Hello Florian,

        Thank you for your reply.

        Please clarify; is this happening when testing on live data or when running a backtest on the Strategy Analyzer?

        I look forward to your reply.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          Hey Emily, this is while testing on historic data - running a backtest.

          Comment


            #6
            Hello schollf,

            Thank you for that information.

            In that case, what you are reporting is expected behavior. There are some known discrepancies between running a strategy in real-time and running a backtest. A page about those discrepancies may be found in the help guide here:


            Order fills during a backtest are determined on OHLC data from a bar, which is essentially like using "On Bar Close" even if your strategy is set to On price change or On each tick. In order to get more granular fills, there are two options. One option is to could set the order resolution to "High" which can add a secondary bar series to base the order fills on. The most granular option is a 1-tick series, though selecting this will cause the backtest to use more resources to process and could result in longer backtest times. For more information about order fill resolution:


            Your second option is to adjust the logic in your strategy to submit orders to a single tick data series. We have a reference sample "Backtesting NinjaScript Strategies with an intrabar granularity" that may be found here:


            Please let me know if I may be of further assistance.
            Emily C.NinjaTrader Customer Service

            Comment


              #7
              Hello Emily, looking at the provided links I think this could solve my issue. Will come back if I need further assistance. Thank you very much for your support

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by cre8able, Yesterday, 01:16 PM
              3 responses
              11 views
              0 likes
              Last Post cre8able  
              Started by Harry, 05-02-2018, 01:54 PM
              10 responses
              3,203 views
              0 likes
              Last Post tharton3  
              Started by ChartTourist, Today, 08:22 AM
              0 responses
              6 views
              0 likes
              Last Post ChartTourist  
              Started by LiamTwine, Today, 08:10 AM
              0 responses
              2 views
              0 likes
              Last Post LiamTwine  
              Started by Balage0922, Today, 07:38 AM
              0 responses
              5 views
              0 likes
              Last Post Balage0922  
              Working...
              X