Execution price remains zero in this example (inside function Execute() of Strategy):
Is this a bug?
CODE:
var t = PlaceTrade(bars, TransactionType.Cover, OrderType.Market; WriteToDebugLog($"{t.ExecutionPrice}");
Is this a bug?
Rename
That’s because the execution price is not known until the following bar, or the following iteration of the Execute method.
See the example for Position > EntryPrice. Whoops, no example in the QuickRef, but we'll fix that.. here it is:
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript2 { public class EntryBarExample : UserStrategyBase { IndicatorBase _ma; public override void Initialize(BarHistory bars) { StartIndex = 20; _ma = SMA.Series(bars.Close, 20); PlotIndicatorLine(_ma); PlotStopsAndLimits(4); } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { if (bars.Close.CrossesOver(_ma, idx)) PlaceTrade(bars, TransactionType.Buy, OrderType.Market); } else { Position p = LastPosition; if (idx - p.EntryBar + 1 > 5) PlaceTrade(bars, TransactionType.Sell, OrderType.Market, 0, "Time-based"); else { double limit = p.EntryPrice * 1.05; // 5% profit target PlaceTrade(bars, TransactionType.Sell, OrderType.Limit, limit, "5%"); } } } } }
Your Response
Post
Edit Post
Login is required