Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy time filter, from one date to another, for every year

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

    Strategy time filter, from one date to another, for every year

    Hi together,

    for developing my strategy further, now starting with the time filters, first of all, the days where no trades will be triggered.
    That is for example the period between around christmas and new years eve, plus X, Dec.15th to Jan. 30th

    to be set in the OnBarUpdate there is the function as follows, but how to take only the months and days? I have seen that there can be used C# time structures, but don´t know enough about it to program it.

    protected override void OnBarUpdate()
    {
    // Compare the date of the current bar to Dec.15th to Jan.30th, but for every year, not only the actual year

    if (ToDay(Time[0]) < "year"1215) && (ToDay(Time[0] > "year"0130)
    {
    // Do something
    }
    }​

    #2
    Hello Triple_M,

    OnBarUpdate is not called for holiday bars so keep that in mind. You can detect in your script if a day is a holiday, for example a partial holiday. For a full holiday you logic would just not be called because there is no market data on that date.

    https://forum.ninjatrader.com/forum/...55#post1169455

    Comment


      #3
      Hello Jesse,
      i dont want to detect holiday days, I want to program a filter that within a period of days, from one day to another, regardless if there are holiday days or not, there is a phase where no trades are triggered. Like from mid of december to mid of january. For backtest purpose, without a year just the date month/day without the year, that i can run a backtest for a strategy for the last ...whatever 3 or 5 years, to check if on special phases no trades are triggered, the result is better.

      Comment


        #4
        Hello Triple_M,

        As mentioned your logic wont be called on holidays so you don't really need to consider those days. You would just need to make your logic to detect when no trades are triggered. The script just skips holidays when backtesting.

        Comment


          #5
          ...."how to" programm such a script, thats the question

          Comment


            #6
            Hello Triple_M,

            If you wanted to do something for that period of time you can use a date filter, you can create that type of condition by using the Time variable and comparing that against DateTimes you have created with the dates in question. You can see examples of working with datetime objects here or also by using google and searching for C# datetime.


            Comment


              #7
              Thank you Jesse, thats so far what I am looking for. I will try to program it into my system.

              Is there any other possibility, outside of the script...... to do a backtest and to extract some time periods???

              My intention is, that in many systems, the period for example before or after christmas, or before and after special holiday days, before and after new years eve......a system is not working properly, because the markets are not reflecting the same behavior then normal. That means, trades are triggered and cause losses, this is then not a really precice analysis.
              In real life, the system is just shut of during these time phases, but to do a backtest for many years it is very interesting to extract those dates.

              Comment


                #8
                Hello Triple_M,

                The best option would be to program the strategy to not trade for those dates. There is not any option in the platform to exclude date ranges of data.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                52 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                130 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                70 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                43 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                47 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X