The strategy I am testing longs/shorts at the open. The data it is operating on is daily.
I also apply stop losses based on previous day ranges.
Now I want to square off the positions at the end of day. I have looked into using TimeNum() function to do that but it won't work in my case since the data is day ranged like 1/1/18, 2/2/18 and not intraday.
So in such a case how should I proceed with closing at the end of the day all open positions?
I see. This seems to work. I have an another related question since this piece of code brough it to my mind and I don't want to waste an another thread on it.
SetTradeDelays(0, 0, 0, 0)
// code to compute Buy and Short signals
//...
//...
Sell = Ref(Buy, 0); // only sell it back if already long
SellPrice = Close;
Cover = Ref(Short, 0);
CoverPrice = Close; // only buy it back if already short
// Setting Stop Loss
StopAmount = Ref(Close, -1);
StopAmount = Max(TickSize, StopAmount);
IsLong = Ref(Buy, 0); // since entering position on the same bar using ref 0, correct?
ApplyStop(stopTypeLoss, stopModePoint, IIf(IsLong, BuyPrice - StopAmount, StopAmount - BuyPrice), 1);
I am using Sell=Ref(Buy, 0) because I think it will only Sell when I am already Long rather than simply using Sell=True which would have caused it to Sell even when not in position.
Hope my logic is correct?