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

Resume Historical Orders in Strategy- Unmanaged Approach

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

    Resume Historical Orders in Strategy- Unmanaged Approach

    Hi all,

    I have a strategy based on unmanaged approach to submit manual orders when certain conditions are met.

    I would like to resume my historical orders via the strategy after any connection loss or PC restart.

    I have the following options in State.SetDefaults:

    Calculate = Calculate.OnEachTick;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.ImmediatelySubmit;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = true;
    RealtimeErrorHandling = RealtimeErrorHandling.IgnoreAllErrors;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    IsUnmanaged = true;
    IsAdoptAccountPositionAware = true;
    ConnectionLossHandling = ConnectionLossHandling.KeepRunning;

    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;

    At the moment, I am not able to catch any previous existing order.

    I place an order by using the strategy. Afterwards I disable the strategy and, as soon I re-enable it again, my orders are cancelled immediately.

    I tried the same thing with Playback and IB paper account but I get the same result.

    My strategy is based on UnmanagedTemplate_January2020 code.

    What could be the problem? Do you have any example to share to do that?

    Thanks & Regards


    #2
    Welcome to the forums Peppo!

    I have moved your post to the Strategy Development from the User App Submission forum. Please use this forum when asking technical questions regarding NinjaScript strategies.

    I made some smaller changes to the Unmanaged Template script so bools are used to prevent multiple order submissions if the script is trading on a very volatile symbol or where ticks/price changes come through faster than order updates and executions which we use for Order object handling and submitting targets/stops.

    I have also removed the if (State == State.Historical) return; lines so the strategy can generate orders with historical data. I am able to use ImmediatelySubmit with this attached revision.

    We look forward to assisting.
    Attached Files
    JimNinjaTrader Customer Service

    Comment


      #3
      Jim, I have been testing this new version of your UnmanagedTemplate. I changed the order quantity from 100 to 1 to enable some single-contract futures testing, but otherwise left everything else unchanged. I attached the strategy to an "ES 03-21" intraday chart, enabled the Playback Connection, selected Market Replay, set the Start Date to 12/08/2020 and the End Date to 12/17/2020, and enabled the strategy before pressing the green start-arrow button in the Playback dialog box. The strategy immediately submitted "1 Buy LMT" and "SellShort 1 LMT" orders. The "1 Buy LMT" order was accepted, but a popup error message box said there was no market data to drive the simulation engine which had affected the "SellShort 1 LMT" order. I expected to be able to fix that problem by starting playback before the strategy was enabled, but that didn't work because the existing "1 Buy LMT" order could not be canceled. The only way I could clear that order was to slide the time-slider to its left limit and wait several minutes for the replay system to eventually re-initialize back at its starting time.

      Then, with the "1 Buy LMT" order finally cleared, I once again expected to be able to run the strategy by first starting playback and then enabling the strategy. However, that still didn't work. Even though the chart was updating at the time, the same thing happened that had happened before. The strategy immediately submitted "1 Buy LMT" and "SellShort 1 LMT" orders. The "1 Buy LMT" order was accepted, but the same popup error box said there was no market data to drive the simulation engine which had affected the "SellShort 1 LMT" order (even though the chart continued to update), and like before, the "1 Buy LMT" ordered couldn't be cancelled.

      After a considerable amount of time trying a bunch of things I eventually discovered that the strategy can be made to run by not attaching it to the chart until playback us running. For some unknown reason that works so long as the strategy isn't disabled. If it is disabled, and then re-enabled, the same things happen that happened initially.
      Last edited by caveat_lector; 12-20-2020, 08:28 AM.

      Comment


        #4
        Hello caveat_lector,

        Thank you for your reply.

        I've been able to reproduce this behavior when starting Jim's strategy from the above post and will take a look at that behavior with him. To clarify, have you seen the same issue when running on a real time data connection using the Sim101 account?

        Thanks in advance; I look forward to assisting you further.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          I haven't tried a real-time connection using the Sim101 account.

          Comment


            #6
            I have been testing the "December2020" strategy that Jim posted further above with a real-time data connection and a Sim101 account since "ES 03-21" trading started this Sunday afternoon. The startup issues described above with market replay don't occur with this mode of testing and so far the strategy has otherwise performed as expected, so those issues seem to be associated with market replay and/or use of the NT simulation engine.

            Comment


              #7
              I found the "December2020" strategy doesn't work with the simulation engine, because it doesn't load a tick data stream. Inserting this below the "State.SetDefaults" configuration section:
              Code:
              } else if (State == State.Configure) {
              
                   AddDataSeries(BarsPeriodType.Tick, 1);
              and this at the top of the "OnBarUpdate()" code:
              Code:
              if (BarsInProgress != 0)
                   return;
              provides the simulation engine the data that it needs and fixes the problems.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by JonesJoker, 04-22-2024, 12:23 PM
              8 responses
              41 views
              0 likes
              Last Post JonesJoker  
              Started by timko, Today, 06:45 AM
              0 responses
              3 views
              0 likes
              Last Post timko
              by timko
               
              Started by Waxavi, 04-19-2024, 02:10 AM
              2 responses
              39 views
              0 likes
              Last Post poeds
              by poeds
               
              Started by chbruno, Yesterday, 04:10 PM
              1 response
              44 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by Max238, Today, 01:28 AM
              1 response
              25 views
              0 likes
              Last Post CactusMan  
              Working...
              X