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 terofs, Yesterday, 04:18 PM
      1 response
      21 views
      0 likes
      Last Post terofs
      by terofs
       
      Started by CommonWhale, Today, 09:55 AM
      1 response
      3 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by Gerik, Today, 09:40 AM
      2 responses
      7 views
      0 likes
      Last Post Gerik
      by Gerik
       
      Started by RookieTrader, Today, 09:37 AM
      2 responses
      13 views
      0 likes
      Last Post RookieTrader  
      Started by alifarahani, Today, 09:40 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X