Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Analyzer Stoppped Working

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

    Strategy Analyzer Stoppped Working

    The strategy analyzer stopped returning results - related to date ranges

    example

    If I run an optimization from 9/27/2018 to 1/31/2019 no results are returned. If I change the dates to 9/24/18 to 1/30/19 results are produced. It is an intraday strategy with same exact entry so changing the dates shouldn't affect the results certainly not causing it to create no results.

    This has happened in the past on 2 different computers. Usually I can close and re-open the strategy analyzer and or restart the computer and that fixes the problem but that is not working now.

    I see this error in the log file I do not know if this has any relation. Log attached


    2019-08-23 08:38:28:075|3|4|Strategy 'TweezerTopTrailSE': Error on calling 'OnBarUpdate' method on bar 19: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    I have a lifetime license but this is on a second computer with the free license. It has happened on both computers.

    Thank you for any help Stefan
    Attached Files

    #2
    Hello sdauteuil,

    The error would be related if that is being presented when you see this 0 result test. Any error your script encounters will completely stop the test, if it is seeing an OnBarUpdate error that needs to be corrected before the test will produce results.

    Based on the situation it sounds like this could relate to data, are you adding any secondary series in the script?

    You very likely need a CurrentBar check in the script but that will depend on what series were used and what BarsAgo have been used.


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

    Comment


      #3
      Primary time frame is 50 ticks there is a secondary time frame referencing previous days high.

      However this has happened in the past on scripts without secondary time frame references. Is it possible something is getting trapped in the computer memory or cache? I am not a computer guy just wondering because of the previous fixes when restarting the computer and or strategy analyzer.

      The strategy is built from the strategy builder.

      I see this code in the script

      ** Secondary data series defined
      AddDataSeries(Data.BarsPeriodType.Day, 1
      **

      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;

      if (CurrentBars[0] < 1)
      return;

      I also tried changing the bars required to trade in the strategy analyzer, that had no effect.

      Comment


        #4
        Hello

        Code:
        [I]However this has happened in the past on scripts without secondary time frame references.[/I]
        Correct, when adding multiple series you can run into this error if the script is programmed in a way which allows for that to happen. This can also happen for single series scripts depending on the syntax.

        Can you provide more detail on how the secondary series is being used in your conditions?



        Code:
        [I] Is it possible something is getting trapped in the computer memory or cache? I am not a computer guy just wondering because of the previous fixes when restarting the computer and or strategy analyzer.[/I]
        Based on the error presented that would relate to your logic not memory or cache. It is very likely some way that the scripts logic is formed which is contributing to this. I would need to see the conditions created to better understand why you might see this error. Can you provide an image of the conditions where you used the secondary series?

        Also, you provided syntax but noted you are using the builder, have you unlocked the code or was this just to show the second series being used? if you unlocked the code, I would just need to see the code and we can ignore the builder images.


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

        Comment


          #5
          Here is the code. I also attached a locked and unlocked file. I would like to keep it in the locked strategy builder if possible but if it needs to be unlocked to be fixed... Whatever works

          Thanks again

          #region Using declarations
          using System;
          using System.Collections.Generic;
          using System.ComponentModel;
          using System.ComponentModel.DataAnnotations;
          using System.Linq;
          using System.Text;
          using System.Threading.Tasks;
          using System.Windows;
          using System.Windows.Input;
          using System.Windows.Media;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Gui;
          using NinjaTrader.Gui.Chart;
          using NinjaTrader.Gui.SuperDom;
          using NinjaTrader.Gui.Tools;
          using NinjaTrader.Data;
          using NinjaTrader.NinjaScript;
          using NinjaTrader.Core.FloatingPoint;
          using NinjaTrader.NinjaScript.Indicators;
          using NinjaTrader.NinjaScript.DrawingTools;
          #endregion

          //This namespace holds Strategies in this folder and is required. Do not change it.
          namespace NinjaTrader.NinjaScript.Strategies
          {
          public class TweezerTopTrailSEunlocked : Strategy
          {
          private int TriggerState;
          private double TriggerPrice;
          private string EntrySignal;
          private int AtrPeriod;
          private int HighValue1;
          private int HIghValue2;

          private MAX MAX1;
          private MAX MAX2;

          private AtrTrailingOnClose AtrTrailingOnClose1;
          private AtrTrailingOnClose AtrTrailingOnClose2;

          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = @"Enter Short on cross of ATR TS - exit profit, stop, ATR TS cross below adx and above adxr values";
          Name = "TweezerTopTrailSEunlocked";
          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 = true;
          ProftTarget = 16;
          StopLoss = 18;
          AtrFactorTa = 0.5;
          TaAdjust = 40;
          Contracts = 1;
          HighBar1 = 20;
          HIghBar2 = 5;
          TriggerState = 0;
          TriggerPrice = 1;
          EntrySignal = @"Short Atr Cross Brk Out";
          AtrPeriod = 1;
          HighValue1 = 1;
          HIghValue2 = 1;
          }
          else if (State == State.Configure)
          {
          AddDataSeries(Data.BarsPeriodType.Day, 1);
          }
          else if (State == State.DataLoaded)
          {
          MAX1 = MAX(High, Convert.ToInt32(HighBar1));
          MAX2 = MAX(High, Convert.ToInt32(HIghBar2));
          AtrTrailingOnClose1 = AtrTrailingOnClose(Close, AtrFactorTa, Convert.ToInt32(1), 0);
          AtrTrailingOnClose2 = AtrTrailingOnClose(Close, AtrFactorTa, Convert.ToInt32(1), 0);
          MAX1.Plots[0].Brush = Brushes.SkyBlue;
          MAX2.Plots[0].Brush = Brushes.Yellow;
          AtrTrailingOnClose1.Plots[0].Brush = Brushes.Firebrick;
          AtrTrailingOnClose1.Plots[1].Brush = Brushes.Firebrick;
          AddChartIndicator(MAX1);
          AddChartIndicator(MAX2);
          AddChartIndicator(AtrTrailingOnClose1);
          SetProfitTarget(EntrySignal.ToString(), CalculationMode.Ticks, ProftTarget);
          SetStopLoss(EntrySignal.ToString(), CalculationMode.Ticks, StopLoss, false);
          }
          }

          protected override void OnBarUpdate()
          {
          if (BarsInProgress != 0)
          return;

          if (CurrentBars[0] < 1)
          return;

          // Set 1
          if (Position.MarketPosition == MarketPosition.Flat)
          {
          TriggerState = 0;
          HighValue1 = Convert.ToInt32(MAX1[1]);
          HIghValue2 = Convert.ToInt32(MAX2[1]);
          }

          // Set 2
          if ((Close[0] == Low[0])
          && (Open[0] == High[0])
          && (HighValue1 > HIghValue2)
          && (TriggerState == 0)
          && (Close[0] < Highs[1][0])
          && (Times[0][0].TimeOfDay >= new TimeSpan(6, 30, 0))
          && (Times[0][0].TimeOfDay <= new TimeSpan(13, 0, 0)))
          {
          EnterShort(Convert.ToInt32(Contracts), EntrySignal.ToString());
          TriggerState = 1;
          }

          // Set 3
          if ((TriggerState == 1)
          && (Position.MarketPosition == MarketPosition.Short))
          {
          TriggerPrice = (Position.AveragePrice + (TaAdjust * TickSize)) ;
          }

          // Set 4
          if ((Close[0] <= TriggerPrice)
          && (Position.MarketPosition == MarketPosition.Short))
          {
          TriggerState = 2;
          Draw.Diamond(this, @"Trail Stop Adjust Diamond_1", false, 0, (High[0] + (20 * TickSize)) , Brushes.Yellow);
          }

          // Set 5
          if ((Close[1] < AtrTrailingOnClose1.Lower[1])
          && (Close[0] >= AtrTrailingOnClose2.Lower[1])
          && (TriggerState == 2))
          {
          ExitShort(Convert.ToInt32(Contracts), @"ATR ADJUST EXIT", EntrySignal.ToString());
          }

          }

          #region Properties
          [NinjaScriptProperty]
          [Range(1, double.MaxValue)]
          [Display(Name="ProftTarget", Description="Profit Target", Order=1, GroupName="Parameters")]
          public double ProftTarget
          { get; set; }

          [NinjaScriptProperty]
          [Range(1, double.MaxValue)]
          [Display(Name="StopLoss", Description="Stop Loss Trailing or Static", Order=2, GroupName="Parameters")]
          public double StopLoss
          { get; set; }

          [NinjaScriptProperty]
          [Range(0.25, double.MaxValue)]
          [Display(Name="AtrFactorTa", Description="Atr Multiple for Second Exit", Order=3, GroupName="Parameters")]
          public double AtrFactorTa
          { get; set; }

          [NinjaScriptProperty]
          [Range(-5000, int.MaxValue)]
          [Display(Name="TaAdjust", Description="Number of Ticks to Trigger Stop adjustment", Order=4, GroupName="Parameters")]
          public int TaAdjust
          { get; set; }

          [NinjaScriptProperty]
          [Range(1, int.MaxValue)]
          [Display(Name="Contracts", Description="Number of contracts to trade", Order=5, GroupName="Parameters")]
          public int Contracts
          { get; set; }

          [NinjaScriptProperty]
          [Range(1, int.MaxValue)]
          [Display(Name="HighBar1", Description="First High Dbl Top", Order=6, GroupName="Parameters")]
          public int HighBar1
          { get; set; }

          [NinjaScriptProperty]
          [Range(1, int.MaxValue)]
          [Display(Name="HIghBar2", Description="Second High Dbl Top", Order=7, GroupName="Parameters")]
          public int HIghBar2
          { get; set; }
          #endregion

          }
          }
          Attached Files

          Comment


            #6
            I tried to post the code in the text and attach the strategy files but the post gets stuck "pending".

            Here are the script files locked an unlocked. I would like to keep it in the strategy builder if possible but whatever works.

            I can try to repost the code in the text if you would like.
            Attached Files

            Comment


              #7
              Hello sdauteuil ,

              Thank you for providing the files,

              From what I can tell, it is related the following line:

              Code:
              && (Close[0] < Highs[1][0])
              This syntax is using the secondary series, we need a CurrentBars check because of this to make sure that series has data. I see that the locked strategy has the check but your unlocked version does not have the full check so that is one item to change.

              Can you test the following from your end? I was getting the error but no longer seem to be able to hit it after trying some changes, reverting back I am still not seeing it so this may be quicker for you to also test this.

              Make a new duplicate of the builder strategy and unlock it so all code is identical again

              Change the following:
              Code:
              if (CurrentBars[0] < 1
                          || CurrentBars[1] < 0)
              to
              Code:
              if (CurrentBars[0] < 1
                          || CurrentBars[1] [B]< 1[/B])
              Then retest, do you still see the error?

              The only difference is that this makes sure both series have 1 bar before processing and not that the primary has a bar and secondary is loaded.


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

              Comment


                #8
                I only saw the code

                if (CurrentBars[0] < 1 ** I did not see that second line of code

                I did change it to

                if (CurrentBars[0] < 1
                || CurrentBars[1]<1)

                That seems to be working... I will give it some additional testing as I have seen this correct itself and start causing the same error.

                What does the double vertical line stand for?


                Comment


                  #9
                  Hello sdauteuil,

                  Yes in one of your scripts that syntax is not present, if you duplicated the script before adding the second series that would have been added later. The double pipes || means OR, if CurrentBars[0] < 1 OR CurrentBars[1] < 1

                  I will provide this information to development as well, if you created the strategy with the builder this type of error is not generally expected and is not something you should need to manually edit.


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

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by swestendorf, Today, 11:14 AM
                  2 responses
                  5 views
                  0 likes
                  Last Post NinjaTrader_Kimberly  
                  Started by xiinteractive, 04-09-2024, 08:08 AM
                  4 responses
                  13 views
                  0 likes
                  Last Post xiinteractive  
                  Started by Mupulen, Today, 11:26 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post Mupulen
                  by Mupulen
                   
                  Started by Sparkyboy, Today, 10:57 AM
                  1 response
                  5 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by TheMarlin801, 10-13-2020, 01:40 AM
                  21 responses
                  3,917 views
                  0 likes
                  Last Post Bidder
                  by Bidder
                   
                  Working...
                  X