Hi Everyone. Consider below Code on 1 minute Bar interval:
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.2f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
SetTradeDelays( 0,0,0,0 );
BuyPrice= Close;
SellPrice= Close;
Buy = Cross( MACD(), SIGNAL() );
Sell = Cross( Signal(), MACD() );
if (LastValue(Buy) == True)
{
_TRACE("Buy Price: " + BuyPrice); // Print Buy Price
}
/************************ Plot Buy/Sell Arrows ******************************/
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
When i Backtest above Code in Analysis window on 1 minute Bar interval for date 6/24/2020, i get following output:
It shows a long trade entered on 6/24/2020 at 9:18 AM at Buy Price of 138.5.
But when i run Bar Replay on same date and time (i.e 6/24/2020 at 9:18 AM) on 1 minute bar and step interval as 1 second i get following trace output:
Here, I get several Buy Signals with First Buy signal at Buy Price of 138.25. I have seperate code to remove repeated Buy signals, so i actually enter only one long trade (during realtime trading) at first Buy signal i.e 138.25
As we can see, there is difference between actual Buy Price (in realtime trading) and Buy Price shown in Backtest Result. I understand that Backtest result will show Close Price of the Bar as Buy Price. But, it is not the actual Buy Price in realtime trading as evident from Bar Replay. Actual Buy Price is 138.25 whereas Buy price shown in Backtest result is 138.50. How can i get actual Buy Price in Backtest Result?