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

Adding Time Constraint to Strategy

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

    Adding Time Constraint to Strategy

    Hello Guys,
    I downloaded a strategy (TrendStrengthA Strategy) from the file sharing section and I need some help with it. I have been trying to add a time constraint to it to, so I only trade certain times of the market say 8am to 2pm, but it keeps giving me erroneous results. I have tried using an if statement with Totimer,using an example i found on the ninja trader help site, but that does not help. Can someone point me in the right direction with how to add this constraint to the strategy?
    thanks in advance

    #2
    Welcome to our forums - have you already checked into our sample on adding time filters to strategies?

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks, I will take a look and let you know if I have any questions.

      Comment


        #4
        Hi everyone. Please advise. Am I correct that if I add this line to the strategy it will allow trades only from 1:00AM till 11:00PM (1:00 - 23:00)?

        Code:
        if ((ToTime(Time[0]) >= 10000 && ToTime(Time[0]) < 230000)
        Or this line in the examples means something else? Cause when I enter it under "protected override void OnBarUpdate()" strategy still enters market after 23:00. What do I miss?
        Thank you in advance.

        Comment


          #5
          Hello Assalt,

          If that is the sample from the ToTime help guide page then yes the intention is to create a time window based on the two times you enter. That would be for making a condition that limits the time between those two times. You would need to surround the code you wanted to be limited with curly braces:

          Code:
          if(your condition)
          {
               //code that should be limited here
          }
          JesseNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Jesse View Post
            Hello Assalt,

            If that is the sample from the ToTime help guide page then yes the intention is to create a time window based on the two times you enter. That would be for making a condition that limits the time between those two times. You would need to surround the code you wanted to be limited with curly braces:

            Code:
            if(your condition)
            {
            //code that should be limited here
            }
            Thank you so much for the perfect advice. When I surrounded the code of conditions for entering the market everything started to work in the designated limits of time. Thank you again.
            Last edited by Assalt; 01-08-2024, 03:21 PM.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by fx.practic, 10-15-2013, 12:53 AM
            5 responses
            5,406 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Started by Shai Samuel, 07-02-2022, 02:46 PM
            4 responses
            98 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Started by DJ888, Yesterday, 10:57 PM
            0 responses
            8 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by MacDad, 02-25-2024, 11:48 PM
            7 responses
            160 views
            0 likes
            Last Post loganjarosz123  
            Started by Belfortbucks, Yesterday, 09:29 PM
            0 responses
            9 views
            0 likes
            Last Post Belfortbucks  
            Working...
            X