Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Dynamically determining BarsRequired on initialization?

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

    Dynamically determining BarsRequired on initialization?

    Is this possible? In other words, can I do a calculation in Initialize() whereby I look at my known indicator/strategy parameters, calculate the max value of those, and set that as "BarsRequired"?

    #2
    Hello,

    You can do this in OnStartUp(). Here is a loose example:

    Code:
    			protected override void OnStartUp()
    			{
    				
    				if(Instrument.FullName == "ES 12-12")
    				{
    					BarsRequired = 20;
    				}
    				
    				if(Instrument.FullName == "NQ 12-12")
    				{
    					BarsRequired = 100;
    				}
    			}
    MatthewNinjaTrader Product Management

    Comment


      #3
      Interesting. So my next question is, which comes first - Initialize() or OnStartUp()?

      Comment


        #4
        Initialize() will always be called first



        Definition
        You can override the OnStartUp() method to initialize any variables or resources you wish to use in the custom indicator or strategy. This method is called only once immediately prior to the start of your script processing its logic in OnBarUpdate(), but after the Initialize() method.
        MatthewNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        80 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        46 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        29 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        32 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        66 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X