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 argusthome, Yesterday, 10:06 AM
|
0 responses
20 views
0 likes
|
Last Post
by argusthome
Yesterday, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
18 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
14 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
9 views
0 likes
|
Last Post
|
||
|
Started by Mindset, 02-28-2026, 06:16 AM
|
0 responses
40 views
0 likes
|
Last Post
by Mindset
02-28-2026, 06:16 AM
|

Comment