HULL MA strategy orders lagging
Forums › ProRealTime English forum › ProOrder support › HULL MA strategy orders lagging
- This topic has 20 replies, 4 voices, and was last updated 6 years ago by
Nicolas.
-
-
12/17/2019 at 12:49 PM #115056
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:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879// Definition of code parametersDEFPARAM 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" timeDEFPARAM FLATAFTER = 163000daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0Period=17inner = 2*weightedaverage[round( Period/2)](typicalprice)-weightedaverage[Period](typicalprice)hull = weightedaverage[round(sqrt(Period))](inner)// Conditions to enter long positionsc1 = hull > hull[1]c2 = hull < hull[1]IF c1 AND not daysForbiddenEntry THENBUY 1 CONTRACT AT MARKETSET STOP PLOSS 20ENDIF// Conditions to exit long positionsIF c2 THENSELL AT MARKETENDIF// Conditions to enter short positionsIF c2 AND not daysForbiddenEntry THENSELLSHORT 1 CONTRACT AT MARKETSET STOP PLOSS 20ENDIF// Conditions to exit short positionsIF c1 THENEXITSHORT AT MARKETENDIF//trailing stop functiontrailingstart = 20 //trailing will start @trailinstart points profittrailingstep = 12 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//************************************************************************12/17/2019 at 12:59 PM #115059Just 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??
1 user thanked author for this post.
12/17/2019 at 1:02 PM #115060I 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
12/17/2019 at 1:04 PM #11506112/17/2019 at 1:07 PM #115062Cursor Details confirm an uptick of the Hull17, as does the colour change (pink to blue in the screen shot)
12/17/2019 at 1:19 PM #115066Sounds 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.
2 users thanked author for this post.
12/17/2019 at 8:14 PM #115121The 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.
12/17/2019 at 8:36 PM #115122orders 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??
12/17/2019 at 11:03 PM #115126For 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.
1 user thanked author for this post.
12/18/2019 at 11:40 AM #115149The code is working correctly. Look at attached picture for a better understanding of what your code is doing.
- Code is read at Close of the bar, condition met, order is launched at next bar open.
- 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”.
1 user thanked author for this post.
12/18/2019 at 1:29 PM #115161nonetheless – 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.
1 user thanked author for this post.
12/18/2019 at 1:52 PM #115166Hmm … 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!
12/18/2019 at 2:02 PM #11517012/18/2019 at 7:22 PM #115196The 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?
12/18/2019 at 9:19 PM #115198 -
AuthorPosts
Find exclusive trading pro-tools on