# Trend Follower

It analyses moving averages in a channel and their momentum according to the channel width.

On each bar it creates a channel by highest/lowest point of a MA. highest point is upper point and lowest point is lower point of the MA channel.

It gets highest and lowest point of last 300 bars, (say Price Channel )
If the width of MA channel is greater than certain rate of price channel then it decides there is trend.

After it decided there is trend, it calculates the rate between channel and MA. Bigger result means stronger trend.

According to rate of MA channel and the price channel , bar color becomes lighter/darker. so when you look at the bar color you can see the trend strength.

The darker the colour, the weeker the trend is.

Upon a request from user denmar (https://www.prorealcode.com/topic/help-converting-trend-follower-indicator-from-trading-view/) I converted this indicator written by LonesomeTheBlue.

Risk disclosure:

No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.

ProRealTime ITF files and other attachments : How to import ITF files into ProRealTime platform?

PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials

1. • 315 days ago #

Many thanks. Highly appreciated.

2. • 195 days ago #

Hi Roberto,
Thanks for this indicator which is very helpful.
I tried to use this indicator into a very simple strategy based on g > 0 –> BUY and r SELL.
The strategy runs however entry in call and put position don’t follow the indicator. Unfortunately I can’t put sceenshot to show
Do you have any idea why?
FYI I run with PRTV11

Thank you

I share only the end of the code + position entries:

Trend = x * diff / MyChannel
IF Trend > 0 THEN
r = 0
g = 255
b = 0
t = 255
IF Trend Trend[1] THEN
r = 139
g = 0
b = 0
t = 255
ENDIF
ENDIF

// Conditions pour ouvrir une position acheteuse
if not onmarket and g = 255 then
ENDIF

// Conditions pour fermer une position acheteuse
if longonmarket and r = 255 then
SELL AT MARKET
ENDIF

// Conditions pour ouvrir une position en vente à découvert
if not onmarket and r = 255 then
SELLSHORT 1 CONTRACTS AT MARKET
ENDIF

// Conditions pour fermer une position en vente à découvert
if shortonmarket and g = 255 then
EXITSHORT AT MARKET
ENDIF

3. • 195 days ago #

Don’t use colours as a signal,
If it’s > 0 it’s a Long signal, otherwise it’s a Short signal.

4. • 194 days ago #

Hi Roberto,
I did previously but same result.

5. • 191 days ago #

Can you try on your side to check if that works properly for you?

6. • 191 days ago #

Post the complete code you used.

7. • 190 days ago #

/ Trend Follower

//
MAtype = 1 //1=Ema
TrendP = 20 //20 periods to check trend
MAperiods = 20 //20 periods for MA
TrendRate = 1 //1% trend channel rate
UseLR = 1 //1=use Linear Regression, 0=do not use LR
LRperiods = 5 //5 periods for Linear Regression
RangeP = 1 //300 period for the range
MAtype = max(0,min(8,MAtype))
TrendP = max(1,min(999,TrendP))
MAperiods = max(1,min(999,MAperiods))
TrendRate = max(0.00001,min(99,TrendRate))
RangeP = max(1,min(999,RangeP))
//
RateMult = TrendRate / 100
PriceRange= highest[RangeP](high) – lowest[RangeP](low)
MyChannel = PriceRange * RateMult
MyMA = average[MAperiods,MAtype](close)
IF UseLR THEN
MyMA = LinearRegression[LRperiods](close)
ENDIF
hh = highest[TrendP](MyMA)
ll = lowest[TrendP](MyMA)
diff = abs(hh – ll)
x = 0
IF diff > MyChannel THEN
IF MyMA > (ll + MyChannel) THEN
x = 1
ELSE
IF MyMA 0 THEN
r = 0
g = 255
b = 0
t = 255
IF Trend Trend[1] THEN
r = 139
g = 0
b = 0
t = 255
ENDIF
ENDIF

// Conditions pour ouvrir une position acheteuse
if not onmarket and trend > 0 then
endif

// Conditions pour fermer une position acheteuse
if longonmarket and trend < 0 then
SELL AT MARKET
ENDIF

// Conditions pour ouvrir une position en vente à découvert
if not onmarket and trend 0 then
EXITSHORT AT MARKET
ENDIF

8. • 190 days ago #

It seems I had some difficulties to copy paste the complete code correctly.
The overall code is just your indicator + the following conditions at the end:
Read trend > 0 instead of g = 255 and trend < 0 instead of r = 255

// Conditions pour ouvrir une position acheteuse
if not onmarket and g = 255 then
ENDIF

// Conditions pour fermer une position acheteuse
if longonmarket and r = 255 then
SELL AT MARKET
ENDIF

// Conditions pour ouvrir une position en vente à découvert
if not onmarket and r = 255 then
SELLSHORT 1 CONTRACTS AT MARKET
ENDIF

// Conditions pour fermer une position en vente à découvert
if shortonmarket and g = 255 then
EXITSHORT AT MARKET
ENDIF

9. • 189 days ago #

I can’t understand when you want to enter/exit.
Please start a new topic in ProOrder support and attach the ITF file of your strategy + screenshot (showing also the instrument and timeframe used).

10. • 189 days ago #

Hi Roberto, sorry for my confusing previous posts (forget them). My request is very simple, I just want to enter/exit by using TREND signal from your indicator.
I want entry long when trend > 0 then exit when trend 0 and exit long is not when trend < 0 (same at the opposite for short signal).
It's why I wondered if you can test by your own and then share with me the last lines of your ProOrder code?
Thanks for you help.

// Trend Follower
//
//
MAtype = 1 //1=Ema
TrendP = 20 //20 periods to check trend
MAperiods = 20 //20 periods for MA
TrendRate = 1 //1% trend channel rate
UseLR = 1 //1=use Linear Regression, 0=do not use LR
LRperiods = 5 //5 periods for Linear Regression
RangeP = 1 //300 period for the range
MAtype = max(0,min(8,MAtype))
TrendP = max(1,min(999,TrendP))
MAperiods = max(1,min(999,MAperiods))
TrendRate = max(0.00001,min(99,TrendRate))
RangeP = max(1,min(999,RangeP))
//
RateMult = TrendRate / 100
PriceRange= highest[RangeP](high) – lowest[RangeP](low)
MyChannel = PriceRange * RateMult
MyMA = average[MAperiods,MAtype](close)
IF UseLR THEN
MyMA = LinearRegression[LRperiods](close)
ENDIF
hh = highest[TrendP](MyMA)
ll = lowest[TrendP](MyMA)
diff = abs(hh – ll)
x = 0
IF diff > MyChannel THEN
IF MyMA > (ll + MyChannel) THEN
x = 1
ELSE
IF MyMA < (hh – MyChannel) THEN
x = -1
ENDIF
ENDIF
ENDIF
Trend = x * diff / MyChannel
IF Trend > 0 THEN
r = 0
g = 255
b = 0
t = 255
IF Trend < Trend[1] THEN
g = 128
t = 180
ENDIF
ELSE
r = 255
g = 0
b = 0
t = 255
IF Trend > Trend[1] THEN
r = 139
g = 0
b = 0
t = 255
ENDIF
ENDIF

// Long Entry
if not onmarket and trend > 0 then
ENDIF

// Long Exit
if longonmarket and trend < 0 then
SELL AT MARKET
ENDIF

// Short Entry
if not onmarket and trend < 0 then
SELLSHORT 1 CONTRACTS AT MARKET
endif

// Short Exit
if shortonmarket and trend > 0 then
EXITSHORT AT MARKET
ENDIF

11. • 187 days ago #

Please start a new topic in ProOrder support.

12. • 187 days ago #

OK

Register or

#### Likes

Related users ' posts
Sever
6 months ago
0
Indicators
Sever
7 months ago
2
Indicators
Hi Sever, how can I visualize the coloured areas?
Hi Stenozar, You need to add the color zones yourself , just go to Add Color Zone To set ...
Nicolas
10 months ago
2
Indicators
hi nicolas this indicator have 2 wrong borderline and islalastbarupdate. thank you can you h...
That'"s because you are not using PRT v11? Just remove lines 59 to 62
robertogozzi
11 months ago
31
Indicators
There you go: myMagicTrend = CALL “Magic Trend custom”[20, 14, 1, 5] alpha = 105 b = 0...
exactly :) Thank you all for the help!
Newbie
1 year ago
0
Indicators
Nicolas
1 year ago
v10.3
12
Indicators
Bonjour, j'ai essayé de faire afficher cet indic en temps 5 mn sur le 1 mn et c'est Hiroshim...
Il suffit d'ajouter l'instruction TIMEFRAME(5 minutes,updateonclose) en tête du code
cordial saludo Nicolas, una pregunta senciLla : Como coloco un STOPS en un maximo o un mini...
Nicolas
1 year ago
v10.3
4
Indicators
change the last line with: return v coloured(r,g,b) style(line,2), v+band coloured(168,168,1...
Thanks ... works as i wanted.
Bonjour Nicolas, comme Paolo.B je souhaiterais utiliser cette indicateur au sein d'un code. ...
Nicolas
1 year ago
2
Indicators
Thanks @Nicolas. I tried to use it as Trend in a proorder system, but don't know why, it doe...
He is right. MT and mavgMT are not defined and causing errors.....
juanj
2 years ago
v10.3
0
Indicators
Nicolas
2 years ago
v10.3
3
Indicators
"style(line,2)" C'è una guida ai parametri che si possono modificare ? Tipo stile della lin...
https://www.prorealcode.com/programming-with-prorealtime/
Tanks
2 years ago
13
Indicators
Écrivez-moi où vous préférez you can easily find me on LinkedIn
C'est payant visiblement sur linkdin je peux pas vous envoyer, discord vous avez ?
Nicolas
2 years ago
v10.3
57
Indicators
C'est dans ce sujet: https://www.prorealcode.com/topic/trendline-une-approche-du-trading/ M...
Bonjour Nicolas, comment est-il possible de backtester cet indicateur? cela fait une erreu...
Oui bien sûr, il doit y avoir pas mal de sujets dans le forum à ce propos.
Nicolas
2 years ago
v10.3
6
Indicators
Il doit s'agir d'un mauvais copier/coller. Je suggère de télécharger le fichier itf contenu ...
Hello @Nicolas, I can get this to display in a separate indicator panel but not on Price as ...
Hi @Nicolas, how can I put the bands on price? Thanks, Stefano
2 years ago
v10.3
7
Indicators
I gave the above message fix ;)
Is it possible to put the itf-file in the right way here in Prorealcode? so the right 'trend...
Thomas
2 years ago
v10.3
0
Indicators
Bard
2 years ago
v10.3
0
Indicators
Jan
2 years ago
v10.3
2
Indicators
Hi man, I installed the indicator and i don't know why but my graph it is so big
sounds interesting I'll take a look
Dow Jones
2 years ago
21
Strategies
Bonjour Souhait Sam, Après de nombreux essais pour le mettre en format afin d'utiliser ce c...
Il faut supprimer celles qui existent dans la fenêtre d'optimisation et les créer en dur dan...
hi there, anyone can help making this strategy work, i have a message saying replace variabl...
Nicolas
2 years ago
v10.3
7
Indicators
Salut nicolas j'aimerais savoir tes résulats grace a cettte methode
It dose not work, I get a strap instead of candels???????????????????????????????????????????
That indicator is the one below the chart. The indicator to put on the price chart is this o...
Nicolas
2 years ago
v11
22
Indicators
P.S : IG , que j'ai contacté ,m'indique que la version V11 , ne sera pas disponible avant un...
Dear Nicolas, is there someting at the arry to modify in order to run the trend at the actu...
Dear Nicolas, just try touse your indicator with backtest but it's not working. is anybody...

Top