Hi,
I am writing CSV file(s) (using the Transaction object) holding all my backtest and live transactions for my strategy. I'm not really interested in the backtest values since they are shown in the backtest results panel but was wondering why am I not getting the exact entry and exit prices from the Transaction object vs. the BackTest Results. I am definitely interested in recording my live trades. Let me show you an example.
My exit price is highlighted in red, I get 21.82 from the Transaction object. I'm using transaction.ExecutionPriceDisplay. However, the backtest results show 21.185 (in green), which is the correct value. And the difference in these values changes the profit.
Why is there a difference in these values?
Is something not set up correctly on my end?
Thanks,
Mike
I am writing CSV file(s) (using the Transaction object) holding all my backtest and live transactions for my strategy. I'm not really interested in the backtest values since they are shown in the backtest results panel but was wondering why am I not getting the exact entry and exit prices from the Transaction object vs. the BackTest Results. I am definitely interested in recording my live trades. Let me show you an example.
My exit price is highlighted in red, I get 21.82 from the Transaction object. I'm using transaction.ExecutionPriceDisplay. However, the backtest results show 21.185 (in green), which is the correct value. And the difference in these values changes the profit.
Why is there a difference in these values?
Is something not set up correctly on my end?
Thanks,
Mike
Rename
It's because you're "using transaction.ExecutionPriceDisplay."
It's the price to display, not full precision.
The display price conforms to the number decimals places for the market, which is 2 in the case of U.S. stocks.
It's the price to display, not full precision.
The display price conforms to the number decimals places for the market, which is 2 in the case of U.S. stocks.
Is there anyway to get the full precision?
Transaction.ExecutionPrice
It only shows two decimal places.
Can that be changed to 3?
Can that be changed to 3?
It's not for me.
If you are writing out Transactions that have been submitted by the broker then it's likely the price was rounded down to 2 decimals unless you have fractional shares enabled in settings, and the broker supports fractional shares.
If you are writing out Transactions that have been submitted by the broker then it's likely the price was rounded down to 2 decimals unless you have fractional shares enabled in settings, and the broker supports fractional shares.
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) { } //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 (idx == bars.Count - 3) { t = PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, bars.Close[idx] - 0.001); } } public override void BacktestComplete() { WriteToDebugLog(t.ExecutionPrice.ToString("N5")); } //declare private variables below private Transaction t; } }
Thanks.
Your Response
Post
Edit Post
Login is required