Trend detection codes
Forums › ProRealTime English forum › ProOrder support › Trend detection codes
- This topic has 44 replies, 12 voices, and was last updated 3 years ago by
monkeys nuts.
-
-
09/30/2021 at 9:43 AM #178769
Hi guys,
I would like to know what kind of codes do you use for trend detection and which do you think are the most reliable; here’s some examples that i’ve applied before:
123// Trend Detectionbull= (average[x](close)>average[y](close)[1])bear= (average[x](close)<average[y](close)[1])12345678// Trend Detectionma1= average[x](close)ma2= average[y](close)bull= close>ma1 and close>ma2 and ma1>ma2ma3= average[x](close)ma4= average[y](close)bear= close<ma3 and close<ema4 and ma3<ema409/30/2021 at 9:58 AM #17877309/30/2021 at 10:26 AM #178775Another one is Higher HIGHs + higher LOWs or Lower HIGHS + Lower LOWS:
12345678910111213141516//N = 20srcH = close //or HIGHsrcL = close //or LOWHH1 = highest[N](srcH)LL1 = lowest[N](srcL)HH2 = highest[N](srcH[N])LL2 = lowest[N](srcL[N])UPtrend = ((HH1 > HH2) AND (LL1 > LL2))DOWNtrend = ((HH1 < HH2) AND (LL1 < LL2))MyTrend = 0IF UPtrend AND UPtrend <> UPtrend[1] THENMyTrend = 1ELSIF DOWNtrend AND DOWNtrend <> DOWNtrend[1] THENMyTrend = -1ENDIFRETURN MyTrend AS "Trend"09/30/2021 at 11:40 AM #178781Link to above added as Log 306 here …
3 users thanked author for this post.
10/02/2021 at 6:02 PM #178946Ciao Francesco, this is what I’m mostly using for primary trend these days for short TFs (rising or falling MA, but separate long and short):
12345Timeframe (1 hour)ma = average[a,t](typicalprice)long = ma > ma[1]mb = average[a1,t1](typicalprice)short = mb < mb[1]2 users thanked author for this post.
01/28/2022 at 5:37 AM #186785Hi Roberto l have made a EA for MT4 but l want to code it on prorealtime but the coding different
this is want i have done
Function Start Time
if is time >= H Start Hour M Start Minute
Boolean variable ONCE to True
Main Bar attach Start time Function(l learnt ONCE form You)
if ONCE
do Set BarCounter to BarCounter + 1
Print Counter = BarCounter (text block)
if barCounter = [65] bars
do Set LC1 to Bar Close Shift of Lowest Close count [6] shift 1
Set HC1 to Bar Close Shift of Highest close count [40] shift 1
Set LHC1 to Bar Close Shift of Lowest High count [65] shift 1
Boolean Set Once to False
Variable Set barCounter to 0
Print LC1 = (Variable) LC1
Print HC1 = (Variable) HC1
Print LHC1= (Variable) LHC1
This is to back test if my EA is working on MT4 How would l start to write this code with ProrRealTime02/14/2022 at 6:41 PM #188245I’d like a smart assessment from some smart people here.
In the short-term sector (M5…M1) I have several of the same systems running with different filters as far as the trend is concerned. All sort of SMAs.
3 variants as an example:
Version 1:
MA > MA[1]
Most customizable, but seems to have the greatest propensity for over-optimization.
Variant 2:
close > MA
Even better and quite robust.
Variant 3:
close > close(20)
Surprisingly the most robust. For whatever reason. Now I wanted to hear your experiences, what have you had?02/15/2022 at 9:56 AM #188273Hello phoentzs
Interesting question. Not sure I meet the definition of ‘smart people’ 🙂 but here is my feedback which I hope is of use. When testing different trend detection systems in a strategy I expect to see periods where the strategy doesn’t trade and a flat line appears on the equity curve. Not trading is also a good option at times.
With that in mind I tested the three different lines of code you posted, and ran them on higher time frames. They didn’t fulfill my own personal requirements and the strategy kept trading. I appreciate this may differ from your own objectives here.
Here is an example of what I use, which can be adapted to lower time frames.
123456//Entry FilterTimeframe(X hours)FMA1 = average[p,t]FMA2 = average[p,t]F1 = FMA1 > FMA2Timeframe(Default)2 users thanked author for this post.
02/15/2022 at 10:06 AM #188275sam, that won’t work the way you’ve written it as FMA1 and FMA2 will be identical.
FMA2 would need a different period or type … which I’m sure is what you meant 😁
02/15/2022 at 10:41 AM #188276Hi nonetheless
Both “p” and “t” are different for both FMA1 and FMA2. Perhaps I should have written it as “p1” and “p2” to make it more obvious 🙂
02/15/2022 at 11:03 AM #188277yeah, i assumed that is what you would have done. I was more concerned for total noobies just copying what you had posted and then wondering why there were 0 trades …
2 users thanked author for this post.
02/15/2022 at 12:33 PM #188286Yes, I also use this variant. As a range filter, just to stay in my direction as much as possible. Perhaps I should have said that I use the variants I posted as an exit from the position at the same time. So you’re pretty close to the course. Depending on the market and timeframe between 10…20. And here, strangely enough, the Close>close(10…20) variant works best as a filter and simultaneous exit.
1 user thanked author for this post.
02/15/2022 at 5:57 PM #18831002/15/2022 at 5:59 PM #18831102/16/2022 at 1:10 PM #188347Given that there is no perfect trend indicator , what if we add several trend indicators and find a “composite” trend indicator, to average the pros & cons of each one ?
composite trend indicator123456789101112131415161718trend = 0 // cummulative "trend strength"//first condition : close > close[10...20]c = 1for i = 10 to 20trend = trend + (close > close[i])nexttrend = trend/11 //average result// second condition EMA(10) > EMA(30)c = c +1trend = trend + (exponentialAverage[10](close) > exponentialaverage[30](close))//third condition: close > EMA(30)c = c +1trend = trend + (close > exponentialaverage[30](close))// more conditions ....trend = trend/c // average trend strength = 0...1return 2*trend - 1, 1, 0, -1 // +1 strong bullish -1 strong bearish1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on