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

TimeSpan

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

    TimeSpan

    Hi,

    I am using TimeSpan and whilst it seems to be working ok when I close and reopen NinjaTrader the indicator is still loaded on the chart but the values are all 00,00,00. Is this expected behaviour?

    Code:
    #region Variables
    TimeSpan sessionStart                = new TimeSpan(22,20,00);     
    TimeSpan sessionEnd                    = new TimeSpan(23,59,59);  
    
    protected override void OnMarketData(MarketDataEventArgs e)
    
    DateTime now = (Bars.MarketData.Connection.Options.Provider == Cbi.Provider.Replay ? Bars.MarketData.Connection.Now : DateTime.Now);
    
    if(now.TimeOfDay >= sessionStart && now.TimeOfDay <= sessionEnd)
    {
    //do something
    }
    
    #region Properties
    [Description("Session Start")]
            [GridCategory("Parameters")]
            public TimeSpan SessionStart
            {
                get { return sessionStart; }
                set { sessionStart = value; }
            }
            
            [Description("Session End")]
            [GridCategory("Parameters")]
            public TimeSpan SessionEnd
            {
                get { return sessionEnd; }
                set { sessionEnd = value; }
            }
    Regards,
    suprsnipes

    #2
    Hi suprsnipes, which value would you expect instead? The OnMarketData() would not be called on any historical bars / period to calculate.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      It works ok it's just when I close NinjaTrade down and then reopen the default values or whatever I have them set to are all reset

      Comment


        #4
        Oh ok, I see what's up here. You would need to custom serialize the TimeSpans to be able to persist (as they are not serializable in C# per dedault). Here's user shared code snippet posted showing how do achieve that:

        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by usazencort, Today, 01:16 AM
        0 responses
        1 view
        0 likes
        Last Post usazencort  
        Started by kaywai, 09-01-2023, 08:44 PM
        5 responses
        603 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by xiinteractive, 04-09-2024, 08:08 AM
        6 responses
        22 views
        0 likes
        Last Post xiinteractive  
        Started by Pattontje, Yesterday, 02:10 PM
        2 responses
        21 views
        0 likes
        Last Post Pattontje  
        Started by flybuzz, 04-21-2024, 04:07 PM
        17 responses
        230 views
        0 likes
        Last Post TradingLoss  
        Working...
        X