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() and Times() Optimization for Trades

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

    ToTime() and Times() Optimization for Trades

    Hello:

    I am developing code to determine the best trading time(s) each day for an instrument. The code currently uses arrays for storage of trades based on a 1 minute seconday bar series. Thus 390 bars per trading day for stocks (9:30 AM - 4:00 PM). Any ideas on how to set up initial code (if{}, etc.) for testing all combinations of times in a trading day based on the 1 minute secondary bar series?

    Thanks,
    Tony

    #2
    Hi tonyh,

    You could set up your conditions and actions within a time filter...

    Code:
    if (ToTime(Time[0]) >= StartTime && ToTime(Time[0]) <= EndTime)
    {
    
    }
    where StartTime and ToTime are public variables with initial settings of, for example, "90000" and "StartTime + 500".
    More info at - http://www.ninjatrader-support2.com/...ead.php?t=3226

    You can then use the optimizer to test for StartTime range from 90000 to 155500, for example.
    More info at - http://www.ninjatrader-support.com/H...imizeAStrategy
    TimNinjaTrader Customer Service

    Comment


      #3
      SampleTimeFilter

      Hello Tim:

      I currently use both the IntraBarBacktest and SampleTimeFilter codes provided by NT, as well as BeginTime and EndTime in my program to process and store trades. My initial try was similar to yours, adding to BeginTime and subtracting from EndTime one bar each time through. This obviously shrinks the time period to 12:45 - 12:46 PM as the last optimization , but misses lots of possibilities:

      93000 - 160000 93000 - 155900 ... 93000 - 93100
      93100 - 160000 93100 - 155900 ... 93100 - 93200
      ...
      155900 - 160000

      I was trying to fit each possible scenario into 1 if{} statement to make sure the optimization would cover all possibities. Would a counter be helpful to update BeginTime?

      Comment


        #4
        Hi tonyh,

        This would clearly take a very long time to compute every single minute combination on even one day, let alone several, however, you could do something like...

        StartTime = 90000
        EndTime = (StartTime + HourOffset) + MinOffset

        Then optimize for:
        StartTime 90000 - 155900 and
        HourOffset 10000 - 60000 and
        MinOffset 100 - 5900.

        If this is with NinjaTrader 7, consider using the Genetic options for optimizing.
        TimNinjaTrader Customer Service

        Comment


          #5
          Long Optimization Times - Genetic Code

          I plan on the code optimizing much larger time increments than 1 minute. I was just trying to simplify the code that includes all possible situations and go from there. Based on your comment, I found genetic code is available on the site for large optimization schemes. I use NT6.5.1000.15, not NT7 beta, so I'll start there. Thanks again Tim.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by DJ888, Today, 10:57 PM
          0 responses
          1 view
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by MacDad, 02-25-2024, 11:48 PM
          7 responses
          158 views
          0 likes
          Last Post loganjarosz123  
          Started by Belfortbucks, Today, 09:29 PM
          0 responses
          7 views
          0 likes
          Last Post Belfortbucks  
          Started by zstheorist, Today, 07:52 PM
          0 responses
          7 views
          0 likes
          Last Post zstheorist  
          Started by pmachiraju, 11-01-2023, 04:46 AM
          8 responses
          151 views
          0 likes
          Last Post rehmans
          by rehmans
           
          Working...
          X