Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is it possible to do Intra bar order generation in a strategy

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

    #16
    The arrow is drawn with a 1-second timestamp resolution and is not specific to a bar. These bars are most likely in the same second? If so, the bar will shift to the right until there is a bar that is not in the same second.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #17
      Thank you, Bruce. The bars have 1-minute setting. The arrows are shifted to the right with each new minute bar. Also at exit. I would like it so that both arrows remain at the Entrybar, the wide one to mark the EntryBar and the small arrow to mark the Entrylevel. Is this possible, as well as with the historical signals? Thank you.

      Comment


        #18
        Not sure - as an idea, try placing your orders against that 1-tick series you have added by changing the first parameter to your EnterLongLimit to 1 instead of 0.
        Bruce DeVault
        QuantKey Trading Vendor Services
        NinjaTrader Ecosystem Vendor - QuantKey

        Comment


          #19
          Thanks, tested it with the tickstream, it is the same phenomenon. And after 15min the dislocation stops and the arrows remain at the position 15min after Entry. Entry and Exit are marked with red circle in the picture.
          Possibly due to the market data delay of 15min or so?

          Click image for larger version  Name:	position_arrow_changes2.png Views:	0 Size:	21.7 KB ID:	1251048
          Last edited by signalworks; 05-11-2023, 08:08 AM.

          Comment


            #20
            Hello signalworks,

            For orders to appear on the same bar as trigger bar, the order must be submitted before the bar closes.

            This means that 1-tick intra-bar granularity must be implemented and orders submitted to the BarsInProgressIndex of that 1 tick series, and TickReplay and Calculate.OnPriceChange/.OnEachTick must be used.

            Below is a link to a forum post that details.



            It might be that you are either not submitting the order during the correct BarsInProgress, or that the orders are being submitted with the incorrect BarsInProgressIndex as the

            Use prints to provide information to understand the behavior.

            Print the time of the bar, print BarsInProgress, print the barsInProgressIndex supplied to the order method, print all values in the condition that submits the order, print the order object in OnOrderUpdate(), include labels for all values, enable TraceOrders.

            Below is a link to a forum post that demonstrates using Print() and TraceOrders to understand behavior.


            Chelsea B.NinjaTrader Customer Service

            Comment


              #21
              Thank you, Chelsea. I print, I use BarsInProgress, BarsInProgressIndex and UpdateEachTick. By using the EnterLongStopMarket() method, the signal intrabar is generated correctly. (with BarsInProgress=0 and BarsInProgress=1). However, the result is the same regardless of BarsInProgress/BarsInProgressIndex, that the PositionMarker arrow is shifted to the right with each new bar. The order is executed only once, but the arrows "wander".
              From my knowledge the TimeStamp probably plays a role here, since that of the signal and the system time stamp are 15Minuten different due to the delayed data. Could the connection be correct?
              Here is an excerpt from the print statement:​

              11.05.2023 19:05:06 Strategy 'Test_v1_0/291564129': Interne SubmitOrderManaged() Methode eingegeben bei 11.05.2023 19:05:06: BarsInProgress=1 Aktion=Buy OrderTyp=StopMarket Anzahl=1 LimitPreis=0 StopPreis=15911 SignalName='LE' FromEntrySignal=''
              Time: 11.05.2023 18:51:00, OnOrder: Order: orderId='5bd9a8a5883a48868dde6e0571427143' account='Sim101' name='LE' orderState=Submitted instrument='FDAX 06-23' orderAction=Buy orderType='Stop Markt' limitPrice=0 stopPrice=15911 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=32 time='2023-05-11 19:05:06' gtd='2099-12-01' statementDate='2023-05-11'
              Time: 11.05.2023 18:50:06 sent OrderLong, BarsInProgress: 1, Systemzeit: 19:05
              ......
              .......
              Time: 11.05.2023 18:51:00, OnOrder: Order: orderId='5bd9a8a5883a48868dde6e0571427143' account='Sim101' name='LE' orderState=Accepted instrument='FDAX 06-23' orderAction=Buy orderType='Stop Markt' limitPrice=0 stopPrice=15911 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=32 time='2023-05-11 19:05:06' gtd='2099-12-01' statementDate='2023-05-11'​
              Click image for larger version

