- ago
Execution price remains zero in this example (inside function Execute() of Strategy):

CODE:
var t = PlaceTrade(bars, TransactionType.Cover, OrderType.Market; WriteToDebugLog($"{t.ExecutionPrice}");


Is this a bug?
0
1,100
2 Replies

Reply

Bookmark

Sort
Glitch8
 ( 10.62% )
- ago
#1
That’s because the execution price is not known until the following bar, or the following iteration of the Execute method.
2
Cone8
 ( 4.98% )
- ago
#2
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%");             }          }       }    } }
1

Reply

Bookmark

Sort