Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

strategy automation during certain hours

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

    strategy automation during certain hours

    Hello,

    I am trying to figure out how to automate on a strategy only during certain hours. I want the chart to run 24 x 7 to get the technical indicators to plot around the clock, so I have the chart setup from 12 AM to 12 AM to read data, however I am unable to get the time data "set" criteria formatted correctly within the strategy.

    As an example, let's say I only want the strategy to work from 8 AM to 9 AM.

    Is there a code example for the Ninja Script language available?

    Thank you,

    Trader Tom

    #2
    Yes there is; here.
    mrlogik
    NinjaTrader Ecosystem Vendor - Purelogik Trading

    Comment


      #3
      Thank you MrLogik!
      DenNinjaTrader Customer Service

      Comment


        #4
        Thanks for the reply. Here is a snippit of the code that was referenced:

        ToTime(Time[0]) >= 93000

        Which I assume means if current time is greater than 9:30 AM. That's fine ... But the question becomes is it possible to use the script editor to create such a line of code?

        When I try to use the time function, I can only make a code such as follows:

        ToTime(8, 0, 0) < ToTime(9, 0, 0)

        Which is clearly going to be the case always as 8 AM is always going to be < 9 AM ... So the question becomes how do we do a "current time" ...

        Comment


          #5
          Not sure what you mean "current time". Time[0] is the current time. It is the time of the latest bar. If you want a time as in your PC clock time you can try using DateTime.Now.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            &quot;time of current bar&quot;

            ok, Josh, that is exactly what I am trying to figure out. Using the "condition builder" within the Ninja Script Wizard, how do I put in the time of the current bar to set it up to be a condition.

            When I put in "price data" "close" on the left side of the argument for example, I get an error that states, "Return type of left expression 'IdataSeries' and right expression 'DateTime" do not match. You need to select a different item.

            While the sample code is great, is it possible to use the NT Script Wizard to build the code? And if so, I am trying to figure out how / where can I select the "time of current bar" to put into the condition.

            Comment


              #7
              &quot;time series&quot; selection bars ago = 0

              ok, ... I think I found the answer. I needed to select the "time series" selection to get the current time.

              Thanks for the responses as I muddled through what I guess is most obvious to everyone else.

              Now we are cooking!!!

              Comment


                #8
                day of week

                ok, making some progress now on the time with that code implemented. Now I'm trying to make use of the day of week function.

                Is that possible to put in place via the NT Script Wizard? If so, that's where I am now stuck to set to not trade on Friday. I see the code to do it would be like this, but I'm trying to build as much as possible using the wizard as I can. The code would be:

                Time[0].DayOfWeek != DayOfWeek.Friday

                It looks like the "date value" would select a day of the week, but not sure it would for "every" Friday for example. The code that gets put in there when I select this coming friday for example becomes:

                ToTime(Time[0]) != ToDay(2008, 9, 12)

                Is it possible to put this code in via the Wizard for "every friday"?

                Comment


                  #9
                  Hello,


                  No, day of the week is not possible in the Wizard, however a certain date its.

                  It looks like you are on the correct path with your non-Wizard code though.
                  DenNinjaTrader Customer Service

                  Comment


                    #10
                    Tom,

                    Create as much as you can via the wizard, then in the OnBarUpdate() function you can just add a line above your entry criteria that states

                    Code:
                    if(Time[0].DayOfWeek == DayOfWeek.Friday)
                        return;
                    To not allow any trades on Friday. You can expand this logic to fit whatever you needs are.

                    mrLogik
                    mrlogik
                    NinjaTrader Ecosystem Vendor - Purelogik Trading

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by DJ888, 04-16-2024, 06:09 PM
                    6 responses
                    18 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by Jon17, Today, 04:33 PM
                    0 responses
                    1 view
                    0 likes
                    Last Post Jon17
                    by Jon17
                     
                    Started by Javierw.ok, Today, 04:12 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post Javierw.ok  
                    Started by timmbbo, Today, 08:59 AM
                    2 responses
                    10 views
                    0 likes
                    Last Post bltdavid  
                    Started by alifarahani, Today, 09:40 AM
                    6 responses
                    41 views
                    0 likes
                    Last Post alifarahani  
                    Working...
                    X