Name:	position_arrow_changes_3.png
Views:	133
Size:	6.1 KB
ID:	1251102
              Attached Files

              Comment


                #22
                signalworks You have delayed data, so the order's timestamp is "now" while the bars that look like now are 15 minutes ago. When 15 minutes has passed since the order was placed, the bars have caught up with the order's time and it will stay there. Until then, it's moving it as far right as possible since the order's time is after the time of the last bar. Boom. Not a bug. Sign up for paid market data and quit wasting time with delayed data causing you these problems.

                UNLESS the bug is that orders placed on delayed data are supposed to have a timestamp that is delayed as well. BUT, that would not make any sense because you wouldn't be able to compare order times with the actual time that it is, and not every data series may have the same delay. BOTTOM LINE - sign up for market data.
                Last edited by QuantKey_Bruce; 05-11-2023, 12:00 PM.
                Bruce DeVault
                QuantKey Trading Vendor Services
                NinjaTrader Ecosystem Vendor - QuantKey

                Comment


                  #23
                  Hello,
                  With real-time data, the shifting problem of the signal arrow is actually off the table
                  Now, however, there is still a further problem, which I can not explain:

                  First of all: with the realtime signal the problem is not present, only with all historical signals:
                  When the EntryStop is executed, a StopLossLevel is generated. However, the level is now already plotted at the pre-bar before the signal. It is obviously a plotting problem, because the times in the print are correct. BarTimeStamp is the close time. In the print window it is to be seen that at the marked line at 18:31:09 the PlotStatement is run through for the first time, thus already in the 18:32:00 bar. In the chart, however, the level of 16011 can already be seen in the 18:31:00 bar. How does this happen or can it be fixed?

                  Plot-Code - BarsInProgress=1 uses a 1-tick data series:

                  Code:
                  #region MARKETPOSITION
                  if (BarsInProgress == 1)
                  {
                       switch (Position.MarketPosition)
                       {
                                          case MarketPosition.Flat:
                                              mpos[0] = 0;
                                              break;
                  
                                          case MarketPosition.Long:
                                              mpos[0] = 1;
                                              break;
                  
                                          case MarketPosition.Short:
                                              mpos[0] = -1;
                                              break;
                  
                                          default:
                                              mpos[0] = 0;
                                              break;
                        }
                  }
                  #endregion​
                  
                  if (BarsInProgress == 1)
                  {
                                      if (PLOT_SL
                                          && level_sl > 0.0
                                          && mpos[0] != 0
                                          )
                                      {
                                          plSl[0] = level_sl;
                  
                                          if (PRINT_Output)
                                              Print(string.Format("Plot: Time: {0}, MPos: {1}, SLLevel: {2}", Time[0], mpos[0], level_sl));
                                      }
                  }​
                  Click image for larger version

Name:	print_plot_offset.png
Views:	163
Size:	128.0 KB
ID:	1251177
                  Click image for larger version

Name:	entrybar_timestamp.png
Views:	122
Size:	31.6 KB
ID:	1251178Click image for larger version

