Dear all, I have been listening to a class by Rob Hofmann yesterday and I though it was worth try to code it.
The strategy is based on the follwoing principles
Should be applicable to many assets and many timeframes.
I post the example of OIL 1hr TF.
Looking forward for your comments
Best
Francesco
///Rob Hoffman idea of trend following mechanism
//crude oil 1hr spread 1
DEFPARAM cumulateorders = FALSE
///indicators used to define market trend
average1 = average[5](close)
average2 = average[20](close)
average3 = average[50](close)
average4 = average[100](close)
atr = averagetruerange[14]
///optimized variable
ml = 9// dynamic factors for profit and stops
nl = 4
ms = 6
ns = 4
c = 2.8// factor used to calibrate the shape of the hammer candle used as a signal
gradient = 1 // slope of moving averages
////defining the bull trend conditions
bulltrend1 = average1-average1[2] >gradient and average1< close
bulltrend2 = average1-average2[2] >gradient and average2< close
bulltrend3 = average3-average3[2] >gradient and average3< close
bulltrend4 = average4-average4[2] >gradient and average4 < close
bulltrend = bulltrend1 and bulltrend2 and bulltrend3 and bulltrend4
/////defining the bear trend conditions
beartrend1 = average1-average1[2] <-gradient and close < average1
beartrend2 = average1-average2[2] <-gradient and close < average2
beartrend3 = average3-average3[2] <-gradient and close < average3
beartrend4 = average4-average4[2] <-gradient and close < average4
beartrend = beartrend1 and beartrend2 and beartrend3 and beartrend4
///defining the signal candles
hammerup = abs(open-close)< (High - low)/2 and close> high -(high-low)/c and open > high - (high-low)/c //
hammerdown = abs(open-close)< (High - low)/2 and close< low +(high-low)/c and open < low + (high-low)/c //
///defining the level for the stop orders
if hammerdown and bulltrend then
levelup = high-(high-low)/2
endif
if hammerup and beartrend then
leveldown =low + (high-low)/2
endif
///trading conditions
if bulltrend then
buy 1 contract at levelup stop
endif
if beartrend then
sellshort 1 contract at leveldown stop
endif
///dynamic profit and stops
if longonmarket then
set target pprofit ml*atr
set stop ploss nl*atr
endif
if shortonmarket then
set target pprofit ms*atr
set stop ploss ns*atr
endif
You must be logged in to post a comment.
This strategy was posted 2 years ago. I tested it today and it works perfect with the new data. I think it deserves attention!
Ciao Francesco, ti scrivo per un aiuto a proposito della strategia di Hofmann che anch'io ho conosciuto tempo fa. Ho visto che su Oil funziona bene anche se non sono riuscito ad impostarlo con lotto 0.1 (come permette di fare IG). POi ho notato che ci sono molti stop e pensavo di trovare il modo di ottimizzarlo. Ma il problema che non riesco a risolvere riguarda gli altri strumenti (forex ad azionario) perchè quando lancio il backtest non mi da operazioni. Credo che sia un problema legato alla parte al "gradient".Potresti suggerirmi cosa modificare nel codice per farlo funzionare su azionario e forex. Grazie Rosario