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

If today is Friday... and If current time is ...

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

    If today is Friday... and If current time is ...

    Hi NT,

    1)
    I am running a script on Weekly Bars.
    I want to be indicator to = 1 if a condition is met; else 0.
    I have it set to OnPriceChange, so that I dont wait until the Monday's open for =1
    In order to be alerted earlier, how can I say: "If today is Friday".

    2) Similarly
    I am running a script on Daily Bars.
    I want to be indicator to = 1 if a condition is met; else 0.
    I have it set to OnPriceChange, so that I dont wait until the tommorow's open for =1
    In order to be alerted earlier, how can I say: "If the current time is > 7:00 pm".

    Thanks
    AK

    #2
    Hello akvevo,

    Thanks for opening the thread.

    I would suggest to use the ToDay() and ToTime() methods to easily create this logic. You could pass in a TimeSeries object to get the time of the bar close, or you could use DateTime.Now for an exact time when the DateTime object is referenced.

    ToDay() - https://ninjatrader.com/support/help...n-us/today.htm

    ToTime() - https://ninjatrader.com/support/help...-us/totime.htm

    Sample code is included in the documentation links above.

    Please let me know if I may be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks Jim,

      The example doesnt show how to say "if day is week is X".
      ToDay() represent a single specific day, whereas I am want a day of the week "Friday".
      Any ideas on this one ?

      I tried:

      Code:
      if (Time[0].DayOfWeek = DayOfWeek.Friday)
      But this fails with:
      -Property of indexer 'System.DateTime.DayOfWeek' cannot be assigned to -- it is read only
      -Cannot implicity convert type ' System.DayofWeek' to 'bool'

      Comment


        #4
        Hello akvevo,

        You are attempting to assign DayOfWeek.Friday to Time[0].DayOfWeek in an if statement. You should use the is-equal operator "==" instead of the assignment operator "="

        These same errors have been encountered numerous times by others online. You can often find a resolution for these compiler errors by Googling the error code and the description to get further input on the error.

        Microsoft has a publicly available reference here: https://msdn.microsoft.com/en-us/lib...5d(vs.71).aspx

        Additionally available is the programming concepts section of the NinjaTrader 7 help guide: http://ninjatrader.com/support/helpG...g_concepts.htm

        Please let me know if I can be of further help.
        JimNinjaTrader Customer Service

        Comment


          #5
          School boy error on my behalf, Thanks Jim !

          Comment


            #6
            Day of week bug

            My PC clock is set on US EST, and when trading a strategy on the SGX singapore I use;

            && Time[0].DayOfWeek != DayOfWeek.Sunday

            to prevent any trades happening on what is effectively a monday in singapore. (SGX monday session opens at 20;00 hrs EST on the Sunday.

            A trade went through this morning despite that logic....
            any ideas how that is possible?

            Regards

            Comment


              #7
              Hello everington_f,

              Thanks for your question.

              In order to assist you further could you provide me answers to the following questions?

              1. Could you tell me what you are receiving in the output window when you print the day of the week in your code?

              Print(Time[0].DayOfWeek);

              2. Additionally, could you tell me the Time Zone that you have set in the Options menu of the Control Center? (Control Center > Tools > Options > General > Time Zone.)

              I look forward to being of further assistance.
              JimNinjaTrader Customer Service

              Comment


                #8
                Time zone set to UTC -5 Eastern

                I can only run that print as of 8pm eastern this evening.

                Comment


                  #9
                  Hello everington_f,

                  Thanks for your reply.

                  Debugging with prints will be necessary to fully understand the issue at hand. Could you test this occurrence with your strategy using Market Replay data with the aforementioned print as well as prints for your other order conditions? Please also enable TraceOrders so we can better understand the submission that occurred.

                  I've attached some additional information on debugging and using Trace Orders.

                  Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418

                  TraceOrders: http://ninjatrader.com/support/forum...ead.php?t=3627

                  Market Replay (Playback Connection) - https://ninjatrader.com/support/help...s/set_up12.htm

                  Please let me know the results you see for the order submission that you have in question.
                  JimNinjaTrader Customer Service

                  Comment


                    #10
                    It appears that the day of the week is not associated with the computer clock because the strategy based on SGX printed tuesday when the computer clock was on Monday 8pm EST. Problem fixed.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by junkone, Today, 11:37 AM
                    2 responses
                    12 views
                    0 likes
                    Last Post junkone
                    by junkone
                     
                    Started by frankthearm, Yesterday, 09:08 AM
                    12 responses
                    43 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by quantismo, 04-17-2024, 05:13 PM
                    5 responses
                    35 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by proptrade13, Today, 11:06 AM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by love2code2trade, 04-17-2024, 01:45 PM
                    4 responses
                    35 views
                    0 likes
                    Last Post love2code2trade  
                    Working...
                    X