Name:	entrybar-before_timestamp.png
Views:	120
Size:	31.0 KB
ID:	1251179

                  Comment


                    #24
                    I'm not sure from the code snippet above what your Calculate is set to but if it is Calculate.OnBarClose the bar that you're saying it's already into isn't exposed yet. If that is the case, changing it to Calculate.OnPriceChange would result in the later bar being exposed and thus when you plot [0] back it would be shifted one bar right. However, you would have to check your code to see if the rest of it can handle this as you would then get OnBarUpdate() intrabar instead of end of bar on that chart time frame.
                    Bruce DeVault
                    QuantKey Trading Vendor Services
                    NinjaTrader Ecosystem Vendor - QuantKey

                    Comment


                      #25
                      Thank you, Bruce. The code runs with Calculate.OnEachTick.

                      Comment


                        #26
                        Hi Chelsea B., do you have any idea what this could be due to? (#23) Thank you!

                        Comment


                          #27
                          Hello signalworks,

                          Thanks for your notes.

                          If this is occurring realtime and you have delayed data then this could occur where the execution plot marker is off. You would need to fund the account and subscribe to realtime market data if this is the case.

                          If this is occurring historically, you would need to use Tick Replay along with an added 1-tick series to have logic processed intra-bar and have orders filled intrabar. Tick Replay would be used to have the logic process OnEachTick or OnPriceChange with historical data, but this does not allow for intra-bar order fills. You would need to add a single-tick data series and submit orders to that single-tick data series for a strategy that uses Tick Replay.

                          ​Please reference the SampleIntrabarBacktest example and the following Help Guide links for more information.

                          SampleIntrabarBacktest 'Backtesting NinjaScript Strategies with an intrabar granularity': https://ninjatrader.com/support/helpGuides/nt8/backtesting_ninjascript_strate.htm

                          TickReplay: https://ninjatrader.com/support/help...ick_replay.htm

                          Developing for Tick Replay: https://ninjatrader.com/support/helpGuides/nt8/developing_for__tick_replay.htm?zoom_highlightsub= developing+for+tick+replay

                          Additional information may be found in this NinjaTrader Forum post: https://ninjatrader.com/support/forum/forum/ninjatrader-8/strategy-development/100192-comparing-real-time-historical-and-replay-performance?t=102504
                          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                          Comment


                            #28
                            Thank you, Brandon. TickReplay now correctly plots the exit levels mentioned above from the entry candle. I have a few questions about this later.

                            However, in TickReplay mode, the chart no longer shows the market data up to the current day, breaks off in the middle of 12/05 and then shows the current bar from today (FDAX 06-23, market data via TWS connection, which shows the data throughout without TickReplay).
                            Is there anything that needs to be set somewhere besides the TickReplay CheckBox? Thanks a lot!​

                            Comment


                              #29
                              Ok, checked, the market data retrieval was interrupted. Another thing: when I open a new chart window, signals are displayed although there is no strategy in the chart, also no other charts open. In the options the two checkboxes are enabled: Clear Entry signals on Disable strategy, Clear Exit signals on Disable strategy.

                              Comment


                                #30
                                Hello signalworks,

                                Thanks for your note.

                                To clarify, are you referring to historical orders on the chart that have been placed on that instrument previously?

                                Are the options you are referring to located in the Tools > Options > Strategies tab and are called "Cancel entry orders when a strategy is disabled" and "Cancel exit orders when a strategy is disabled"?

                                These options do not clear the order markers on a chart for previous orders that are placed. Historical order markers will remain on the chart.

                                "Cancel entry orders when a strategy is disabled" enables or disables automatic cancellation of a NinjaScript strategy's entry orders when the strategy is disabled.

                                "Cancel exit orders when a strategy is disabled" enables or disables automatic cancellation of a NinjaScript strategy's exit orders when the strategy is disabled.

                                See this help guide page: https://ninjatrader.com/support/help...riptProperties

                                Generally, when you open a New > Chart window with Chart Trader enabled and no strategies added, you are able to see order markers for orders that were previously placed on that instrument. See the attached screenshot.
                                Attached Files
                                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by NullPointStrategies, 03-13-2026, 05:17 AM
                                0 responses
                                86 views
                                0 likes
                                Last Post NullPointStrategies  
                                Started by argusthome, 03-08-2026, 10:06 AM
                                0 responses
                                151 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                79 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                53 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                61 views
                                0 likes
                                Last Post TheRealMorford  
                                Working...
                                X