HULL MA strategy orders lagging

Viewing 15 posts - 1 through 15 (of 21 total)
  • Author
    Posts
  • #115056 quote
    nonetheless
    Participant
    Master

    Here’s a strange thing: code specifies changing direction after a change in the Hull17. Running on the FTSE it works as expected but on the DAX there tends to be a lag, so orders happen not on the next candle but after 2 candles … much less good. Looking at the screen shot, the Hull17 turns up at 11:20 so it should close the short and open long next candle @ 13285 … but instead this happens a candle later @ 13296. Any thoughts ?

    Here’s the code:

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    // The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the "FLATBEFORE" time.
    DEFPARAM FLATBEFORE = 080000
    // Cancel all pending orders and close all positions at the "FLATAFTER" time
    DEFPARAM FLATAFTER = 163000
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
     
    Period=17
    inner = 2*weightedaverage[round( Period/2)](typicalprice)-weightedaverage[Period](typicalprice)
     
    hull = weightedaverage[round(sqrt(Period))](inner)
     
    // Conditions to enter long positions
    c1 = hull > hull[1]
    c2 = hull < hull[1]
     
    IF c1 AND not daysForbiddenEntry THEN
    BUY 1 CONTRACT AT MARKET
    SET STOP PLOSS 20
    ENDIF
     
    // Conditions to exit long positions
     
    IF c2 THEN
    SELL AT MARKET
    ENDIF
     
    // Conditions to enter short positions
     
    IF c2 AND not daysForbiddenEntry THEN
    SELLSHORT 1 CONTRACT AT MARKET
    SET STOP PLOSS 20
    ENDIF
     
    // Conditions to exit short positions
     
    IF c1 THEN
    EXITSHORT AT MARKET
    ENDIF
    //trailing stop function
    trailingstart = 20 //trailing will start @trailinstart points profit
    trailingstep = 12 //trailing step to move the "stoploss"
     
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
     
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
    newSL = tradeprice(1)-trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
    newSL = newSL-trailingstep*pipsize
    ENDIF
    ENDIF
     
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    //************************************************************************
     
    
    DAX-2.5.jpg DAX-2.5.jpg
    #115059 quote
    GraHal
    Participant
    Master

    Just a though off the top of my head … what is it like if you run on a 2 min TF instead of 2.5 min TF??

    Have you tried looking at the values of Hull using … right click, Display , Cursor Details … maybe Hull is not turning up just when you think by looking at the Hull curve??

    nonetheless thanked this post
    #115060 quote
    nonetheless
    Participant
    Master

    I could try that, but generally I prefer 2.5m as a fast chart as it stays in synch with the more popular 5m and 15m. On the FTSE it works exactly as expected on the 2.5m

    #115061 quote
    GraHal
    Participant
    Master

    Try Cursor Details  … let us know how you get on please??

    #115062 quote
    nonetheless
    Participant
    Master

    Cursor Details confirm an uptick of the Hull17, as does the colour change (pink to blue in the screen shot)

    #115066 quote
    Nicolas
    Keymaster
    Master

    Sounds like a rounding issue of the period used for the Hull average.

    Add “graph hull” at the end of your code to compare the calculated HULL MA in ProBacktest to the one displayed on your chart.

    GraHal and nonetheless thanked this post
    #115121 quote
    nonetheless
    Participant
    Master

    The ProBacktest graph gives slightly different values for HULL than the Prorealtime chart but registers the same change of direction at the same time.  I’ve just noticed the same problem with another script on DJI 15m – orders are executed on the third candle instead of  the second. Bigger problem when waiting another 15 minutes to open/close.

    #115122 quote
    GraHal
    Participant
    Master

    orders are executed on the third candle instead of  the second.

    This is worrying and we have had this brought up on here before  … very recently.

    For clarification, third candle means 2 candles after the candle which meet conditions to execute a trade?

    This is something that very few (if any except you) of us check for?? I know I don’t!

    If any reader does check this then please just say so on this Thread, then we will know this is NOT a widespread Issue??

    #115126 quote
    nonetheless
    Participant
    Master

    For clarification, third candle means 2 candles after the candle which meet conditions to execute a trade?

    Yes. First candle shows the MA has changed direction, second should be the entry/exit, instead I’m getting the one after that … but only with DAX and DJI. FTSE behaves itself.

    V strange.

    GraHal thanked this post
    #115149 quote
    Nicolas
    Keymaster
    Master

    The code is working correctly. Look at attached picture for a better understanding of what your code is doing.

    1. Code is read at Close of the bar, condition met, order is launched at next bar open.
    2. Your code is not testing changing of direction, but the slope of the Hull moving average (ascending or descending?). So orders could be launched in a middle of a long time formed “Hull trend”.
    nonetheless thanked this post
    hull-ma-trading-strategy.png hull-ma-trading-strategy.png
    #115161 quote
    Vonasi
    Moderator
    Master

    nonetheless – I have changed your topic tile to something more meaningful. Please try to use titles that describe your topic rather than meaningless ones otherwise we will end up with forums full of ‘Help needed’ and ‘Code is not behaving’ topics.

    nonetheless thanked this post
    #115166 quote
    nonetheless
    Participant
    Master

    Hmm … that’s interesting. Not what I thought I had coded for. With the FTSE it acts upon a simple change of direction in the Hull MA rather than the slope. Or at least, I think it does! I’ll watch it a bit longer and see how it plays. Thanks again!

    #115170 quote
    Nicolas
    Keymaster
    Master

    The conditions c1 and c2 are actually just testing if hull is superior (or inferior) to its last value, and not testing if it has changed from ascending to descending (making a top) and vice-versa (making a bottom).

    #115196 quote
    nonetheless
    Participant
    Master

    The conditions c1 and c2 are actually just testing if hull is superior (or inferior) to its last value

    Yes, that is what I intended. And my expectation was that positions would enter/exit on the candle after that change.

    Otherwise the code would be c1 = hull > hull[2] no?

    #115198 quote
    GraHal
    Participant
    Master

    To test if Hull has made a Bottom or a Top (change of direction) would you not use Lowest or Highest over x periods?

    But I guess you want what you coded for!? 🙂

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

HULL MA strategy orders lagging


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 20 replies,
has 4 voices, and was last updated by Nicolas
6 years, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/17/2019
Status: Active
Attachments: 2 files
Logo Logo
Loading...