MazParticipant
Veteran
And here it is again with 24hour high (red) and 24-hour low (blue) lines. Pink is MA. White boxes are 7-8am tunnel
Useful on it’s own Maz, might you consider sharing as a stand-alone Indicator for the Library please?
Many Thanks
GraHal
Hi @grimweasel47 – I have some time to take a look as promised. Some clarifications please if you wouldn’t mind… Question: When you quote ATR above in your set of rules, are you referring to ATR-hourly or ATR daily? I would assume hourly as your period is 24 – but then could be daily too as that’s roughly a month. Question: With regard to rule #1 – if which candle touches MA? Signal or the following price action? When is it invalidated? What if the 8am doesn’t touch MA, nor break signal tunnel, but 9am does touch MA? To my mind, you actually have 3 seperate systems here. System 1: Breaks of a 7am period tunnel beyond psychological 00 levels, only if somthing touches some kind of MA System 2: Upward breaks of the signal candle if it’s the 24-hour high. Subsequently downward breaks of the signal candle if it’s the 24 hour low System 3: 24-hour tunnel breaks. Is there any reason why these 3 should be put together into one bot? Best, M
Hi Maz
Thanks for this and apologies for the late reply. Work today.
- ATR is 24 period on the H1 chart as you correctly surmised; same as the EMA as this =1 day.
- Wrt Rule 1 – this is the candle 0600-0700 UK time, so closes 1hr prior to LSE/FTSE open at 0800. As an OCO order we place long/short at next .00 levels. Whichever activates first cancels the other leg.
- The orders are left live in the market for 23hrs
- There are 3 possible trades:
- Long/Short OCO if the 6-7 candle touches the 24ema. – 15pips stoploss and 10pip TP
- Long only if price > 24ema, but only above the highest high of past 24 hrs (sometimes the signal candle IS that high!) – 1xATR SL and 2xATR TP (changed from 1.5TP)
- Short only if price <24ema, but only below the lowest low of past 24hrs (sometimes the signal candle IS that low!) – 1xATR SL and 2xATR TP (changed from 1.5TP)
Please let me know if you need further clarification and thanks VM for the help; much appreciated.
Hi Maz,
Did you manage to look at the code above? I’m trying to automate this strategy as work means I am missing some trades which is affecting overall system profitability.
Since the post above I have made a couple of changes that now yield better results:
- MA has changed to 50ema
- OCO order – both legs have 6 pip SL and 9 pips limit order (take profit)
- Changed ATR TP for ‘trend’ trade (ie non-OCO) to 1.5xATR
The system also works with above rules on EURJPY but when traded at 0800 UK time (so using high/low of 0700-0800 candle and associated next .00 levels above and below).
Any help appreciated.
I’m still having issues with this code on Igindex. I have adapted the strategy to trade GBPUSD on the close of the 0600-0700 candle (activationtime=070000)
The first part of my code sets the indicators. The strategy uses emas to determine the trend and then sets orders relative to the candle close above.
// --- indicators
ema = exponentialaverage[30](close)
ema2 = exponentialaverage[20](close)
ema3 = exponentialaverage[10](close)
EMAabove = ema2>ema
EMAbelow = ema2<ema
//change = ROC(exponentialaverage[a](close))
atr = averagetruerange[24]
hh = highest[3](high)
ll = lowest[3](low)
Filter = ema2-ema2[1]
Filter2 = ema3-ema3[1]
Long = Filter >0 and emaabove and filter2 <1.2 //and Filter2 <60
Short = Filter <0 and emabelow and Filter2 >-1.2 //and Filter2 >-60
As you can see the trend element should only open a trade above/below the highest high or lowest low from the previous 3 H1 bars.
The pending orders part is given below where Case2 is long and Case 3 is short:
//case 2 : If price is above the MA then only trade long BUT only above the highest high of the past 3 hrs
if close>ema and long and case = 0 then
case = 2
levelhi = hh[1]
endif
//case 3 : If price is below the MA then only trade short BUT only below the lowest low of the past 3 hrs
if close<ema and short and case = 0 then
case = 3
levello = ll[1]
endif
endif
if alreadytraded = 0 then
//money management
if case=1 then
StopLoss = 0.9*ATR
else
StopLoss = 0.9*atr
endif
Risk = riskpercent/100
//calculate contracts
equity = balance + StrategyProfit
maxrisk = round(equity*Risk)
size = max(minlot,abs(round((maxrisk/StopLoss)/PointValue)*pipsize))
//in all cases put pending orders on market
while case <> 0 and time <=LimitHour and daytrading=1 do
if levelhi>0 then
buy size contract at levelhi stop
endif
if levello>0 then
sellshort size contract at levello stop
endif
wend
endif
//set target and profit
if onmarket then
if case = 1 then
set target profit 1.1*ATR
set stop ploss StopLoss
endif
if case = 2 or case = 3 then
set target profit 2.1*ATR
set stop loss StopLoss
endif
endif
currentprofit = strategyprofit
The problem is that on the IgIndex feed this morning the trade activated at 070000 but NOT below the low (wick) of the previous candle (which was the lowest low of the previous 3hrs, highlighted in chart below) but at exactly the close price of the previous bar, which is incorrect as per the code above?
My question is, is this en error in the above code, or an issue with PRT on IgIndex?
Help appreciated as very frustrating.
USDCAD
defparam cumulateorders=false
// --- settings
balance = 10000 //balance of the strategy when activated the first time
minlot = 1 //minimum lot size for the current instrument (example: 1 for DAX)
riskpercent = 2 //risk percent per trade
activationtime = 100000 //Close time of the candle to activate the strategy
LimitHour = 170000 //limit time
if dayofweek=1 then //Monday
daytrading=0
endif
if dayofweek=2 then // Tuesday
daytrading=1
endif
if dayofweek=3 then // Wednesday
daytrading=1
endif
if dayofweek=4 then //Thursday
daytrading=0
endif
if dayofweek=5 then // Friday
daytrading=1
endif
// ---
Again. USDCAD. Activationtime=100000. Yet this morning at 00:00 11secs the system activated a trade when the trade time should be on the close of the 0900-1000 candle? Any ideas or help greatly appreciated!
if intradaybarindex=0 then
alreadytraded = 0
case = 0
levelhi = 0
levello = 0
endif
if onmarket or (onmarket[1] and not onmarket) or (currentprofit<>strategyprofit) then
alreadytraded = 1
endif
if time=activationtime then
// case 1 : If price candle touches MA (even wicks) then look at high or low of signal candle
if high>ema and low<ema then
case = 1
levelhi = CALL"#floor and ceil"[high,10.0,1]
levello = CALL"#floor and ceil"[low,10.0,-1]
endif
//case 2 : If price is above the MA then only trade long BUT only above the highest high of the past 24 hrs
if close>ema and long and case = 0 then
case = 2
levelhi = hh[1]
endif
Hard to say. Your code is incomplete.
Nicolas- any ideas on this? Again tonight two trades have activated at 00:00hrs on the IGindex platform when they shouldn’t have as activationtime=060000?? Why is it activating trades at 0000hrs all the time? Thanks.
Despair – thanks for the reply but as I had Nicolas code this for a £fee for me I didn’t want to post the entire code!