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

limit run time of day

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

    limit run time of day

    How do you restrict a script to particular times of the day? Lets say I want my strategy to only execute trades on between 3pm and 4pm EST. How would I do that? And how would I be able to test it. While we are asking, what about particular days, or days of the week.

    Thanks

    #2
    You can do this using a datetime object

    Here is an example script: http://www.ninjatrader.com/support/f...ead.php?t=3226

    This link also includes links to additional references in the help guide.

    Let me know if you have further questions on this.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Thank you.

      But here is an even more basic question.
      How do you actually stick that into a strategy? How do we take that ninjascript and my strategy ninjascript and mash'em together so they are one? And then my strategy runs with the time constraints from the example.

      Thanks again

      Comment


        #4
        If your using the NinjaScript Editor you would take the logic from the sample and place it around your current strategy logic. If you're unsure of how to do this let me know and I can provide you with additional script learning material.

        Based on this question I'm wondering if you're using the strategy wizard. If you are you wont have the same amount of flexibility with your filters but you will be able to create a basic time or date filter. See this video at this current time for how to do this: http://www.youtube.com/watch?v=SpwGT...ilpage#t=1448s
        LanceNinjaTrader Customer Service

        Comment


          #5
          Time Filters

          I followed the thread for inserting the basic time filters to trade between certain times of the day and only on my entries. Something isn't correct b/c it took a strategy that was generating 2,000 trades over 2.5yrs to making more than 26,000 over the same period. here is the code I used - the only other issue I can think of is that I am pulling the chart up in Renko and executing the trades off of a tic chart. Is somehow the reference to "totime" calculating off of tick and not renko?

          // Condition set 1
          if (


          ATR(BOP(21), 14)[0] > 0
          && Close[0] >= ParabolicSAR(0.02, 0.2, 0.02)[0]





          && (ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 01000)
          || (ToTime(Time[0]) >= 02000 && ToTime(Time[0]) < 04000)
          || (ToTime(Time[0]) >= 05000 && ToTime(Time[0]) < 07000)
          || (ToTime(Time[0]) >= 08000 && ToTime(Time[0]) < 170000)
          || (ToTime(Time[0]) >= 180000 && ToTime(Time[0]) < 230000)





          )



          {
          EnterLong(tbip,positionSize, "L RT");

          Comment


            #6
            Without debugging the entire script it would be hard for me to isolate the specific cause of any error.

            However with the information you have shared I do suspect there are some issues relating to the renko bar type.

            Renko bars have several issues when performing a backtest. While you said your adding a secondary tick series to get added granularity one other issue that likely isn't accounted for is the fact that the Renko bar opens change in real time.

            Please see this thread for a longer discussion on this: https://www.bigmiketrading.com/ninja...ko-charts.html

            Also, depending on how you're structuring of Bars in progress the time filter might be based on a different BIP.

            Let me know if I can further assist.
            LanceNinjaTrader Customer Service

            Comment


              #7
              Time Filter

              There was no material change in performance i assume b/c the calculation is on bar close while the execution order is immediately on tick data at the time the bar closed. also b/c we are talking forex assuming a non econ data release at the moment the bar closes the next available tick should be close to the bar close.

              but okay still does not solve why the code i laid out before creates so many executions

              here is what I am using for the tick data "Add(PeriodType.Tick,1);" is this the correct code to state the time frames filters

              && Time[0].DayOfWeek != DayOfWeek.Tuesday // It does not work on thursdays
              && (ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 01000)
              || (ToTime(Time[0]) >= 02000 && ToTime(Time[0]) < 04000)
              || (ToTime(Time[0]) >= 05000 && ToTime(Time[0]) < 07000)
              || (ToTime(Time[0]) >= 08000 && ToTime(Time[0]) < 170000)
              || (ToTime(Time[0]) >= 180000 && ToTime(Time[0]) < 230000)

              Comment


                #8
                While it looks like you're filtering time here one thing I'm not sure of is how your code is structured to handle the different time frames.

                what could be happening is your system is trading both off of the tick and renko time frame.

                Please see this document for how to setup your OnBarUpdate structure to handle multi series: http://www.ninjatrader.com/support/h...nstruments.htm

                Let me know how I can further assist.
                LanceNinjaTrader Customer Service

                Comment


                  #9
                  here is the code reference for the barsinprogress

                  }

                  protected override void OnStartUp()
                  {
                  for (int a = 0; a< BarsArray.Length; a++)
                  Print(this.Name+" Bars data ["+a+"] contains "+BarsPeriods[a].ToString()+" of "+BarsArray[a].Count+" bars, commencing at "+BarsArray[a].Get(0).Time);
                  }

                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {




                  if (BarsInProgress > 0 || CurrentBar < BarsRequired)
                  return; // don't process anything directly on the high granularity timeframe, or early in the chart's data

                  Comment


                    #10
                    I'm not seeing any obvious problems with the information presented.

                    Your NinjaScript / C# Code will always be logically processed and evaluate according to your set logic – this can of course lead to unexpected results at times, thus we would suggest to simplify and debug your code to better understand the event sequence it would go through

                    First of all you would want to use Print() statements to verify values are what you expect - Debugging your NinjaScript code.

                    For strategies add TraceOrders = true to your Initialize() method and you can then view valuable output related to strategy submitted orders through Tools > Output window - TraceOrders

                    It may also help to add drawing objects to your chart for signal and condition confirmation - Drawing Objects.

                    If you would prefer the debug assist of a professional NinjaScript consultant, please send mail to support [at] ninjatrader [dot] com
                    LanceNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Jimmyk, 01-26-2018, 05:19 AM
                    6 responses
                    835 views
                    0 likes
                    Last Post emuns
                    by emuns
                     
                    Started by jxs_xrj, 01-12-2020, 09:49 AM
                    6 responses
                    3,291 views
                    1 like
                    Last Post jgualdronc  
                    Started by Touch-Ups, Today, 10:36 AM
                    0 responses
                    10 views
                    0 likes
                    Last Post Touch-Ups  
                    Started by geddyisodin, 04-25-2024, 05:20 AM
                    11 responses
                    62 views
                    0 likes
                    Last Post halgo_boulder  
                    Started by Option Whisperer, Today, 09:55 AM
                    0 responses
                    9 views
                    0 likes
                    Last Post Option Whisperer  
                    Working...
                    X