GabyParticipant
Average
Hello,
I am seeking confirmation on the OPENTIME instruction.
I am trading the hourly timeframe and I do not want to open new trades after 21.45 or opening a new trades on Saturday or Sunday.
The code I used so far is:
TimeCond = OpenTime <= 214500
DayCond = OpenDayOfWeek >= 1 AND OpenDayOfWeek <= 5
IF TimeCond and DayCond THEN
cond1 = ……
IF NOT ONMARKET and cond1 THEN
BUY size PERPOINT AT MARKET
SET TARGET $PROFIT (35 * size)
SET STOP $LOSS (35 * size)
ENDIF
ENDIF
Problem = the program opened a trade on Monday at 22.00 – that is exactly what I was trying to avoid (at 22.00 the DFB spread is incredibly wide).
Doing some more digging I understood the OPENTIME instruction returns the opening time of the bar and it does not refer to the opening time of the trade as I mistakenly assumed. Therefore in order to avoid any order at 22.oo and at 23.00 I need to update the code above as follow:
TimeCond = OpenTime <= 204500 OR OpenTime >= 224500
In this way I expect the bar starting at 21.00 and the bar starting at 22.00 to be disregarded and therefore no trades will be taken at 22.00 or 23.00.
Is my interpretation correct?
Thanks very much, Gaby
You could use TIME, which is the closing time of candles.
GabyParticipant
Average
Thanks Roberto.
To exclude any trade between 22.00 and 24.00 in the hourly frame, would it be this the right code to use:
TimeCond = Time <= 214500 AND time >= 234500
Thanks, again. Gaby
Times used must be on your TF boundary. The HOURLY TF only closes/opens on a 0000 boundary, so they must be 220000 and 000000.
GabyParticipant
Average
Thanks Roberto – I made some backT to be sure.
On the HOURLY TF using Time 220000 on the dot it does not work as the program still took the trade at 220000 (could be too little time for the program to react).
But using 214500 it works… Also, the two limits should be in OR (I made a mistake before using AND) and the working code is:
TimeCond = Time <= 214500 OR time >= 234500
In this way the bar ending at 220000 is excluded (indeed is not <= 214500) and the program did not take the trade in back-T.
The second limit allows the bar ending at 240000 to be considered and a trade can be taken at 000001.
Opentime can be used too. But everything should be anticipated 1 hour in both limits. In that case the right code is:
TimeCond = OpenTime <= 204500 OR OpenTime >= 224500
Warm Regards