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

Start Date Using Chart Strategy

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

    Start Date Using Chart Strategy

    Hi if I am running a strategy from a chart and select # of days to load. As the strategy walks forward in time will it also move the start date/time of the strategy? For futures will it move the start date up 1 day at the close or open of the next day? If so what is the best way to prevent this behavior? I would like to have a firm start date/time for my VMA indicator since it builds recursively and therefore depends on all previous bars not just the last X number of bars.

    Thanks,
    John

    #2
    Hello John,

    Thanks for opening this thread.

    The number of days to load will place the start date a certain number of days from the current date. It will not limit you to having a view of a certain number of days, it simply determines where the data series should begin. You can pre-load a large amount of historical data that can be used for calculations in your strategy.

    If you specifically rely on a period of real time data for your indicator, I would advise to make sure you have given enough time for it to calculate the data it needs before you begin making trades. For example, you can create a condition using ToTime() or ToDay() to control a bool that would then control your entries and exits.

    The following sample code will allow control any logic by your strategy until the current time is within 7:45AM and 1:45PM and 3 days of data has iterated through the strategy.

    Code:
    private int DayActivated;
    protected override void OnBarUpdate()
    {
    	if (CurrentBar == 0)
    		DayActivated = ToDay(Time[0]);
    	
    	if ((ToTime(Time[0]) >= 74500 && ToTime(Time[0]) <= 134500)
    		&& (ToDay(Time[0]) >= DayActivated + 3))
    	{
    	    // Strategy logic goes here
    	}
    }
    You may reference the documentation on Time objects and ToTime() and ToDay()

    ToTime() - https://ninjatrader.com/support/help...-us/totime.htm

    ToDay() - https://ninjatrader.com/support/help...n-us/today.htm

    Time - https://ninjatrader.com/support/help...eries_time.htm

    If you have any further questions, please don't hesitate to ask.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick reply. The logic to force the strategy to wait a certain amount of days makes sense and is worthwhile implementing, but right now I am more concerned with how the strategy adapts as it runs forward.

      For example say I load 3 days of data on the chart and add my strategy to that data series. Today for CME FX futures it would pull data from 4/4,4/3 and 4/2 (after 17:00 CT). Now the strategy runs for a 2 days until 4/6 will the data series now begin at 4/3 instead of 4/2 17:00CT? Will any indicators in the strategy have adjusted their calculations to begin at this later date?

      This is something I can obviously test live but would prefer not to have to wait a day or two to observe the behavior.

      Ultimately, is there any way to force a strategy to begin calculating at a specific date rather than a number of days back from the current date?

      John

      Comment


        #4
        Hello jlkramer16,

        Thanks for the reply.

        Now the strategy runs for a 2 days until 4/6 will the data series now begin at 4/3 instead of 4/2 17:00CT?
        The data series will still begin at the same start date.

        Will any indicators in the strategy have adjusted their calculations to begin at this later date?
        The start date does not get changed, there would not be any need to adjust indicators to specify a different period as time passes.

        Ultimately, is there any way to force a strategy to begin calculating at a specific date rather than a number of days back from the current date?
        Yes, you can. Within the data series window, you can select "Custom Range" from the "Load data based on" pull down menu to specify a start date and an end date. The end date will continue to stay current with the data running through it.

        Please let me know if I may be of further assistance.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,603 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        8 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        4 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        12 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X