Hello,
Below script is written to give Buy or Short signals based on some condition and exit all positions before the market closes (say at 3:25 PM) with exit price as price at 3:25 PM.
ExitAllPositionsTime = 152500;
Buy = …some conditions… //Buy when condition is true
Sell = TimeNum() >= ExitAllPositionsTime; //Exit at 3:25 PM before market closure
Short = …some conditions… //Short when condition is true
Cover = TimeNum() >= ExitAllPositionsTime; //Exit at 3:25 PM before market closure
BuyPrice= ShortPrice = Open; //Open Price of candle
SellPrice = CoverPrice = GetRTData(“Last”); //Price at Exit i.e. at 3:25 PM
But when I backtest it, I am facing the following issues:
-
Exit is happening on the next day candle.
-
Exit price is taken as the next day candle closure price.
Can someone help?