• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ToTime() not working

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

    ToTime() not working

    Hi,

    I tried adding a time constraint in my strategy but can't get it working. I want to add a "maximum 15 minute" rule between two swing highs that I capture in previous steps. I used ToTime() function as it was described in the Help Menu.

    Code:
    if (model_A && ToTime(Time[new_swing_high])-ToTime(Time[old_swing_high])<=1500)
    	{
    	 Order Rules ...
    	}
    My script compiles and strategy executes orders as if there's not time constraint. Any idea where i'm going wrong?

    Thanks
    MT

    #2
    Use Print to print out your computations to the Output window.

    You will eventually find the issue. It could be model_A or your swing time calculations.
    Impossible to tell from here.

    Comment


      #3
      Hello mntemel,

      Thank you for your note.

      Sledge offers a great suggestion, I too would suggest adding print statements to check the value of your variables. I’ve provided a link to a youtube video which covers an example of using prints to understand behavior:
      https://www.youtube.com/watch?v=K8v_...tu.be&t=48m45s

      I’ve provided a link covering debugging which you may find helpful.
      Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418

      Please let us know if you need further assistance.
      Alan P.NinjaTrader Customer Service

      Comment


        #4
        ToTime not working...

        if ((ToTime(Time[0]) < 91000)
        && Time[0].DayOfWeek != DayOfWeek.Sunday)

        {
        Print("true");
        }

        I ran this at 092000 and outputted "true".... ideas why?

        Output window gives 20180702,85900 which is the date and time stamp for the end of the primary series.



        Regards and thx
        Last edited by elliot5; 07-02-2018, 06:57 AM.

        Comment


          #5
          Hello everington_f,

          Thank you for your note.

          If you use the following if statement do you get the results you desire?

          Code:
          if ((ToTime(Time[0]) < ToTime(8,10,00)) 
          && Time[0].DayOfWeek != DayOfWeek.Sunday)
          I look forward to your reply.
          Alan P.NinjaTrader Customer Service

          Comment


            #6
            No same problem.

            Should I add a new tick series and reference that to get the current time? All I want is easy access to the computer clock current time.
            Last edited by elliot5; 07-02-2018, 07:31 AM.

            Comment


              #7
              Hello everington_f,

              What period data series are you running this on?

              If you run this on a 1 minute chart do you see different results?

              I look forward to your reply.
              Alan P.NinjaTrader Customer Service

              Comment


                #8
                Gold overnight session 1108 minute ... so ToTime simply prints the end timestamp of the bar series. Added a tick series but it crashed NT twice.

                Simply want to trade once per session... but cant rely on ToTime to reset the counter.
                Last edited by elliot5; 07-02-2018, 07:50 AM.

                Comment


                  #9
                  Hello everington_f,

                  I would suggest adding a 1 minute data series, since the period you are applying the strategy to is 1108 minutes, and a 1 minute series will have a close every 1 minute.

                  Below would be an example of adding additional data series to a script,
                  https://ninjatrader.com/support/foru...ead.php?t=5787

                  Below would be an example of how you can have your strategy trade between certain times.
                  https://ninjatrader.com/support/foru...ead.php?t=3226

                  I have also attached 2 strategies which will only trade once per day,

                  Please let us know if you need further assistance.
                  Attached Files
                  Alan P.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks have got around the crashing from adding data series... your help appreciated and a very comprehensive reply. Thx

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by tecmisc1, Today, 09:57 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post tecmisc1  
                    Started by mbesha, Today, 09:26 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post mbesha
                    by mbesha
                     
                    Started by Brillo, Today, 08:58 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post Brillo
                    by Brillo
                     
                    Started by avrege, Today, 01:48 AM
                    2 responses
                    14 views
                    0 likes
                    Last Post avrege
                    by avrege
                     
                    Started by markbb10, Today, 07:14 AM
                    0 responses
                    7 views
                    0 likes
                    Last Post markbb10  
                    Working...
                    X