Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time Filter Template

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

    Time Filter Template

    I found a SampleTimeFilter template in the Ninjatrader help guide which I've attached for reference. I would like to use the 24hr format that it's currently in, but would like to be able to modify the time when I select the strategy. Below is a code of what I've modified so far. Would this be the correct way?


    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    StartTradingTime = 083000;
    EndTradingTime = 150000;
    }
    }

    protected override void OnBarUpdate()
    {
    if (ToTime(Time[0]) >= StartTradingTime && ToTime(Time[0]) < EndTradingTime)
    {
    Logic
    }
    }

    #region Properties
    [NinjaScriptProperty]
    [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")]
    [Display(Name="StartTradingTime", Order=1, GroupName="TradingTime")]
    public DateTime StartTradingTime
    { get; set; }

    [NinjaScriptProperty]
    [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")]
    [Display(Name="EndTradingTime", Order=2, GroupName="TradingTime")]
    public DateTime EndTradingTime
    { get; set; }


    Attached Files

    #2
    Hello AgriTrdr,

    If you wanted to maintain the same format of using 083000 then the public properties should be integers.

    Code:
    [NinjaScriptProperty]
    [Display(Name="StartTradingTime", Order=1, GroupName="TradingTime")]
    public int StartTradingTime
    { get; set; }
    
    [NinjaScriptProperty]
    [Display(Name="EndTradingTime", Order=1, GroupName="TradingTime")]
    public int EndTradingTime
    { get; set; }

    Comment


      #3
      Thanks for your reply. Does there need to be anything for the Range?

      #region Properties
      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="StartTradingTime", Order=1, GroupName="TradingTime")]
      public int StartTradingTime
      { get; set; }

      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="EndTradingTime", Order=2, GroupName="TradingTime")]
      public int EndTradingTime
      { get; set; }

      Comment


        #4
        Hello AgriTrdr,

        No you would not need the range attribute for this.

        Comment


          #5
          If there's a secondary data series in the strategy, would the below be the correct way for the if condition or do I leave it as I had initially?

          if (ToTime(Times[0][0]) >= StartTradingTime && ToTime(Times[0][0]) < EndTradingTime)

          Comment


            #6
            Hello AgriTrdr,

            This code is using Times[0][0] meaning the primary series times. If you wanted to check the time for both series that depends if this code is within a BarsInProgress condition.

            If there are no BarsInProgress conditions you can use Time[0] to reference whichever series has called OnBarUpdate.

            Code:
            protected override void OnBarUpdate()
            {
            
            
            if (ToTime(Time[0]) >= StartTradingTime && ToTime(Time[0]) < EndTradingTime)

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            50 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            127 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            69 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            42 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X