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

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.
      Brandon H.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by cmtjoancolmenero, Yesterday, 03:58 PM
      3 responses
      23 views
      0 likes
      Last Post cmtjoancolmenero  
      Started by Brevo, Today, 01:45 AM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by rjbtrade1, 11-30-2023, 04:38 PM
      2 responses
      72 views
      0 likes
      Last Post DavidHP
      by DavidHP
       
      Started by suroot, 04-10-2017, 02:18 AM
      5 responses
      3,021 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by Stanfillirenfro, Today, 07:23 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X