Francesco’s Hammernegated strategy

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #101538 quote
    25sonalgo
    Participant
    New

    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?

    #101539 quote
    25sonalgo
    Participant
    New

    Credit to Francesco, the true legend!

    #101616 quote
    robertogozzi
    Moderator
    Master

    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
    #101634 quote
    solar
    Participant
    Senior

    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:

    1. whats is the difference between  av1 and av2 (line 10 and 11) ( Is it a typo or sth else?)
    2. 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)
    3. Do the parameters like p,t,x,m,n c come from optimization? (any WF test done on these parameters?)
    4. Can you or any others help to test it for 200k bars?
    5. 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

    #101638 quote
    robertogozzi
    Moderator
    Master
    1. it’s not a typo, it’s the optimization tool that said it was the same (I kept all the three not to alter the original logic)
    2. I kept the same code as the original version, but you can try different settings
    3. Yes, I optimized all variables due to the fact that I was using a MTF approach, which is different from using a single TF
    4. Yes, I attach both 100k and 200k performance on the original code, but with a 15-minute TF as you asked (oddly enough there’s no difference in performance and dates on CL, while there are on DAX or Eur/Usd). I never use 200k tests!
    5. No, I just kept the original code, just changing values or replacing some constants with variables. I also reintroduced the last two lines, but placed them elsewhere to avoid SL & TP be altered every candle when onmarket
    #101791 quote
    solar
    Participant
    Senior

    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?

    #101792 quote
    25sonalgo
    Participant
    New

    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!

    #101800 quote
    robertogozzi
    Moderator
    Master

    Performance for DJI-15min with 2.4 spread.

    #101803 quote
    solar
    Participant
    Senior

    IMO it works better if TGL or TGS are above 40 as the indices price is around 4times of that of oil.

    #101818 quote
    jannus
    Participant
    Junior

    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.

    #101819 quote
    robertogozzi
    Moderator
    Master

    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.

    #101830 quote
    robertogozzi
    Moderator
    Master

    I attach the .ITF file to be imported.

    #101887 quote
    Paul
    Participant
    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
    solar thanked this post
    #101999 quote
    solar
    Participant
    Senior

    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?

    #102054 quote
    Paul
    Participant
    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.

    solar thanked this post
Viewing 15 posts - 1 through 15 (of 16 total)
  • You must be logged in to reply to this topic.

Francesco’s Hammernegated strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
25sonalgo @25sonalgo Participant
Summary

This topic contains 15 replies,
has 5 voices, and was last updated by solar
6 years, 7 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/27/2019
Status: Active
Attachments: 6 files
Logo Logo
Loading...