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

Strategy: Days to Load/Start Date

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

    Strategy: Days to Load/Start Date

    Hi -

    Is there a way to set -- within the code -- the "start date" for the days to load?

    For example, let's say I want to set "2/2/2015" in the code. Is there a way to do this?

    Thanks!

    #2
    Hello bigsurftrader,

    Thanks for writing in.

    As the days to load is intended for input by the end user in the GUI, there is not a way to force the days to load in the primary data series of an indicator or a strategy. You may however add a return condition to prevent your indicator or strategy from processing historical data from before that period of time.

    The following example will not process anything in OnBarUpdate() if a) there are not enough bars, and b) The date of the bars are before 02/02/2017. A message will also be displayed when from OnBarUpdate() method before it gets returned.

    Code:
    protected override void OnBarUpdate()
    {
    	if (CurrentBars[0] < 1)
    	  return;
    
    	// Return if the bar date is before 02/02/2017
    	if (Times[0][0] == new DateTime(2017, 2, 2))
    	{
    	  Draw.TextFixed(this, @"ReturnMessage", @"Bars taking place before 02/02/2017", TextPosition.TopRight);
              return;
    	}
    			
    }
    Usage for the Times series and DateTime can be referenced below. I will also link the documentation for Draw.TextFixed():

    Times - http://ninjatrader.com/support/helpG...ries_times.htm
    DateTime - https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
    Draw.TextFixed - http://ninjatrader.com/support/helpG..._textfixed.htm

    Please let me know if you have any further questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      Ah, gotcha. Thank you! This will have to do then. Thank you,

      Big Surf

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by frankthearm, Today, 09:08 AM
      5 responses
      14 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      43 views
      0 likes
      Last Post jeronymite  
      Started by yertle, Today, 08:38 AM
      5 responses
      15 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by adeelshahzad, Today, 03:54 AM
      3 responses
      19 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by bill2023, Yesterday, 08:51 AM
      6 responses
      27 views
      0 likes
      Last Post NinjaTrader_Erick  
      Working...
      X