Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Comparing time no work properly

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

    Comparing time no work properly

    hi all

    I am here with a so strange case. When I use iterator to define a stopTime to use this as time to stop enter long and compare this to Time[0] by ToTime work if I put a print as order to execute but no execute enterlong instead of. Any help will be welcommed due to I have test many diferent ways and when I do not put this in my logic the strategy work fine (but create long entries after stopTime).




    protected override void OnBarUpdate()
    {


    if (Bars.IsFirstBarOfSession)
    {


    // use the current bar time to calculate the next session
    sessionIterator.GetNextSession(Time[0], true);
    // store the desired session information
    tradingDay = sessionIterator.ActualTradingDayExchange;
    beginTime = sessionIterator.ActualSessionBegin;
    stopTime = sessionIterator.ActualSessionBegin.AddHours(3);
    endTime = sessionIterator.ActualSessionEnd.AddHours(-0.2);



    }

    if (ToTime(Time[0]) < ToTime(stopTime))
    {

    EnterLong();
    }​




    Regards

    #2
    Hello J2512,

    Use Print() to understand behavior.


    Print ToTime(Time[0]), and print ToTime(stopTime).

    Include the output text file with your next post.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi ChelseaB

      thank you for your response, but I already solved. the problem was that I was using more conditions in the if statement and another comparision about date and time conflicts between them, finally I remove on of them and work properly.

      if ( Low[0] <= Level
      && Position.MarketPosition == MarketPosition.Flat
      && ToTime(Time[0]) < ToTime(stopTime)
      && ToTime(Time[0]) > ToTime(beginTime))

      On hte other hand I would like ask to you about how can i acces to mini data box information by code, I have been looking for in ninja forum but no find anything relate to this. And let me explain what is my target because maybe there is simple solution of that.

      I want to export OHLC and volume information 5 minutes after US Equities RTH session finish but I cannot get the data from last bar as ninjatrader no consider as bar ended. I tried to get the information bar by bar in 1 minute but always I will lost close price and a part of volume. Then I have found that mini data box provide that information then that information is stored by ninjatrader, how can i access to this? Maybe by Bars.GetClose, Bars.GetHigh, Bars.GetLow, Bars.GetOpen, Bars.GetVolume...

      Anyhelp wil be welcommed.

      Regards.



      Comment


        #4
        Hello J2512,

        The databox is not directly accessible, however you can retrieve any information in the databox with that object directly.

        It is possible to get information about the bar under the mouse pointer the same way the databox does. Below is a link to an example.


        To get information about a bar before it closes in OnBarUpdate() use the Calculate.OnPriceChange or .OnEachTick setting.


        If you want to trigger an action when OnBarUpdate() is not updating, such as after the close of the session, use a Timer. Below is a link to an example.


        Yes, Bars.GetClose() would be correct for fetching bar information, particularly from a non-data-driven method.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        79 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        45 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        29 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        32 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        66 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X