Announcement

Collapse
No announcement yet.

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.

    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.

        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.

            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 NullPointStrategies, Yesterday, 05:17 AM
              0 responses
              71 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              143 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              76 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              47 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              51 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X