Hello. I was asked to bring this previous question up in a separate thread. When I run optimization tests, sometimes I will get average bars held as a negative#(impossible) or I will get a really big # like 500, but I'm only testing 5-minute bars with instructions to close the position at no later than 3:55pm ET so as not to hold any positions overnight. 500 bars would put me waaay beyond overnight and days(possibly weeks into the trade). TY.
Rename
A good way to understand what's happening is if we can duplicate what you're seeing - or at least see what you're seeing. (Post an image)
Alternatively, export the strategy to C# code (or a minimal one that demonstrates the issue), post it, and give us a symbol, date settings, and anything else that might be required to duplicate it.
Alternatively, export the strategy to C# code (or a minimal one that demonstrates the issue), post it, and give us a symbol, date settings, and anything else that might be required to duplicate it.
Here's the C# code taken right from WL:
Here's a screenshot of a large # of bars held:

Another for negative bars:

Hope this helps to determine the issue. TY.
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript2 { public class MyStrategy : UserStrategyBase { public MyStrategy() : base() { AddParameter("is Percentage", ParameterType.Double, 5, 1, 5, 1); AddParameter("Profit Target", ParameterType.Double, 1, 1, 5, 0.5); } public override void Initialize(BarHistory bars) { indicator1 = bars.Close; indicator2 = new ScaledInd(bars,new TimeSeriesIndicatorWrapper(bars.Close),HistoryScale.Daily); PlotIndicator(indicator2,new WLColor(0,0,0)); indicator2.MassageColors = true; PlotStopsAndLimits(3); StartIndex = 0; } public override void Execute(BarHistory bars, int idx) { int index = idx; Position foundPosition0 = FindOpenPosition(0); bool condition0; if (foundPosition0 == null) { condition0 = false; { if (index - 0 >= 0 && (indicator1[index] > indicator2[index - 0] * (1.0 + (Parameters[0].AsDouble / 100.0)))) { if(bars.DateTimes[index].GetTime() >= 930) { condition0 = true; } } } if (condition0) { _transaction = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, 0, "Buy At Market (1)"); } } else { condition0 = false; { if(bars.DateTimes[index].GetTime() >= 1559) { condition0 = true; } } if (condition0) { Backtester.CancelationCode = 122; ClosePosition(foundPosition0, OrderType.Market, 0, "Sell At Market (1)"); } condition0 = false; { condition0 = true; } if (condition0) { Backtester.CancelationCode = 122; value = (Parameters[1].AsDouble / 100.0) + 1.0; ClosePosition(foundPosition0, OrderType.Limit, foundPosition0.EntryPrice * value, "Sell at 1% profit target"); } } } public override void NewWFOInterval(BarHistory bars) { indicator1 = bars.Close; indicator2 = new ScaledInd(bars,new TimeSeriesIndicatorWrapper(bars.Close),HistoryScale.Daily); } private TimeSeries indicator1; private IndicatorBase indicator2; private double value; private Transaction _transaction; } }
Here's a screenshot of a large # of bars held:
Another for negative bars:
Hope this helps to determine the issue. TY.
Thanks for providing the info. It looks like ScaleInd is the culprit here, it's causing the instability in the parallel optimizations. I'm working on it at the moment. For now, if you use the Exhaustive Non-Parallel Optimizer it should be ok.
OK, this was a nasty one but the bug looks to be squashed for Build 19.
Your Response
Post
Edit Post
Login is required