Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

time slots not saving down properly

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

    time slots not saving down properly

    Hi
    I have created a strategy that runs during multiple time slots within the day (8-925AM; 10-11AM...). The time slots within my code however revert to zero in the strategy menu when I save them down as a template and reopen them ( or if I have a chart saved with a strategy and reopen it the next day). How do I get my time slots to be stored when saved down as templates or when ninjatrader reopens. This is how I have them coded currently in the different sections

    public class and declarations:
    private bool IsWithinTimeSlots(DateTime time)
    {
    TimeSpan currentTime = time.TimeOfDay;
    return (currentTime >= TimeSlot1Start && currentTime <= TimeSlot1End) ||
    (currentTime >= TimeSlot2Start && currentTime <= TimeSlot2End) ||
    (currentTime >= TimeSlot3Start && currentTime <= TimeSlot3End);​

    --
    [NinjaScriptProperty]
    [Display(Name = "Time Slot 1 Start", Order = 19, GroupName = "Time Slots")]
    public TimeSpan TimeSlot1Start { get; set; }

    [NinjaScriptProperty]
    [Display(Name = "Time Slot 1 End", Order = 20, GroupName = "Time Slots")]
    public TimeSpan TimeSlot1End { get; set; }

    [NinjaScriptProperty]
    [Display(Name = "Time Slot 2 Start", Order = 21, GroupName = "Time Slots")]
    public TimeSpan TimeSlot2Start { get; set; }​

    [NinjaScriptProperty]
    [Display(Name = "Time Slot 3 Start", Order = 23, GroupName = "Time Slots")]
    public TimeSpan TimeSlot3Start { get; set; }

    [NinjaScriptProperty]
    [Display(Name = "Time Slot 3 End", Order = 24, GroupName = "Time Slots")]
    public TimeSpan TimeSlot3End { get; set; }​

    --
    State.SetDefaults:
    TimeSlot1Start = new TimeSpan(8, 0, 0);
    TimeSlot1End = new TimeSpan(9, 25, 0);
    TimeSlot2Start = new TimeSpan(9, 40, 0);
    TimeSlot2End = new TimeSpan(10, 0, 0);​

    (State == State.DataLoaded)
    sessionStartTime = new TimeSpan(8, 00, 0);

    OnBarUpdate()
    if (!IsWithinTimeSlots(Time[0]))
    return;​

    #2
    Hello snoinvest,

    To save a timespan you would need to convert that to a string and back to a timespan for saving and loading, this would be similar to how brushes use a second property for saving and loading. I would suggest using a DateTime instead of a TimeSpan

    Code:
    [NinjaScriptProperty]
    [Display(Name = "Time Slot 2 Start", Order = 23, GroupName = "Time Slots")]
    [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
    public DateTime TimeSlot2Start { get; set; }

    Comment


      #3
      Hi,

      I have tried this before. This shows up as a date calendar in the strategy menu instead of time (i.e I can only select dates as opposed to time).
      ​​​ please advise.

      Comment


        #4
        Hello snoinvest,

        I provided a sample that uses the TimeEditor which shows a time, not a date.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        41 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        124 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        64 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        41 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