Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Wizard Time Settings – Time Value Settings

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

    Strategy Wizard Time Settings – Time Value Settings

    I am trying to figure out how to add a condition to a strategy through the strategy wizard based on time. What I am trying to do is to only allow a strategy to run and back test only between the hours of 8Am and 5PM.


    In the strategy wizard there is a “Time” tab and the choices on the drop down are “Date value”, “Time series” and “Time value”. I choose “Time value” and cannot figure out how I set it up a condition equal to this: time > 800 and time < 1700;


    Thanks,


    Dave

    P.S. I did search for this answer but could not find anything related.

    #2
    Anybody have a idea?

    Comment


      #3
      Hello www. Shift-Theory.Com,

      Thanks for your post.

      Attached are screenshots that demonstrate this.

      This is also covered in the Automated Strategy Development NinjaTrader YouTube training video.
      https://www.youtube.com/watch?v=Maaq...56536A44DD7105
      Attached Files
      Last edited by NinjaTrader_ChelseaB; 08-21-2014, 07:24 AM.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        That is EXACTLY what I did not understand.

        Awesome and easy to understand screen shots too!

        Thanks,

        Dave

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello www. Shift-Theory.Com,

          Thanks for your post.

          Attached are screenshots that demonstrate this.

          This is also covered in the Automated Strategy Development NinjaTrader YouTube training video.
          https://www.youtube.com/watch?v=Maaq...56536A44DD7105
          I am confused by this solution. When I put it in exactly as detailed here it seems to work fine. But I want to trade the off hours (avoid volatility) so I put in greater than 6:00PM and less than 8:30AM. No trades take place either in back testing or in market replay. I tried switching the times and placing the less than 8:30 first but that didn't help. Can you please explain?

          Comment


            #6
            Hello Dolfan,

            If you add a Misc -> 'Print to output window' action to your time filter, do you find that the time of each bar within your custom time filter prints to the output window?
            (Tools -> Output window)

            Here is how the solution works.

            If the time series (time of the bar) is greater than or equal to 8:00 AM

            ToTime(Time[0]) >= ToTime(8, 0, 0)

            and the time series is less than 5:00 PM

            ToTime(Time[0]) <= ToTime(17, 0, 0)

            Then it will trigger any action below.

            What code do you have added to your script? May I see a screenshot of the condition set?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_ChelseaB View Post
              Hello Dolfan,

              If you add a Misc -> 'Print to output window' action to your time filter, do you find that the time of each bar within your custom time filter prints to the output window?
              (Tools -> Output window)

              Here is how the solution works.

              If the time series (time of the bar) is greater than or equal to 8:00 AM

              ToTime(Time[0]) >= ToTime(8, 0, 0)

              and the time series is less than 5:00 PM

              ToTime(Time[0]) <= ToTime(17, 0, 0)

              Then it will trigger any action below.

              What code do you have added to your script? May I see a screenshot of the condition set?
              Oh, here's the reply. :-)

              I have not coded it myself, I used the Strategy Wizard as directed in the video example and the the pictures depicted in the earlier discussion. Here is the syntax from the "View Code" window (minus the other trading signals from indicators).

              && ToTime(Time[0]) >= ToTime(17, 0, 0)
              && ToTime(Time[0]) < ToTime(8, 30, 0))
              {
              EnterLong(1, "");

              && ToTime(Time[0]) >= ToTime(17, 0, 0)
              && ToTime(Time[0]) < ToTime(8, 30, 0))
              {
              EnterShort(1, "");

              I am assuming that given that everything is done within the wizard, the syntax is correct. Am I missing something here? Thanks for your help.

              Best regards,

              Dolfan

              Comment


                #8
                Hi Dolfan,

                Thanks for posting the code.

                The issue is that the script is looking for the time to be greater than or equal to 5:00 PM (on the same day) and less than 8:30 AM (on the same day) which is not possible.

                What needs to be here is an 'or' instead of an 'and'. The time is greater than 5:00 PM or the time is less than 8:30 AM.

                In C# the 'or' logic is the two vertical lines operator.

                if (ToTime(Time[0]) < ToTime(8, 30, 0) || ToTime(Time[0]) >= (17, 0, 0))
                {
                // execute code
                }

                However, the Strategy Wizard is not capable of adding in 'or' logic. Instead, each line added is automatically joined with an 'and' (&&).

                So to continue using the wizard, you would need to add these to two separate condition statements.
                // Condition set 1
                if (ToTime(Time[0]) < ToTime(8, 30, 0))

                // Condition set 2
                if (ToTime(Time[0]) >= ToTime(17, 0, 0))

                In both condition sets 1 and 2, add the same code to the action block (where it says 'Do the following:') so that both conditions take the same action.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  OK, so if I understand this correctly, where I now have 1 set of conditions to enter long and 1 set of conditions to enter short, I will now need 2 sets of conditions to enter long and 2 sets of conditions to enter short? The first of each set will set the time at plus 5PM and the second of each set will set the time at minus 8:30AM.

                  Comment


                    #10
                    Hello Dolfan,

                    That is correct.

                    If you would like to keep the strategy locked for editing in the Strategy Wizard, you would need to separate the time filter into two conditions one checking for the time being greater than or equal to 17:00 the other being less than 8:30.

                    (If there is a second entry order for entering short and , this would also need to be separated into two conditions as well)
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Chelsea. This seems to be working fine now. I will elevate this challenge a little later. :-)

                      Another problem is occurring in this strategy in that I have it set to read the regression channel and enter only if a crossover occurs and the regression channel agrees with the direction. For example if I have and EMA crossabove and the low of the regression channel for 20 periods is higher than the low of the regression channel for 20 periods 20 bars ago, then enter long. No matter how I adjust the settings, it seems to be ignoring the regression channel check sum. Any thoughts on this? I am using the regression channel to verify immediate trend and hopefully avoid volatility.

                      Best regards,

                      Dolfan

                      Comment


                        #12
                        Hello Dolfan,

                        Something to keep in mind about the regression channel is that the lines you see on a chart, are drawn as a "best fit" line through the data points which may or may not be on that line. In other words, if you see the sma plotting above the regression channel lower line for a particular bar, the data point for the sma on that bar might actually be below the data point for the lower line for the regression channel on that bar.

                        The data points oscillate while the regression line is drawn as an average trend through those points.

                        I would recommend that you unlock your code and add prints to the script so that you can see what values are being returned by the regression channel for each bar and compare this to the close (or high or whatever price point you would like) of that bar.

                        For example:
                        Print(string.Format("{0} | SMA: {1} | Regression Lower: {2}", Time[0], SMA(5)[0], RegressionChannel(35, 2).Lower[0]));
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          I may have misled you here. The crossover is not over the channel. The crossover is between moving averages. I merely seek to use the channel to 'see' that the immediate trend is dedicated and not flopping back and forth every few bars.

                          I have no idea what you wrote in your example there but I do note the 35 regression channel. Seems to be a 'popular' length for the Ninja team. ;-)

                          Thanks once again for all your guidance.

                          Best regards,

                          Dolfan

                          Comment


                            #14
                            Hello Dolfan,

                            I'm not quite sure what you are trying to do.

                            From the text "EMA crossabove and the low of the regression channel for 20 periods is higher than the low of the regression channel for 20 periods 20 bars ago, then enter long".

                            From this I understood you want the EMA value of the current bar to cross above the regression lower channel on the current bar and the regression lower channel from the current bar is greater than the regression lower channel 20 bars ago.

                            What I was warning is, the regression channel itself uses lines. These lines do not match the actual saved values for this indicator.

                            You then mention that you want to see the crossover is moving between averages. I do not know what this means.
                            Can you clarify what you mean by the crossover is moving?
                            Also, please clarify what you mean by between averages. Are you using two EMA calls? Are you averaging the regression lower channel?

                            Can you write out the logic you are looking for as if it were spoken rules?
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              The strategy is based on the HMA moving over the SMA, either up or down. When the cross over happens I mean for the strategy to check the regression channel and read a channel of 20 bars in length with the present bar (in a long buy) being higher than a bar 20 bars back. This to me would indicate a regression channel tilted up, or an upward trend, thus trading with the trend. Since it is not reading it right I am guessing my assumption is incorrect. Would you concur?

                              Dolfan

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by llanqui, Today, 10:32 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post llanqui
                              by llanqui
                               
                              Started by StockTrader88, 03-06-2021, 08:58 AM
                              45 responses
                              3,992 views
                              3 likes
                              Last Post johntraderuser2  
                              Started by TAJTrades, Today, 09:46 AM
                              0 responses
                              8 views
                              0 likes
                              Last Post TAJTrades  
                              Started by rhyminkevin, Yesterday, 04:58 PM
                              5 responses
                              62 views
                              0 likes
                              Last Post dp8282
                              by dp8282
                               
                              Started by realblubb, Today, 09:28 AM
                              0 responses
                              8 views
                              0 likes
                              Last Post realblubb  
                              Working...
                              X