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

Strategy Analyzer performance issues

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

    Strategy Analyzer performance issues

    Hi

    The below strategy only contains like 300 lines from top to bottom including variables and properties, but it kills my PC when I try to do a backtest!So much so, I converted it over to NT8 from NT7 to try and improve backtesting performance, but no joy. My PC is only 2 years old, and no other progs are open and running while I'm trying this.

    Can anyone see anything obvious that I can do to get this to run quickly and efficiently on a portfolio of forex? I've tried already doing each currency one by one, and it still kills my machine. Have got lucky and have a couple of results, so I know the code is working, but overall, I've wasted hours and still got a lot of testing to do.

    Thanks all,
    Steve

    public class zzRSIdblretrace : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int rSIOverbought = 80; // Default setting for RSIOverbought
    private int rSIOversold = 1; // Default setting for RSIOversold
    private int stopLong = 1;
    private double stopShort = 0;
    private double profitShort = 0;
    private int BarCountOverbought = 0;
    private int BarCountRetest = 0;
    private int BarCountBreaklow = 0;
    private int Trendperiod = 50;
    private double x1=1.0;
    private int p1 = 6;
    private int s1 = 3;
    private int AvTR=0;
    private int movav=300;
    private int movavshort=50;
    private bool Notrade= true;
    private bool Overbought= false;
    private bool Retest= false;
    private bool Breaklow= false;
    private bool Oversold= false;
    private bool rolA= true;
    private bool rolB= false;
    private bool rolC= false;
    private bool rolD= false;
    private bool rolE= false;
    private bool rolF= false;
    private bool rolG= false;
    private bool rolH= false;
    #endregion
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "zzRSIdblretrace";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = false;
    }
    else if (State == State.Configure)
    {
    }
    }
     

    #2
    Hello lancasterstephen,

    Thanks for your post.

    Based on what you have posted, no, I don't see anything that would improve the processing time.

    How long does the processing time take for 1 instrument?
    Do you already have the historical data or does the processing time include downloading as well?
    What type bars are you backtesting?
    What duration of time are you back testing over?
    What data provider are you connected to for your historical data?
    Can you provide any further detail concerning your performance observations?
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi

      I'm trying to run it on 15m and 60m bars for thee period 2010 to 2017

      It takes up to 20 mins for one instrument on 60m and I have not got 15m to work yet- it just hangs and gives up

      I'm using fxcm for the data. I don't know if the processing time includes time to download or not. I'm not sure what you mean by this.

      However I do not have the connection to fxcm "live" when backtesting because I saw sever performance issues on nt7 when this was the case

      Any help would be very much appreciated

      Comment


        #4
        Hello lancasterstephen,

        Thanks for your reply.

        Please check your NT8 to FXCM connection and make sure that: "NinjaTrader historical data servers: For optimal performance, enable the "NinjaTrader historical data servers" checkbox" is checked.

        Next, we recommend that you download the data needed first then disconnect and try the backtest again.

        To download the data, we recommend using the Historical data manager. Please see the helpguide here: https://ninjatrader.com/support/help.../?download.htm

        (You can try the same approach in NT7 as well)
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hi

          Thanks for the advice, all that makes sense to me. I've performed both steps you recommended....but it still hangs and ends up not responding, leading to NT8 having to be shut down via task manager.

          Do you have any further suggestions? I'm sure NT8 is capable of much more regarding backtesting, and people out there will be using a lot more complex strategy than I am.

          I've attached the NT8 version of the strategy I'm trying to use, its only 10kb in size. I'd be really grateful for any further advice you can provide.

          Many thanks
          Steve
          Attached Files

          Comment


            #6
            Hello lancasterstephen,

            Thanks for your reply.

            Please note that in the support department at NinjaTrader we do not create, debug, or modify code for our clients. This is so that we can maintain a high level of service for all of our clients.

            In a quick review of your code:

            You are making a number of in-line references to indicators and this has a performance cost. Please review the helpguide section on best ninjascript practices, performance section: https://ninjatrader.com/support/help..._practices.htm

            Your code could be written to reduce the number of checks of the same thing, for example, you have 13 checks to see if the market position is flat, you can reduce this to 1 check and then have your other conditions below that grouped together where it makes sense. There may be other opportunities to improve the code performance and thus improve the analysis performance.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hi

              Your guidance is very much appreciated, thanks for the referral to the Help text. I've made a number of changes and the backtesting performance speeds have significantly improved.

              I'm also getting an error everytime I backtest

              Value of property of 'Period' of NinjaScript 'MAX' is 0 and not in the valid range between 1 and 2147483647.
              Do you have any guidance on how to fix this?

              I have looked through my code- I do not have a variable named 'Period' and any reference to the use of the MAX calculation looks to make absolute sense to me. When I run F5 on the code, I get the "OK" and it does not show me any errors.

              I've looked at the downloaded historical data I'm using, and it all appears to be there. So, I do not think it relates to that part either.

              Comment


                #8
                Hello lancasterstephen,

                Thanks for your reply.

                The error message is advising that the period for the MAX() method is 0 and needs to be 1 or greater. The period is the lookback that the MAX(0 method uses and is required for its use. Reference: https://ninjatrader.com/support/help...aximum_max.htm

                Recompiling the code would not yield any errors because the error only occurs at run-time when the variable used for the period is dynamically calculated.

                In this example, from your code: MAX(High,BarCountOverbought)[BarCountRetest+BarCountBreaklow] The input series to the MAX() is the High data series and the variable BarCountOverbought is what defines the lookback period. So at some point the run time error occurred because the variable BarCountOverbought was determined not to be in the range of 1 or greater.

                To resolve, you would need to debug your strategy further, likely using Print statements to advise the value of BarCountOverbought before the MAX() method is called. You would also then need to find the statements that set the value of BarCountOverbought to then understand why they are zero. To further assist, here is a reference to our debugging tips: https://ninjatrader.com/support/foru...ead.php?t=3418
                Paul H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by yertle, Yesterday, 08:38 AM
                7 responses
                28 views
                0 likes
                Last Post yertle
                by yertle
                 
                Started by bmartz, 03-12-2024, 06:12 AM
                2 responses
                21 views
                0 likes
                Last Post bmartz
                by bmartz
                 
                Started by funk10101, Today, 12:02 AM
                0 responses
                4 views
                0 likes
                Last Post funk10101  
                Started by gravdigaz6, Yesterday, 11:40 PM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by MarianApalaghiei, Yesterday, 10:49 PM
                3 responses
                11 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Working...
                X