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 NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        54 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        130 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        72 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X