- ago
I read the FAQ and other discussion for the topic. I still didn't find the answer.

I ignore 'Retain NSF positions' for back test, and set Weight for each buy, and still get different results for each run, NSF position count is 0 in metrics report.

What should I do in this case ? How can I follow strategy signals ?

1. If I followed my strategy yesterday, and bought 'AMZN' this morning at Open;
2. I ran it again in the evening today, and 'AMZN' doesn't show up in my positions
3. Should I sell 'AMZN' or keep it ? or it will show up again when I run the strategy tomorrow ?

thanks

0
159
Solved
7 Replies

Reply

Bookmark

Sort
Glitch8
 ( 10.92% )
- ago
#1
I can’t imagine how that’s happening. Can you share the strategy here or via email support@wealth-lab.com?
0
- ago
#2
To share the strategy by email, go to Strategies, highlight it and choose "Export Strategies".
0
Cone8
 ( 23.78% )
- ago
#3
"Just guessing" explanations:

1. You ran the strategy using a different scale.
For example, a Weekly scale last weekend triggered the signal to buy yesterday. Daily bars doesn't have the same trade.

2. Something else in the data is different.
Example, the data wasn't updated before, or isn't updating now.

3. The strategy has a random or peeking element.
(That's the first thing we'd look for.)
0
- ago
#4
code modified from 'one percent per week' from sample:
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; namespace WealthScript5 {    public class OnePercentV3 : UserStrategyBase    {       public override void Initialize(BarHistory bars)       {          rsi = new RSI(bars.Close, 5);          sma50 = new SMA(bars.Close, 3);          hi52 = new Highest(bars.Close, 30);          var external = GetHistory(bars, "^GSPC");          idxSma = new EMA(external.Close, 20);          StartIndex = 246;       }       public override void Execute(BarHistory bars, int idx)       {          bool NextBarIsStartOfWeek = _lastBarofWeek == idx;          bool NextBarIsLastDayOfWeek = bars.TomorrowIsLastTradingDayOfWeek(idx);          if (NextBarIsLastDayOfWeek)             _lastBarofWeek = idx + 1;          if (idx - 1 == _lastBarofWeek)             SetBackgroundColor(bars, idx, WLColor.Silver.SetAlpha(32));          if (NextBarIsStartOfWeek)          {             mondayOpen = bars.Open[idx + 1]; //sessionOpenPrice;             mondayClose = bars.Close[idx + 1]; //sessionOpenPrice;             tradedThisWeek = false;          }          if (HasOpenPosition(bars, PositionType.Long))          {             var p = LastPosition;             double target = LastOpenPosition.EntryPrice;             if (LastOpenPosition.ProfitPctAsOf(idx) > -0.5)                target = target * 1.01;             Backtester.CancelationCode = 1;             CloseAtTrailingStop(p, TrailingStopType.PercentC, 12, "Trailing Stop");             Backtester.CancelationCode = 642;             PlaceTrade(bars, TransactionType.Sell, OrderType.Limit, target, $"Sell {target.ToString("00.##")}");             Backtester.CancelationCode = 640;             if (idx < bars.Count - 1)             {                if (NextBarIsLastDayOfWeek)                   PlaceTrade(bars, TransactionType.Sell, OrderType.MarketClose, 0, "Sell Friday");             }             else             {                //last bar: if today is the last trading day of the week, signal MOC for the open position                if (bars.TomorrowIsLastTradingDayOfWeek(idx))                   PlaceTrade(bars, TransactionType.Sell, OrderType.MarketClose, 0, "Sell Exit");             }          }          else          {             if (!Double.IsNaN(mondayOpen) && !tradedThisWeek && !NextBarIsStartOfWeek                && bars.Close[idx] > sma50[idx] * 0.92                ) // TodayIsMonday)             {                double mult = 0.99;                //   PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, mondayOpen * mult, "Buy");                if (mondayClose < mondayOpen * mult) //&& sma50[idx] > sma50[idx-1] )                {                   var trade = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, "Buy");                   trade.Weight = -rsi[idx];                   tradedThisWeek = true;                }                // not sure if it is good                if (NextBarIsLastDayOfWeek)                {                   Backtester.CancelationCode = 642;                   PlaceTrade(bars, TransactionType.Sell, OrderType.MarketClose, 0, "Sell SameDay");                }             }          }       }       //same bar exit       public override void AssignAutoStopTargetPrices(Transaction t, double basisPrice, double executionPrice)       {          //t.AutoProfitTargetPrice = executionPrice * 1.01;          tradedThisWeek = true;       }       //declare private variables below       private double mondayOpen = Double.NaN;       private double mondayClose = Double.NaN;       bool tradedThisWeek = false;       int _lastBarofWeek = -1;       private IndicatorBase rsi;       private IndicatorBase sma50;       IndicatorBase hi52;       IndicatorBase idxSma;    } }
0
- ago
#5
Test settings: (I am still getting different results: APR, WLScore etc)

0
Glitch8
 ( 10.92% )
- ago
#6
You're getting different results because of the different exits, you are issuing a CloseAtTrailingStop at line 47 and a sell at Limit on line 50. In cases where both of those exits could be hit, WL8 chooses one randomly.

You can choose to favor either the Stop or Limit exit in Backtest Preferences, Exit Prioritization. The default is Neutral (Random).
1
Best Answer
- ago
#7
Great, problem solved. thanks
0

Reply

Bookmark

Sort