- ago
Run the following code in 5-minute interval: once with VXX as the default 'Single Symbol', and once as "SPY".
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript3 { public class MyStrategy : UserStrategyBase {       BarHistory barsToUse = null; public override void Initialize(BarHistory bars) {          barsToUse = GetHistory(bars, "VXX");          StartIndex = 1; } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int bar) {          int barTime = bars.DateTimes[bar].Hour * 100 + bars.DateTimes[bar].Minute;          Position position = GetPositionsAllSymbols(true).Count > 0 ? GetPositionsAllSymbols(true)[0] : null; if (position == null && bar == StartIndex) {             PlaceTrade(barsToUse, TransactionType.Buy, OrderType.Market); } else { if(barTime >= 1555 && position != null && position.IsOpen)             {                Transaction transaction = PlaceTrade(position.Bars, TransactionType.Sell, OrderType.Market);                if(bars.Symbol != "VXX")                {                   transaction.Quantity = position.Quantity -1;                }                                } } } //declare private variables below } }

It should close the position when "VXX" is the bar's symbol, but leave the position open with one share if the symbol is 'SPY'.

Next, create a MetaStrategy and apply the same strategy twice: once with VXX and once with SPY as the symbol to run on. You will notice that for SPY, the entire position remains open instead of just one share.

Expected: MetaStrategy to work as running the strategy standalone.


0
205
0 Replies

Reply

Bookmark

Sort
Currently there are no replies yet. Please check back later.