Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stopping a strategy for running thrice in backtesting

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

    Stopping a strategy for running thrice in backtesting

    To my knowledge, strategies run, or are at least initialized three times during backtesting. I'd like to only run my full strategy once, as I have some expensive computation going on outside of the onbarupdate method. How can I cause it to only run my external functions one time?

    #2
    Correct, one as you open the strategies list, second time as you select and apply a strategy and the third time when it's actually started. Have you tried moving the calculations to the OnBarUpdate instead?

    Comment


      #3
      I did that, but it still runs three times. Here's my code:

      Code:
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
      			//ToDay == 20090715
      			if (ToDay(Time[0]) == DayOfLastBar && ToTime(Time[0]) >= TimeOfLastBar)
      			{
      				Run();
      			} 
      			else 
      			{
      				//load every interval into an interval list
      				Interval interval = new Interval();
      				interval.SetDate(Time[0]);
      				interval.SetChange((Close[PredictBars] - Close[0]) / PredictBars);
      				interval.SetADX((ADX(14)[PredictBars] - ADX(14)[0]) / PredictBars);
      				interval.SetOBV(((OBV()[PredictBars] / 1000) - (OBV()[0] / 1000)) / PredictBars);
      				interval.SetStoch(((Stochastics(3, 9, 3).K[PredictBars] - Stochastics(3, 9, 3).D[0]) / PredictBars), ((Stochastics(3, 9, 3).K[PredictBars] - Stochastics(3, 9, 3).K[0]) / PredictBars));
      				interval.SetRSI((RSI(14, 3)[PredictBars] - RSI(14, 3)[0]) / PredictBars);
      				intervals.Add(interval);
      			}
              }
      EDIT: I just figured it out, now that I thought about it.

      Updated code:

      Code:
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
      			//ToDay == 20090715
      			if (ToDay(Time[0]) == DayOfLastBar && ToTime(Time[0]) == TimeOfLastBar)
      			{
      				Run();
      			} 
      			else 
      			{
      				//load every interval into an interval list
      				Interval interval = new Interval();
      				interval.SetDate(Time[0]);
      				interval.SetChange((Close[PredictBars] - Close[0]) / PredictBars);
      				interval.SetADX((ADX(14)[PredictBars] - ADX(14)[0]) / PredictBars);
      				interval.SetOBV(((OBV()[PredictBars] / 1000) - (OBV()[0] / 1000)) / PredictBars);
      				interval.SetStoch(((Stochastics(3, 9, 3).K[PredictBars] - Stochastics(3, 9, 3).D[0]) / PredictBars), ((Stochastics(3, 9, 3).K[PredictBars] - Stochastics(3, 9, 3).K[0]) / PredictBars));
      				interval.SetRSI((RSI(14, 3)[PredictBars] - RSI(14, 3)[0]) / PredictBars);
      				intervals.Add(interval);
      			}
              }
      Last edited by zwentz; 09-08-2009, 08:20 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      648 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      369 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      572 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      574 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X