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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        72 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        39 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        63 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        63 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        53 views
        0 likes
        Last Post CarlTrading  
        Working...
        X