Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Treatment of Time

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

    Treatment of Time

    My strategy is intended to trade only during several windows. I have a function called IsTimeWithin(a, b) which will return true if:

    Code:
    ToTime(Time[0]) >= a && ToTime(Time[0]) <= b)
    So, if we are currently outside the trading windows, the strategy is not allowed to trade.

    My problem now is that if one of the windows is say, 22:00 to 02:00, will I need to rewrite the function to use a different logic if the closing time (b) is lesser than the opening time (a)?

    Next, I have a function that does something after an offset of time after an event occurs. If the event occurs at 23:55 and the offset is 10 minutes, the trigger is set
    by 235500 + 001000 which would give 240500. When dealing with time, will NT recognize that 240500 is equivalent to 000500 or do I have to add additional logic to deal with times > 240000?

    Thanks

    #2
    Hi wuilengh, yes then the filter function would need to changed for this to be evaluated as you would expect, for example :

    if (ToTime(Time[0]) >= 220000 && ToTime(Time[0]) <= 235959
    ||
    ToTime(Time[0]) >= 000000 && ToTime(Time[0]) <= 020000)

    The int 240500 would not be recognized, you could though work with the more advanced C# DateTime objects and add your offset here with the .Add

    Returns a new DateTime that adds the specified number of minutes to the value of this instance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    68 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    38 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    63 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    62 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    53 views
    0 likes
    Last Post CarlTrading  
    Working...
    X