Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Stopping a strategy for running thrice in backtesting
Collapse
X
-
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?Tags: None
-
I did that, but it still runs three times. Here's my code:
EDIT: I just figured it out, now that I thought about it.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); } }
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
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
369 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
108 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
572 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
574 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment