Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy doesn't run when time condition added

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

    Strategy doesn't run when time condition added

    I used strategy builder to use a start and end time to color chart window background.

    But this is not happening after applying the strategy to chart and enabling it. Loaded a total of 10 days and yet no background colors.

    Kindly review and let me know what I'm missing.

    Also, same thing happens when I add the time check to other strategies - they will not print on chart if the time conditions are added.

    // Set 1
    if ((Times[0][0].TimeOfDay >= TradingStartTime.TimeOfDay)
    && (Times[0][0].TimeOfDay < TradingStopTime.TimeOfDay))
    {
    BackBrushAll = Brushes.CornflowerBlue;
    }
    Attached Files
    Last edited by NTbrass; 04-28-2020, 10:50 PM.

    #2
    Most likely TradingStartTime is greater than TradingStopTime therefore the condition will never be true.
    Because the time of day rolls over to 0 at midnight the comparison is more complicated for this case.
    Not a general solution but off the top off my head if stop time is greater than start time, try(untested)
    Code:
    if (Times[0][0].TimeOfDay <= TradingStopTime.TimeOfDay
    || (Times[0][0].TimeOfDay > TradingStartTime.TimeOfDay)
    Edit:
    updated logic
    Last edited by MojoJojo; 04-29-2020, 05:10 AM.

    Comment


      #3
      Hi NTbrass,
      If quickly tested this myself. If TradingStartTime is SMALLER than TradingStopTime, the chart is coloured during the TimeWindow with just your two conditions.
      If colouring shall span over night, your logic will have to be slightly more advanced. MojoJojo kindly offered a suggestion.
      NT-Roland

      Comment


        #4
        Hello NTbrass,

        Thanks for your post and welcome to the Ninjatrader forums!

        The time conditions you are using will not work as is because as the other forum members have advised the time condition will not be true.

        What you would have to do is to create two "time filters" where the first one checks to see if the bar time is between 11:41 PM and 11:59 PM, the second one would have to be from 12:00 AM to 7:43. In the strategy builder you would create two seperate condition "groups" to create the time filters and you would have to change the conditions window from "If all" to "If any". In the condition groups you would need to set those to "If all". This would mean that from the period of 11:59 PM to 12:00 AM the set would not be true.
        To further assist I've created a short video on time filters: https://paul-ninjatrader.tinytake.co...N18xMzMyNDA1Mg Also, please see the section, "How to create time filters" on this page: https://ninjatrader.com/support/help...on_builder.htm

        Alternatively, you may want to just have one time filter that starts at Midnight and goes to 7:43 as this will avoid the issue of time conflict with Midnight.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        110 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        59 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        37 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        41 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        78 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X