Hi everyone:
See attached from an AUDNZD currency chart.
The buy price, which is “TradePrice”, is graphed at 1.04910; the blue arrows indicating the entry show it at over 1.0520. When I run the backtest, I do NOT have the “Spread” option checked (enabled).
It’s similar for the sell as well.
Here is the relevant code. This is the only place in the code where the value for theBuyTradePrice is set and also the only place in the code where the values are graphed:
BUY 1 SHARES AT MARKET
theBuyTradePrice = TradePrice
GRAPHONPRICE theBuyTradePrice as "theBuyTradePrice"
So why is there such a discrepancy?
Thank you.
Code is read at Close, and orders are launched at next open, it means that at the time when the code is read, we have no hint of what would be the exact open price, you’ll have to wait for the order to be launched for that.. (next bar!).
thanked this post
I understand orders are executed at the next bar.
So then:
1) the “tradeprice” should be the same “open” price of the next bar if the orders are executed on the next open, correct?
2) to get the actual price, we have to set a flag to let us know when the next bar comes around. Then, when that next bar does come around, we can do “tradeprice” to get the exact price from the order in the code executed from the previous bar’s close?
3) Or is there an easier/better way to do #2 above?
THank you.
1.yes
2.yes
3.not really, you could try with MTF instruction to get the tradeprice faster with a lower timeframe.