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

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:
      Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...


      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, 07: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]) <[B] ToTime(8,10,00)[/B]) 
          && 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, 08: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, 08: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,


                  Below would be an example of how you can have your strategy trade between certain times.


                  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 funk10101, Today, 12:02 AM
                    1 response
                    10 views
                    0 likes
                    Last Post NinjaTrader_LuisH  
                    Started by GLFX005, Today, 03:23 AM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_Erick  
                    Started by nandhumca, Yesterday, 03:41 PM
                    1 response
                    12 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by The_Sec, Yesterday, 03:37 PM
                    1 response
                    11 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by vecnopus, Today, 06:15 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post vecnopus  
                    Working...
                    X