Hull average cross over strategy – where I am going wrong?

Viewing 15 posts - 1 through 15 (of 53 total)
  • Author
    Posts
  • #167721 quote
    8ficusst
    Participant
    Average

    Could someone please advise me here?

    I am developing a crossover type of trading system using aligning (< < or >>) HullAverage indicators for long and short triggers. The system performs well in BT, but I need to convert it for testing on the AUTO demo system. (It either triggers on every candle, or not at all)

    This system is designed to trade intraday swings on the EUR/USD 1-Min bars.  At each new bar, I press BT and only follow the direction of the two HullAverage indicators when they both align with each other – either up (long trigger) or down (short trigger).

    I have attached a very shortened version of this system here, because it contains a few hundred lines of code due to its multiple variables. I inserted both the BT version and the corresponding AUTO format on the same page to make it easier for you to compare the two systems.

    I would greatly appreciate someone having a look at this code in case you can see something wrong with it.

    Thanking you!

    CODING-example-for-AUTO-system.itf
    #167723 quote
    robertogozzi
    Moderator
    Master

    Can you post the code?

    8ficusst thanked this post
    #167755 quote
    Vonasi
    Moderator
    Master

    8ficusst – One place you are going wrong is by not giving your topic a meaningful title!

    • Give your topic a meaningful title. Describe your question or your subject in your title. Do not use meaningless titles such as ‘Coding Help Needed’.

     

    I changed your title to something that describes your topic.

    8ficusst thanked this post
    #167760 quote
    8ficusst
    Participant
    Average

    Point taken, thanks.

    #167766 quote
    GraHal
    Participant
    Master

    I posted the code as Roberto asked so then the coding wizards can readily spot any problems without having to download the .itf file.

    defparam cumulateorders = false
    defparam preloadbars = 1000
    
    // a and b variables: 300-350-50
    // c and d variables: 180-200-20
    
    MA1=HullAverage[c](momentum[a](close))
    MA2=HullAverage[d](momentum[a](close))
    S = MA1 < MA2
    
    MA3=HullAverage[c](momentum[b](close))
    MA4=HullAverage[d](momentum[b](close))
    L = MA3 > MA4
    
    if S and NOT L then
    sellshort at close stop
    endif
    
    if L and NOT S then
    buy at close stop
    endif
    
    GRAPH MA1 COLOURED (255,195,77) AS "Hullone"// orange
    GRAPH MA2 COLOURED (102,179,255) AS "Hulltwo"// blue
    
    GRAPH MA3 COLOURED (255,195,77) AS "Hullthree"// orange
    GRAPH MA4 COLOURED (102,179,255) AS "Hullfour"// blue
    
    
    // Below is my AUTO TRADING coding attempt for the above
    
    ////////  SHORTS   ///////////////////////
    
    AnyOfTheShorts = S1 or S2 or S3 or S4
    OpposingShorts =  (h1 > h2) or (h3 > h4) or (h5 > h6) or (h7 > h8)
    
    h1=HullAverage[900](momentum[300](close))
    h2=HullAverage[950](momentum[300](close))
    S1 = (h1 < h2)
    
    h3=HullAverage[950](momentum[300](close))
    h4=HullAverage[900](momentum[300](close))
    S2 = (h3 < h4)
    
    h5=HullAverage[900](momentum[350](close))
    h6=HullAverage[950](momentum[350](close))
    S3 = (h5 < h6)
    
    h7=HullAverage[950](momentum[350](close))
    h8=HullAverage[900](momentum[350](close))
    S4 = (h7 < h8)
    
    ////////  LONGS   ///////////////////////
    
    AnyOfTheLongs = L1 or L2 or L3 or L4
    OpposingLongs =  (k1 < k2) or (k3 < k4) or (k5 < k6) or (k7 < k8)
    
    k1=HullAverage[900](momentum[300](close))
    k2=HullAverage[950](momentum[300](close))
    L1 = (k1 > k2)
    
    k3=HullAverage[950](momentum[300](close))
    k4=HullAverage[900](momentum[300](close))
    L2 = (k3 > k4)
    
    k5=HullAverage[900](momentum[350](close))
    k6=HullAverage[950](momentum[350](close))
    L3 = (k5 > k6)
    
    k7=HullAverage[950](momentum[350](close))
    k8=HullAverage[900](momentum[350](close))
    L4 = (k7 > k8)
    
    ////////  SHORTS   ///////////////////////
    
    if AnyOfTheShorts and OpposingLongs then
    sellshort at close stop
    endif
    
    ////////  LONGS   ///////////////////////
    
    if AnyOfTheLongs and OpposingShorts then
    buy at close stop
    endif
    
    #167767 quote
    8ficusst
    Participant
    Average

    Hi Robertogozzi

    Thanks for your reply – please find the code attached here.

    CODING-example-for-AUTO-system-1.itf
    #167769 quote
    8ficusst
    Participant
    Average

    Thanks Gra

    My apologies. I was not sure.

    #167770 quote
    8ficusst
    Participant
    Average

    Correction

    Line 5 note should read: // c and d variables: 900-950-50

    Apologies.

    #167777 quote
    GraHal
    Participant
    Master

    Does adding not onmarket as below sort your problem?

    ////////  SHORTS   ///////////////////////
    
    if not onmarket and AnyOfTheShorts and OpposingLongs then
    sellshort at close stop
    endif
    
    ////////  LONGS   ///////////////////////
    
    if not onmarket and AnyOfTheLongs and OpposingShorts then
    buy at close stop
    endif
    #167783 quote
    8ficusst
    Participant
    Average

    GraHa – the “if NOT ONMARKET” instruction would be OK for the first trade when it is not yet onmarket, but thereafter the code itself keeps it always on market (it never exits – it just changes from shorts to longs, or vice versa), therefore the “if NOT ONMARKET” instruction would surely prevent it from being able to trigger another trade? Please correct me if my thinking is wrong about this?

    #167785 quote
    8ficusst
    Participant
    Average

    Thanks, I am trying it out with NOT ONMARKET just in case it will solve the problem.

    Will let you know the outcome.

    #167809 quote
    8ficusst
    Participant
    Average

    Gra, no luck with NOT ONMARKET……. it only allows one trade and wont trigger after that.

    Maybe someone else has an idea to get it operating like the BT does?

    #167810 quote
    GraHal
    Participant
    Master

    Did you try below …

    if not shortonmarket and AnyOfTheShorts and OpposingLongs then
    sellshort at close stop
    endif
     
    ////////  LONGS   ///////////////////////
     
    if not longonmarket and AnyOfTheLongs and OpposingShorts then
    buy at close stop
    endif
    #167811 quote
    GraHal
    Participant
    Master

    Anyway, why can’t / don’t you trade your backtest version … it contains Buy and Sellshort and you say it is the same as the Auto version??

    #167812 quote
    GraHal
    Participant
    Master

    In fact why don’t you throw it all in together and get attached!? 🙂

    Weird … PRT isn’t even stopping it working in ProOrder due to GRAPH in the code … I inadvertently left it in??

    8fi-5.jpg 8fi-5.jpg 8fi-6.jpg 8fi-6.jpg 8if-HullAv-DJI-M5-v1GH.itf
Viewing 15 posts - 1 through 15 (of 53 total)
  • You must be logged in to reply to this topic.

Hull average cross over strategy – where I am going wrong?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
8ficusst @8ficusst Participant
Summary

This topic contains 52 replies,
has 4 voices, and was last updated by 8ficusst
4 years, 9 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/21/2021
Status: Active
Attachments: 10 files
Logo Logo
Loading...