Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Analyzer and DateTime.Now

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

    Strategy Analyzer and DateTime.Now

    In my strategy, I have code that effectively checks if DateTime.Now is greater than start of the NY Session before placing a trade.

    It works with live data but not in Strategy Analyzer. What can I use for this check that will be compatible with both Strategy Analyzer and Market Replay

    Note that I cannot use the "Trading Hours" feature in Strategy Analyzer because my strategy depends on the sequential ordering of bars, and Strategy Analyzer truncates bars that fall outside whichever "Trading Hours" window is selected.

    Thanks in advance for your assistance.

    #2
    Hello lanredocemo,

    DateTime.Now is the current computer time, not the time of the bar being processed in OnBarUpdate.

    In historical (backtest) only the time of the bar is known which is found with Time[0]. You could add a 1 second series with AddDataSeries if you would like a timestamp of 1 second granularity.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Thanks for the response.

      If I wanted to write a condition for this pseudocode, how do I go about it in such a way that it works with the same behavior in live market, market replay and strategy analyzer:

      Code:
      if (Time[0] > "8:45am CST" && Time[0] < "3pm CST") {
                  Do stuff...
      }

      Comment


        #4
        Hello lanredocemo,

        Are you wanting to trigger actions after the bar has closed or before the bar has closed?

        What is the primary series bar type and interval?

        What time zone is the local computer in?
        Are you wanting to convert

        As a simple example, assuming the OnBarClose behavior is fine, and the chart is a 1 minute, 5 minute chart, or 15 minute chart, and the computer time zone is CST:
        Code:
        if (ToTime(Time[0]) > 84500 && ToTime(Time[0]) < 150000)
        {
        // execute code
        }
        Below are links to the help guide.

        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        88 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        134 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        68 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        119 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        67 views
        0 likes
        Last Post PaulMohn  
        Working...
        X