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

Time Filter is not working if going into the next day

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

    #16
    tkaboris You could try something like this:
    Code:
        DateTime startDay = DateTime.Now.Date;                  // Choose any date you want to get that Day at 00:00
        DateTime startDay530pm = startDay.AddHours(17.5);       // Set the time of Day. Use .Addxxx where xxx might be hours, mins, etc
        DateTime nextDay7am = startDay.AddDays(1).AddHours(7);  // Adds 1 full day (24 hours) from 00:00 and any additional time next day
        DateTime whenever = DateTime.Now;                       // Choose any DateTime you want to check
    
        bool IsInsideTimes = whenever >= startDay530pm && whenever < nextDay7am;
        bool IsOutsideTimes = whenever < startDay530pm || whenever >= nextDay7am;
    Hope that helps.

    Thanks.
    Multi-Dimensional Managed Trading
    jeronymite
    NinjaTrader Ecosystem Vendor - Mizpah Software

    Comment


      #17
      @NinjaTrader_ChrisL
      Can you please update multiday time filter in example file so it indeed can work on multiday without hardcoded values?

      TestTimeFilter.zip (4.1 KB, 6 views)​







      Comment


        #18
        Well the workaround was to create two time filters. I guess it works for now thank you

        Comment


          #19
          Hi, I attached the modified example below to use inputs.
          Attached Files
          Chris L.NinjaTrader Customer Service

          Comment


            #20
            I have these settings for both times


            But it doenst open trades when first time section selected in the same AM. Did i put that if statement correctly?

            if ((Time[1].TimeOfDay >= Start1.TimeOfDay) && (Time[1].TimeOfDay <= End1.TimeOfDay)
            || (Time[1].TimeOfDay >= Start2.TimeOfDay) && (Time[1].TimeOfDay <= End2.TimeOfDay)​

            Comment


              #21
              Hi Boris, It looks like there is just a missing parentheses:

              if ((Time[1].TimeOfDay >= Start1.TimeOfDay) && (Time[1].TimeOfDay <= End1.TimeOfDay)
              || (Time[1].TimeOfDay >= Start2.TimeOfDay) && (Time[1].TimeOfDay <= End2.TimeOfDay)​​)

              Instead of placing trades, just try testing with the Draw.Dot command as I did in my original example, this will confirm that your time filter is working.

              Kind regards,
              -ChrisL
              Chris L.NinjaTrader Customer Service

              Comment


                #22
                HI please take a look at thi screenhot
                I made time filter from 1am to 1pm but it plots blue markings after 1pm..
                testimer strrategy compiles but its not working
                Last edited by tkaboris; 02-20-2023, 05:10 PM.

                Comment


                  #23
                  Hello, thanks for the follow up. This is exactly what the condition is evaluating. The time is greater than 1AM and less than 1PM.
                  if (
                  ((Times[0][0].TimeOfDay > Time0.TimeOfDay)
                  || (Times[0][0].TimeOfDay < Time1.TimeOfDay)))​

                  You need to put 1PM first for time0, then 1AM second for Time1 to trigger in between 1PM and 1AM.

                  Kind regards,
                  -ChrisL​
                  Chris L.NinjaTrader Customer Service

                  Comment


                    #24
                    Thank you, But how then can i select a time for morning session only?
                    start 9am finish 2pm. If my first time is bigger then second one. What would be the approach then?

                    Comment


                      #25
                      Hello, thanks for the follow up. That would require the condition to be different. The example I have is designed to span between days. To check if the time is between two time points int the same day, change the condition group from If Any to If All, then set the times from 9AM-2PM.;
                      Chris L.NinjaTrader Customer Service

                      Comment


                        #26
                        Hello, I guess my timefileter from a while ago is not working as suppose to. I tried to copy from whats was in example but its opening trades past time filter and before that too. Can you please help?
                        In my onbarupdate I have

                        Code:
                         if (Bars.IsFirstBarOfSession)
                                    {
                                        currentPnl = 0;
                                    }
                        
                                    if (CurrentBar < Math.Max(BarsRequiredToTrade, BarsBefore))
                                    {
                                        return;
                                    }
                        
                        
                                    if (
                                        // multiday
                                        (((Times[0][0].TimeOfDay > MultiDayTime1.TimeOfDay)
                                        || (Times[0][0].TimeOfDay < MultiDayTime2.TimeOfDay))
                                        && (MultiDay == true)
                                        && (SameDay == false))
                                        ||
                                        // SameDay
                                        (((Times[0][0].TimeOfDay > SameDayTime1.TimeOfDay)
                                        && (Times[0][0].TimeOfDay < SameDayTime2.TimeOfDay))
                                        && (MultiDay == false)
                                        && (SameDay == true))
                                        && Position.MarketPosition == MarketPosition.Flat && CurrentBar > BarsRequiredToTrade
                                        && (dailyPnL > -DailyLossLimit) //Loss remains 'above' limit
                                        && (dailyPnL < DailyProfitLimit)) //Profit remains 'below' limit    ​
                        and in my properties i have
                        Code:
                        #region 09. Time Management    
                                [NinjaScriptProperty]
                                [Display(Name = "SameDay", Order = 0, GroupName = "09. Time Management")]
                                public bool SameDay
                                { get; set; }
                        
                                [NinjaScriptProperty]
                                [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
                                [Display(Name = "Begin Time", Order = 1, GroupName = "09. Time Management")]
                                public DateTime SameDayTime1
                                { get; set; }
                        
                                [NinjaScriptProperty]
                                [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
                                [Display(Name = "End Time", Order = 2, GroupName = "09. Time Management")]
                                public DateTime SameDayTime2
                                { get; set; }
                        
                        
                                [NinjaScriptProperty]
                                [Display(Name = "MultiDay", Order = 3, GroupName = "09. Time Management")]
                                public bool MultiDay
                                { get; set; }
                        
                                [NinjaScriptProperty]
                                [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
                                [Display(Name = "Begin Time", Order = 4, GroupName = "09. Time Management")]
                                public DateTime MultiDayTime1
                                { get; set; }
                        
                                [NinjaScriptProperty]
                                [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
                                [Display(Name = "End Time", Order = 5, GroupName = "09. Time Management")]
                                public DateTime MultiDayTime2
                                { get; set; }
                                #endregion​

                        Comment


                          #27
                          Hi Boris, Unfortunately, I will not be able to further debug any custom code. Please use the examples we have provided and also use the Print() method to explain the output you are getting from the script. Using print is the best way to see the data that your script is processing and will help explain unexpected results.
                          Chris L.NinjaTrader Customer Service

                          Comment


                            #28
                            I am sorry to ask once again

                            ((Times[0][0].TimeOfDay > Time0.TimeOfDay)
                            || (Times[0][0].TimeOfDay < Time1.TimeOfDay)))​

                            You need to put 1PM first for time0, then 1AM second for Time1 to trigger in between 1PM and 1AM.​

                            If i want to modify in output Time0 to place lesser time like AM and Time1 like PM. How can I modify above code?

                            Comment


                              #29
                              Hi Boris, this would require two condition groups to span two days and cover the morning to the PM the next day. I attached my test script made in the builder.

                              Attached Files
                              Chris L.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by GussJ, 03-04-2020, 03:11 PM
                              11 responses
                              3,227 views
                              0 likes
                              Last Post xiinteractive  
                              Started by andrewtrades, Today, 04:57 PM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by chbruno, Today, 04:10 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              440 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post FAQtrader  
                              Working...
                              X