The code :
Strategy Setting Image :
How can i debug this :
Thx.
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript1 { public class My : UserStrategyBase { private static List<BarHistory> Buys = new List<BarHistory>(); public override void Initialize(BarHistory bars) { StartIndex = 101; _Mom = new Momentum(bars.Close, 100); bars.Cache["Momentum"] = _Mom; } public override void PreExecute(DateTime dt, List<BarHistory> participants) { foreach (BarHistory bh in participants) { Momentum _M = (Momentum)bh.Cache["Momentum"]; int idx = GetCurrentIndex(bh); double MomVal = _Mom[idx]; bh.UserData = MomVal; } participants.Sort((a, b) => a.UserDataAsDouble.CompareTo(b.UserDataAsDouble)); Buys.Clear(); for (int n = 0; n <= 19; n++) { if (n >= participants.Count) break; Buys.Add(participants[n]); } } public override void Execute(BarHistory bars, int idx) { bool inBuyList = Buys.Contains(bars); if (!HasOpenPosition(bars, PositionType.Long)) { if (inBuyList) PlaceTrade(bars, TransactionType.Buy, OrderType.Market); } else { if (!inBuyList) PlaceTrade(bars, TransactionType.Sell, OrderType.Market); } } private Momentum _Mom; } }
Strategy Setting Image :
How can i debug this :
Thx.
Rename
A. Most likely, you can find more details of the exception in the Log Viewer (Tools menu).
B. Since the strategy appears to work, wrapping the offending line in a try/catch block could help catch errors and output to the Debug log.
C. WriteToDebugLog is the built-in way to print out the various debug info.
B. Since the strategy appears to work, wrapping the offending line in a try/catch block could help catch errors and output to the Debug log.
C. WriteToDebugLog is the built-in way to print out the various debug info.
QUOTE:Yes, I would add some WriteToDebugLog lines in there.
C. WriteToDebugLog is the built-in way to print out the various debug info.
What concerns me is the idx value for _Mom[idx] below?
CODE:Is that idx value valid? I'm guessing it isn't. But if you print its value out with WriteToDebugLog, you could verify it's wrong. Remember idx values between 0 thru 100 are not valid arguments and _Mom[idx] will return Double.NaN. But WriteToDebugLog can confirm that; otherwise, we are just guessing.
int idx = GetCurrentIndex(bh); double MomVal = _Mom[idx];
Ok, Thx
And, have Backtest result question
Every execute "Run Backtest", the results vary a lot
I don't edit code.
Thx
And, have Backtest result question
Every execute "Run Backtest", the results vary a lot
I don't edit code.
Thx
It's answered in the FAQ under Basic Usage, third question down:
https://www.wealth-lab.com/Support/Faq
https://www.wealth-lab.com/Support/Faq
QUOTE:
It's answered in the FAQ under Basic Usage, third question down:
https://www.wealth-lab.com/Support/Faq
Maybe you could add extra checkbox when downloading WL7? – “I confirm that I know why backtesting results may differ even if I changed nothing”.
Btw data scientist use random seed for this. You set it and it lets you reproduce the same result even if using randomization.
But I like this variety of results – it’s more realistic, one more small step away from curve-fitting.
I guess this is something already in your backlog, you could add links to the exact part of the page – something with # symbol, I guess (I don’t know how it works).
Your Response
Post
Edit Post
Login is required