Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.

        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by judysamnt7, 03-13-2023, 09:11 AM
        4 responses
        59 views
        0 likes
        Last Post DynamicTest  
        Started by ScottWalsh, Today, 06:52 PM
        4 responses
        36 views
        0 likes
        Last Post ScottWalsh  
        Started by olisav57, Today, 07:39 PM
        0 responses
        7 views
        0 likes
        Last Post olisav57  
        Started by trilliantrader, Today, 03:01 PM
        2 responses
        21 views
        0 likes
        Last Post helpwanted  
        Started by cre8able, Today, 07:24 PM
        0 responses
        10 views
        0 likes
        Last Post cre8able  
        Working...
        X