Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy start-up initialization

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

    Strategy start-up initialization

    Where is there information on the startup of a strategy in terms of how much data is used and how it is used prior to the first OnBarUpdate? I need this in particular for the ATR. The ATR is the EMA of True Ranges. But at first it is the SMA over the initial period, then it continues as the EMA from there. I am effectively having to reverse engineer the way NT handles the startup of the ATR, even though the ATR formula is public.

    #2
    Hello,

    There is a page in our Help Guide on the BarsRequired for a strategy:



    The strategy will wait until BarsRequired have been met (20 by default, user definable) are added before it will call OnBarUpdate.

    The is NOT the same as the BarsRequired for indicator, which will process data starting on Bar 0. It just simply waits until the BarsRequired have been met before it plots an indicator:



    You will often find your indicator is in an unstable period between the bar 0 and the BarsRequired in an indicator. The value of the indicator will be available, but will not actually plot it until the bars required have been met to ensure we're working with stable values before it plots.
    MatthewNinjaTrader Product Management

    Comment


      #3
      I set BarsRequired = 100, and I still get the first CurrentBar = 20. It looks like it is ignoring my setting.

      Comment


        #4
        Hi,

        If you're referring to the strategy, note that there is both the option to set the BarsRequired from the UI when starting the strategy, and from the Initialize method.

        The UI settings will override the Initialize.

        The following is taken in the strategy base and works to my expectations

        Code:
        		protected override void Initialize()
        		{
        			BarsRequired = 100;
        		}
        
        		protected override void OnBarUpdate()
        		{
        			
        			Print("BarsRequired: " + BarsRequired);
        			Print("CurrentBar: " + CurrentBar);	
        		
        		}
        //first output
        CurrentBar: 100
        BarsRequired: 100
        If you're getting a different CurrentBar and BarsRequired, there there would be something else setting the BarsRequired than what you Initalized.
        MatthewNinjaTrader Product Management

        Comment


          #5
          It was the one in the UI that was set to 20. I changed it to 100 and it worked!

          Thanks.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by zstheorist, Today, 07:52 PM
          0 responses
          7 views
          0 likes
          Last Post zstheorist  
          Started by pmachiraju, 11-01-2023, 04:46 AM
          8 responses
          150 views
          0 likes
          Last Post rehmans
          by rehmans
           
          Started by mattbsea, Today, 05:44 PM
          0 responses
          6 views
          0 likes
          Last Post mattbsea  
          Started by RideMe, 04-07-2024, 04:54 PM
          6 responses
          33 views
          0 likes
          Last Post RideMe
          by RideMe
           
          Started by tkaboris, Today, 05:13 PM
          0 responses
          6 views
          0 likes
          Last Post tkaboris  
          Working...
          X