Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trade placed fully outside the current bar - Time issue

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

    Trade placed fully outside the current bar - Time issue

    Hi,
    I have an interesting behaviour of ninjatrader. It is placing in the backtest and optimization trades outside the chart - I think shifted by a few hours.
    I am not sure if the test is invalid or just the chart display is wrong.

    My setup is: my local time zone is currently UTC +1 (Berlin) my Timezone set in Ninjatrader is UTC-5 Eastern Time (New York).
    Same behaviour is when I shift the local time zone to UTC-5.

    Does anybody know if my test is valid anyway?

    Below you can see a plausible case based on my timezone, and an unplausible case based on the NY time zone.
    The EA restricts by time as follows:

    DateTime start1 = Time[0].Date;
    start1 = start1.AddHours((int)InpHourFrom).AddMinutes((InpH ourFrom - (int)InpHourFrom) * 60);
    DateTime end1 = Time[0].Date;
    end1 = end1.AddHours((int)InpHourTo).AddMinutes((InpHourT o - (int)InpHourTo) * 60);

    // Prüfe, ob der aktuelle Balken nach die Uhrzeiteinschränkung einhält
    if (ToTime(Time[0]) < ToTime(start1)) {
    return; // Verlasse die Methode, wenn es vor inpHourFrom Uhr ist
    }

    if (ToTime(Time[0]) >ToTime(end1))
    {
    if (Position.Quantity != 0)
    {
    ExitLong();
    ExitShort();
    }
    return; // Verlasse die Methode, wenn es nach inpHourTo Uhr ist
    }​

    Plausible case:
    Time Zone in Ninja set to my timezone
    Click image for larger version

Name:	image.png
Views:	113
Size:	13.8 KB
ID:	1341648

    ​Best trade
    Click image for larger version

Name:	image.png
Views:	79
Size:	8.7 KB
ID:	1341649

    Unplausible case Time Zone set to NY time (Ninjatrader was restarted to take effect)
    Result
    Click image for larger version

Name:	image.png
Views:	81
Size:	13.6 KB
ID:	1341653

    Best trade - position completely outside the bars - it is just exemplary, most of the positions are outside the bar


    Click image for larger version

Name:	image.png
Views:	79
Size:	18.5 KB
ID:	1341652

    My questions are:
    do I have to think about the wrong display as false backtest result or is it just a display issue?
    Can I rely that Time[0] is in the timezone I set in the Ninjatrader settings?

    Thanks and best regards
    ​​

    Attached Files

    #2
    Hello moneymaster,

    Thank you for your post.

    Does this behavior still occur if you implement 1-tick intrabar granularity, and (if you are using Calculate.OnEachTick or .OnPriceChange) enable TickReplay?

    Below is a sample script that demonstrates implementing 1-tick intrabar granularity.



    Tick Replay - https://ninjatrader.com/support/help...ick_replay.htm

    Comment


      #3
      Hi Gaby, my historical fill process is done with a 1 second granularity. The shifts are so massive, they are more than 1h away from the price.
      How does Ninjatrader consider the time zone of the PC and the time zone of the Ninatrader and the data during the backtest vs live? Are there any special differences or is it just a bug? Probably you could play with it, setting ninjatrader to a different timezone that You are in and then doing any optimization, then looking at the chart of the executed trades.
      Thanks and best regards

      Comment


        #4
        Hello moneymaster,

        You indicated that this occurs regardless of whether your local time zone matches the time-zone configured in NT, correct? If that is the case then it is unlikely this is due to that. However if you are using IB, this could cause issues.

        Are you using a bar type that is based on movement that does not show the full range of the market?

        Additionally, try resyncing your PC clock, and then deleting and redownloading all historical data.

        PC Clock sync instructions can be found here: https://forum.ninjatrader.com/forum/ninjatrader-7/platform-technical-support/89156-getting-fills-outside-bid-ask?p=749815#post749815

        Delete historical data: https://ninjatrader.com/support/help...HistoricalData

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        23 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        120 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        63 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
        45 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X