Hi, I want to see if there are specific times that are better to trade in a specific stock. I have tried the code at a 5min chart. The optmization for buy time work as it should but I dont get the code to do what I want when selling. If i try a fixed time for selling the code works as it should but running the code, trying to optimize the selling time, it always sells at 17.30 (FLATAFTER = 173000) Can someone please help me with this problem! The .itf is also attached.
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the "FLATBEFORE" time.
DEFPARAM FLATBEFORE = 090000
// Cancel all pending orders and close all positions at the "FLATAFTER" time
DEFPARAM FLATAFTER = 173000
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
buytime = t*10000 + (M1*100)
selltime = (buytime + (M2*100)) //Not ok! The system don´t sell at the assigned time
//selltime = buytime + 500 //Not ok! The system don´t sell at the assigned time
//selltime = 160000 //OK! The system sell at the assigned time
// Conditions to enter long positions
//Check trend in 1day chart
timeframe(1 day, updateonclose)
ma = average[70]
longtrend1 = close > ma
//Set time frame to default
timeframe(default)
indicator1 = adx[14]
momentum1 = indicator1 > mom and indicator1 < mom1
IF longtrend1 AND momentum1 AND not daysForbiddenEntry THEN
if time=buytime then
BUY 1 CONTRACT AT MARKET
ENDIF
endif
// Stops and targets
SET STOP %LOSS 0.15
// Conditions to exit long positions
IF longonmarket then
if time=selltime THEN
sell 1 CONTRACT AT MARKET
ENDIF
endif
Hello Seatrout
The function TIME is a specific and fixed one assigned by PRT, its format “HHmmnn” cannot be changed nor altered or incremented what so ever.
furthermore be careful to write the correct Numbers of zero, its seems that your “buytime = t*10000 + …” misses a zero .
Be simple in your coding, with the DAX, one Supertrend for the long and another one for the shorts is far away the best 🙂
Then, the market operators and their spychology are not the same along the day, statistically you have one setting from 090200 to 095500, one from 100200 to 124500 and the last from 141500 to 163000. Black hours at lunch time (124500 to 141500).
Hope this help. Good luck.