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 trilliantrader, 04-18-2024, 08:16 AM
        5 responses
        22 views
        0 likes
        Last Post trilliantrader  
        Started by Davidtowleii, Today, 12:15 AM
        0 responses
        3 views
        0 likes
        Last Post Davidtowleii  
        Started by guillembm, Yesterday, 11:25 AM
        2 responses
        9 views
        0 likes
        Last Post guillembm  
        Started by junkone, 04-21-2024, 07:17 AM
        9 responses
        70 views
        0 likes
        Last Post jeronymite  
        Started by mgco4you, Yesterday, 09:46 PM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X