Oil 10min “hammernegated” pattern strategy
I refer to the strategy in the above link. It seems to be working well in recent months. But can someone please do a 200k bars test for us so so the community can further improve the code?
Credit to Francesco, the true legend!
I converted it to MTF (1-minute default TF):
// HammerNegated OIL 10min mtf
//
// https://www.prorealcode.com/prorealtime-trading-strategies/oil-10min-hammernegated-pattern-strategy/
// https://www.prorealcode.com/topic/francescos-hammernegated-strategy/
//
defparam cumulateorders = false
timeframe(10 minute,updateonclose)
ONCE p = 36 //36 4
ONCE t = 0 //0 0
av1 = average[2,t](close) //2 2
av2 = average[2,t](close) //2 15
av3 = average[50,t](close) //50 30
ONCE x = 0.53 //0.53 0.50
bull = close> av1 and close >av2 and close > av3
bear = close <av1 and close <av2 and close < av3
ONCE n = 150 //150 95
ONCE m = 30 //30 85
hammerup = min(open[1],close[1]) > high[1]-(high[1]-low[1]) / 3//and timeok
hammerupnegated = max(open,close) < min(open[1],close[1]) and abs(open-close) / (high-low) > x
cs = hammerup and hammerupnegated and bear
hammerdown = max(open[1],close[1]) < low[1]+(high[1]-low[1]) / 3 //and timeok
hammerdownnegated = min(open,close) > max(open[1],close[1]) and abs(open-close) / (high-low) > x
cl = hammerdown and hammerdownnegated and bull
timeframe(default)
if cs AND Not OnMarket then
sellshort 1 contract at market
set target pprofit n*averagetruerange[p]
set stop ploss m*averagetruerange[p]
endif
if cl AND Not OnMarket then
buy 1 contract at market
set target pprofit n*averagetruerange[p]
set stop ploss m*averagetruerange[p]
endif
//TRAILING STOP
ONCE TGL = 27 //27 30
ONCE TGS = 27 //27 18
if not onmarket then
MAXPRICE = 0
MINPRICE = close
PREZZOUSCITA = 0
ENDIF
if longonmarket then
MAXPRICE = MAX(MAXPRICE,close)
if MAXPRICE-tradeprice(1)>=TGL*pointsize then
PREZZOUSCITA = MAXPRICE-TGL*pointsize
ENDIF
ENDIF
if shortonmarket then
MINPRICE = MIN(MINPRICE,close)
if tradeprice(1)-MINPRICE>=TGS*pointsize then
PREZZOUSCITA = MINPRICE+TGS*pointsize
ENDIF
ENDIF
if onmarket and PREZZOUSCITA>0 then
EXITSHORT AT PREZZOUSCITA STOP
SELL AT PREZZOUSCITA STOP
ENDIF
Thank you robertogozzi for your modification on the code. Interesting result, I have several questions regarding your version of this strategy. For the sake of tidiness and legibility I make my questions in point form:
- whats is the difference between av1 and av2 (line 10 and 11) ( Is it a typo or sth else?)
- would it make more sense for “hammerupnegated = max(open,close) <= min(open[1],close[1]) “(line 19 and same for line 22) as i guess the open of the current bar should always equal the close of previous bar ?(except gaps after session break)
- Do the parameters like p,t,x,m,n c come from optimization? (any WF test done on these parameters?)
- Can you or any others help to test it for 200k bars?
- Have you tried other type of trailing stop or exit strategies?
Meanwhile, I am also interested on the original code’s performance on 15min TF for 200k bar. Would you mind posting the backtest result here for my reference?
Cheers
I can see that very often the profit is secured after hours the position is opened. It somehow implies that “hammer negated” is not a very precise/ accurate signal, otherwise the market would always trend in direction favourable to the position.
Would you mind sharing your thoughts on this strategy?
Thank you @robertogozzi! I found that the original code written by @Francesco also works pretty well on DJI
Can robertogozzi please help the original code on DJI on 15min TF for 200k bar and share with us the results!
Many thanks!
Performance for DJI-15min with 2.4 spread.
IMO it works better if TGL or TGS are above 40 as the indices price is around 4times of that of oil.
Hola Roberto. He copiado el código del Hammarnegated pero no me funciona.
Hay algún fallo o algo que haya que hacer? yo hice un copy paste. Gracias.
Hola Roberto. He copiado el código del Hammarnegated pero no me funciona.
Hay algún fallo o algo que haya que hacer? yo hice un copy paste. Gracias.
Please speak English on the english forum.
If it does absolutely nothing, then there must be an error in the backtest periods.
Doesn’t it report any error?
It works perfectly if copied as is. Should you have also copied line numbers please remove them.
I attach the .ITF file to be imported.
PaulParticipant
Master
interesting results, but I think there’s a point to take in consideration.
Although very high win-chance and nice results, there’s no fixed stoploss.
The highest MAE, is about the same as a 2.5-3% stoploss. (1 minute 200k bars us crude)
So perhaps it’s good to have a fixed % set and then you get out. 3% is big seeing a market running against your trade which can happen apparently.
The shorter the timeframe, the lower the stoploss should be?
If switched that code to 10min, it goes up al the way to 11,75% loss on a trade and still a win-chance of more then 90%.
pp=(positionperf*100)
sl=2.00 //stoploss in %
if pp < -sl then
sell at market
exitshort at market
endif
graph pp
Thanks Paul for your advice.
It certainly makes me feel more comfortable by applying a fixed percentage stoploss, and of course, the trade off is a little bit lower win rate and profit.
The next thing that comes to my mind is increasing the bet size after losses, since the maximum consecutive loser is just 2 or 3. I know each trade occur independently, however, statistically speaking, i think it maybe worth doing so. What do you think?
PaulParticipant
Master
Hi fatlung
In my opinion it’s not a good strategy, only maybe if you have 1000 of trades to test.
Example is an other strategy, nice run up and then after unexpected consecutive losses it gained momentum again.
In the backtest it never had so many consecutive losses. To take those losses is bad enough without doubling down.