//-------------------------------------------------------------------------
// END OF DAY - YEN
// www.doctrading.fr
Defparam cumulateorders = false
// TAILLE DES POSITIONS
n = 2
daysForbiddenEntry = OpenDayOfWeek = 5 or opendayofweek = 5 or OpenDayOfWeek = 4 or opendayofweek = 4 or OpenDayOfWeek = 3 or opendayofweek = 3 or OpenDayOfWeek = 2 or opendayofweek = 2 or OpenDayOfWeek = 1 or opendayofweek = 1
ratio = 0.6
// HORAIRES
startTime = 210000
endTime = 231500
exitLongTime = 03000
exitShortTime = 03000
// STOP LOSS & TAKE PROFIT (%)
SL = 0.7
TP = 1.2
Period = 8
// BOUGIE REFERENCE à StartTime
if time = startTime THEN
amplitude = highest[Period](high) - lowest[Period](low)
ouverture = close
endif
// LONGS & SHORTS : every day except Fridays
// entre StartTime et EndTime
if time >= startTime and time <= endTime and not daysForbiddenEntry then
buy n shares at ouverture - amplitude*ratio limit
sellshort n shares at ouverture + amplitude*ratio limit
endif
// Stop Loss & Take Profit
set stop %loss SL
set target %profit TP
// Exit Time
if time = exitLongTime then
sell at market
endif
if time = exitShortTime then
exitshort at market
endif
I have been playing around with @Doctrading ‘s end of day Yen M15 strategy (code above is for Sunday only trades), which I find works quite well when initial positions are opened and then hit take profit levels. Performance then tails off a little when new positions are opened and run through to 0030 when all positions are closed. When the strategy goes live each day, it sets limit orders higher (sell) than the opening level and lower (buy). Is there a way to effectively add an OCO rule so that once a buy order is opened (for example), the corresponding sell order is cancelled….so, if a 1.09 USD/JPY buy order is filled, the corresponding 1.10 sell order would be cancelled?
Thanks in advance.
This will limit your strategy to One Trade per Day (using the variable OTD):
//-------------------------------------------------------------------------
// END OF DAY - YEN
// www.doctrading.fr
Defparam cumulateorders = false
// TAILLE DES POSITIONS
n = 2
daysForbiddenEntry = OpenDayOfWeek = 5 or opendayofweek = 5 or OpenDayOfWeek = 4 or opendayofweek = 4 or OpenDayOfWeek = 3 or opendayofweek = 3 or OpenDayOfWeek = 2 or opendayofweek = 2 or OpenDayOfWeek = 1 or opendayofweek = 1
OTD = (Barindex - TradeIndex(1) > IntradayBarIndex)
ratio = 0.6
// HORAIRES
startTime = 210000
endTime = 231500
exitLongTime = 03000
exitShortTime = 03000
// STOP LOSS & TAKE PROFIT (%)
SL = 0.7
TP = 1.2
Period = 8
// BOUGIE REFERENCE à StartTime
if time = startTime THEN
amplitude = highest[Period](high) - lowest[Period](low)
ouverture = close
endif
// LONGS & SHORTS : every day except Fridays
// entre StartTime et EndTime
if time >= startTime and time <= endTime and not daysForbiddenEntry and OTD then
buy n shares at ouverture - amplitude*ratio limit
sellshort n shares at ouverture + amplitude*ratio limit
endif
// Stop Loss & Take Profit
set stop %loss SL
set target %profit TP
// Exit Time
if time = exitLongTime then
sell at market
endif
if time = exitShortTime then
exitshort at market
endif
I like to simplify so think this would work but not tested it.. Logic seems OK though… I used similar for only trading once between certain times of day which worked very well…
This simply resets at start of the day after each day:
Once StartT=000000
once EndT=000001
td1 = 1 AND OpenDayOfWeek = 1 AND OpenTime >= startT AND OpenTime <= endT //Monday
td2 = 1 AND OpenDayOfWeek = 2 AND OpenTime >= startT AND OpenTime <= endT //Tuesday
td3 = 1 AND OpenDayOfWeek = 3 AND OpenTime >= startT AND OpenTime <= endT //Wednesday
td4 = 1 AND OpenDayOfWeek = 4 AND OpenTime >= startT AND OpenTime <= endT //Thursday
td5 = 1 AND OpenDayOfWeek = 5 AND OpenTime >= startT AND OpenTime <= EndT //Friday
tdcond= td1 or td2 or td3 or td4 or td5
If tdcond then
myday=dayofweek
endif
If not onmarket and myday=dayofweek and (Your criteria)then
buy myamount perpoint at market
myday=dayofweek+1
endif
If not onmarket and myday=dayofweek and (Your criteria) then
sellshort myamount perpoint at market
myday=dayofweek+1
endif
Obviously putting in your own buy codes and criteria etc… I’ve not played around with the end time but hopefully it would work..
Hope it helps..