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

    #31
    Thank you, Brandon. I deleted the historical signals with a DB reset (via Tools -> Datenbankmanagement -> DB Reset)
    Is the execution data in the database relevant for backtesting? Does it have to be reset manually each time?


    Click image for larger version

Name:	db_reset.png
Views:	147
Size:	73.8 KB
ID:	1251658

    Comment


      #32
      Hello signalworks,

      Thanks for your note.

      Historical trade data refers to any previous trades that you have made. The Historical executions checkbox seen in the screenshot you shared refers to the executions on the Executions tab of the Control Center. An execution is another name for a fill of an order.

      Typically the database does not need to be reset to backtest strategies.

      You could consider using the Strategy Analyzer window to backtest strategies on historical data.

      See this help guide page about performing a backtest in the Strategy Analyzer:


      The Playback connection could be used with Market Replay data to test a strategy as if it were running in realtime.

      See this help guide page about using Playback: https://ninjatrader.com/support/help...connection.htm
      <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


        #33
        Hello Brandon,

        There is still a problem with the ordering: The print shows that an order will be sent on 05/17/23 at 3:00 p.m. However, the trace entry for this shows a time stamp of 1:40:18 p.m. The order is not executed and displayed despite touching the stop. You can see the correlation between the two print entries based on the stop price of 16,027.

        Previously, I had generated the order in real time. Shortly thereafter I had reloaded the script in the chart (via the Ninjascript reload function in the context menu). After reloading, the signal is no longer displayed. Does something now have to be reset somewhere because NT still recognizes this position? Thank you.​

        Click image for larger version

Name:	trace_earlier_chart.png
Views:	157
Size:	13.2 KB
ID:	1251726
        Click image for larger version

Name:	trace_earlier.png
Views:	125
Size:	83.4 KB
ID:	1251729
        Attached Files

        Comment


          #34
          Hello signalworks,

          Thanks for your note.

          The time behavior you are reporting could be due to where you are printing in the script and if you are printing Time[0]. You could print from OnOrderUpdate() if you wanted to know the actual time when the strategy sees that the order was submitted.

          In the strategy, add a print to the script that prints out the time and order object in OnOrderUpdate() to know the actual time when the strategy sees the order was submitted.

          When you reload the NinjaScript on the chart and the order signal is gone then that means the order did not get submitted. This is likely a difference in how the logic is executed real-time vs historical.

          See this forum thread about comparing realtime to historical: https://forum.ninjatrader.com/forum/...nce#post100192
          Last edited by NinjaTrader_BrandonH; 05-17-2023, 11:03 AM.
          <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


            #35
            Hello,
            I would like to ask a few additional questions on the subject of history and real time, as some things are not quite clear to me:

            What does and for what do I need the translation of historical orders in live orders in realtime operation?

            Code:
            //Convert any old historical order object references to the live order submitted to the real-time account
            if (order != null && order.IsBacktestOrder && State == State.Realtime)
                 order = GetRealtimeOrder(order);​
            My requirement is, I want to have EntryStopMarket() signals on certain condition levels, which allow me to do a historical backtest. Now whether these would have been executed in realtime with gap/slippage/etc. is not really relevant. What is important are the levels. That works also so far for the time being. Does anything else have to be done for the live switching? When I go live, the strategy should simply leave the historical signals where they were before and generate new signals and execute the orders accordingly. What is the purpose of the above code? Is it important for my purpose?​ Thank you!

            Comment


              #36
              Hello signalworks,

              Thanks for your note.

              If you are tracking order objects, is important that you update the order reference to ensure that it is now using the correct order details. GetRealtimeOrder() would be used to update order references.

              If you DO NOT update a historical order reference, and then attempt to cancel/change that order after it has been submitted in real-time, your strategy will be disabled with a message similar to: "Strategy has been disabled because it attempted to modify a historical order that has transitioned to a live order."

              Please see the help guide documentation linked below for deatails about transitioning order references from historical to live.

              Transitioning order references from historical to live: https://ninjatrader.com/support/help...tm#Transitioni ngorderreferencesfromhistoricaltolive
              GetRealtimeOrder(): https://ninjatrader.com/support/help...ltimeorder.htm

              ​Here is a reference sample demonstrating converting any old historical order object references to the new live order submitted to the real-time account as we transition from historical: https://ninjatrader.com/support/help...and_onexec.htm.​​
              Last edited by NinjaTrader_BrandonH; 05-23-2023, 02:07 PM.
              <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


                #37
                Thank you, Brandon! The third link (sample code) goes to an error page...
                The conversion to a RealtimeOrder, so to speak, concerns the situation when I load a strategy into the chart and there would already be an order active in the system at the current time? If the market price reaches this order, not converting would result in your described error message, right?
                From other platforms I know it so that when "live switching" possibly existing (historical) orders are automatically sent to the market. This would then be done with the code described above to convert the historical (current) order? And all previous historical orders remain untouched? Thank you!​​

                Comment


                  #38
                  Hello signalworks,

                  Thanks for your note.

                  I have edited my previous post to include a link that does not lead to an error page.

                  You could also find the reference sample linked here: https://ninjatrader.com/support/help...and_onexec.htm

                  When starting a strategy on real-time data, the starting behavior will renew any active historical orders and resubmit these orders to your live or simulation account. This process includes updating the historical/backtest generated order ID to the account generated order ID, and any associated OCO IDs.

                  When you have historical order references that you wish to transition and manage in real-time (i.e., you had a working order which was submitted historically and re-submitted in real-time as the strategy is enabled), you would use GetRealtimeOrder(). This method only needs to be called once per order object, and should be done in OnOrderUpdate to handle all scenarios.

                  The help guide links in post # 36 could be viewed which details information about transitioning order references from historical to live.​
                  <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
                  60 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X