Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question on handling strategy initialization with older entries

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

    Question on handling strategy initialization with older entries

    I've got a strategy that looks back a bit in the past. So my question is when enabling a strategy is there a best practice to follow to "start fresh", let me explain what happens.

    Today is good example, so Friday my strategy went short a couple of times on /MES prior to close based on the rules. When we opened on Sunday, we gapped up and then camped out for quite some time before pulling back down.

    It's obviously "aware" of previous entries even though nothing is showing in the P&L.

    Ideal state is it just starts clean on a new version or a fresh install since it will go back and "make trades" no matter what.

    Good visual of what happened here.
    Click image for larger version  Name:	2020-12-14_9-12-04.jpg Views:	0 Size:	360.2 KB ID:	1132339

    As you can see, it went short 3 times and then added another one. It's setup to currently wait until a specified target profit before exiting the position. So it will hold the short until that point in the future.

    Thanks!
    Last edited by DogEars; 12-14-2020, 08:35 PM.

    #2
    I discovered that I can do

    HTML Code:
    if (State == State.Historical)
    return;
    I'm not sure this is best practice though. The documentation is a little thin here, are there any ramifications for doing this?

    Comment


      #3
      Hello DogEars,

      Thank you for your post.

      Skipping historical data will allow you to start "fresh" and flat each time the strategy is enabled. If you do not want the strategy to calculate a position from processing historical data you could add if (State == State.Historical) return; to the top of your strategy logic so historical processing is skipped. The strategy will then always start from a flat position because it has not calculated any orders.

      Please note that by skipping historical data you will lose the ability to resume positions with the start behavior Immediately Submit.

      Immediately Submit automatically submits working orders from when the strategy processed historical data and assumes the strategy position and account position are where you want it when you enable the strategy. This is typically used to have a strategy to resume a position after disabling/enabling. If the strategy already had live orders running, the orders will resume with the new enablement of the strategy if they match the historically calculated orders. If the orders calculated from historical data do not match the live working orders, the live working orders will be canceled and replaced by those calculated from historical data.

      Please see the help guide documentation below for more information about Strategy vs Account position and Start Behaviors.
      Strategy vs. Account Position — https://ninjatrader.com/support/help..._account_p.htm
      Start Behaviors — https://ninjatrader.com/support/help..._positions.htm

      Let us know if we may assist further.
      <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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      21 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      30 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      50 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Working...
      X