# Magic Trend Indicator

Magic Trend Indicator may help identifying the correct trend direction.
It is plotted on the price chart, like any moving average, though it is faster, more accurate
and reliable than other trend following indicators.

The calculation of indicator is based on ATR, current price direction and some more complex
logic.

Magic Trend Indicator changes its color based on the direction of the trend, so if the line
is green then the trend is up and if it is red then the trend is down.
The value of Magic Trend indicator can be used as trend reversal trigger on closing basis.
If you are on long position and on any bar price closes below the indicator value then the
indicator turns red from the next bar to indicate the reversal of trend, so the trader can
exit his long position and take short position at the same time.
The opposite rules apply to the short positions.

A buy signal is also triggered when the closing price crosses above the Magic Trend line and
a short signal is triggered when the closing price crosses below the Magic Trend line.

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. • 09/14/2021 #

what is the function of temp1? it is not taken into account in the calculation

2. • 09/14/2021 #

How can i use this in a strategy?

3. • 09/14/2021 #

It is well described above.
To use it you can use CALL as with any other indicator.
This is the instruction:
myMagicTrend = CALL “Magic Trend”[20, 14, 1, 5]
Parameters (you can change them as best suits you):
20 is the CCI periods
14 is the ATR periods
1 is the ATR multiplier (can be a decimal number)
5 is the periods of a Simple Moving Average.

4. • 09/14/2021 #

I Created a thread for this
https://www.prorealcode.com/topic/magic-trend-strategy/

5. • 09/14/2021 #

Wich timeframe and index are used in your picture?

• • 09/14/2021 #

DAX daily

6. • 09/14/2021 #

Hi Roberto, Thank you for the work but how do you get the indicator to change color from green to red and vice versa? Mine is one color only with no option to change it in the configuration window?

• • 09/14/2021 #

Color and other drawing indicator settings can be changed easily if you select “Properties”.

• • 09/14/2021 #

If MagicTrend > MagicTrend[1] then it’s green, red otherwise.

7. • 09/14/2021 #

Hello Roberto.
Thanks for this interesting indicator.

I wanted to try use it in an automatic system in 2 different ways.

First depending on its state do not enter long or short. Example if green, do not short and if red do not enter long
Second trigger signal when the color change from green to red or red to green.

I must admit I failed in both ways.
Cheers.

8. • 09/14/2021 #

If MagicTrend > MagicTrend[1] then it’s green, red otherwise.

• • 09/14/2021 #

Thank Roberto.
I thought about that also but I would like to get only one signal. Only when the color change from green to red or red to green.
If I do
MagicTrend > MagicTrend[1]
I will get several signals not only when the color change.

9. • 09/14/2021 #

(see below)

10. • 09/14/2021 #

If MagicTrend <> MagicTrend[1] then it’s Green or Red

• • 09/14/2021 #

Buonasera Roberto, ho provato ad usare questo indicatore inserendo l’istruzione di cui sopra ” If MagicTrend > MagicTrend[1] then it’s green, red otherwise” ma ricevo un errore di sintassi . cosa sbaglio ? grazie

11. • 09/14/2021 #

A really nice indicator. Can easily be used as a strategy. I’ve tried a few trend indicators here but this one works perfectly for me.

Thank you for sharing, Roberto.

12. • 328 days ago #

Hi. I would like to color the background green or red if the “Magic Trend Custom” is green or red. Unfortunately I can’t get this to work correctly. I tried the following:

myMagicTrend = CALL “Magic Trend custom”[20, 14, 1, 5]

//If myMagicTrend => myMagicTrend[1] THEN
//BACKGROUNDCOLOR(204,255,204,alpha)
//ELSIF myMagicTrend =< myMagicTrend[1] THEN
//BACKGROUNDCOLOR(255,204,204,alpha)
//ENDIF

If myMagicTrend <> myMagicTrend[1] THEN
BACKGROUNDCOLOR(204,255,204,alpha)
ELSE
BACKGROUNDCOLOR(255,204,204,alpha)
ENDIF

Return

Can anyone help me? Many thanks

• • 328 days ago #

You forgot to set the variable ALPHA to any value between 0 and 255 (0=invisible, 255=fully visible). place this line at the beginning (or at any point prior to where it is used):
alpha = 150

• • 325 days ago #

Hello Roberto. I have set ALPHA as a variable. But even if I fill it in manually, the background doesn’t match the magic trand indicator.
I p

• • 325 days ago #
• • 325 days ago #

It’s because you are NOT checking when it’s green or red, but when it’s different from the previous bar.
This will do:
myMagicTrend = CALL “Magic Trend custom”[20, 14, 1, 5]
alpha = 150
Green = myMagicTrend > myMagicTrend[1]
Red = myMagicTrend < myMagicTrend[1]
If Green THEN
r = 204
g = 255
b = 204
ELSIF Red THEN
r = 255
g = 204
b = 204
ENDIF
BACKGROUNDCOLOR(r,g,b,alpha)
Return

13. • 325 days ago #

Ahhh, I think it rang now. MANY THANKS. I shouldn’t have used “Background” in the query:
If myMagicTrend => myMagicTrend[1] THEN
BACKGROUNDCOLOR(204,255,204,alpha)
ELSIF ………….

Right way:
IF myMagicTrend > myMagicTrend[1] THEN
r = 204
g = 255
b = 204
ELSIF myMagicTrend < myMagicTrend[1] THEN
r = 255
g = 204
b = 204
ENDIF

Sto usando il tuo codice ora.
Stupido, io. Grazie molte.

Tonto, yo.
😉

14. • 322 days ago #

I want to see vertical lines instead of background. Green line long and red line short.
Can someone help me?
see image.

Thanks 🙂

• • 322 days ago #

use DRAWVLINE in replacement of BACKGROUNDCOLOR.

15. • 322 days ago #

Simply “DRAWVLINE” through “BACKGROUNDCOLOR” doesn’t work.
I have no idea about it.

• • 322 days ago #

You can find details about the instructions at https://www.prorealcode.com/prorealtime-documentation/.
Anyway, this is the code:
myMagicTrend = CALL “Magic Trend custom”[20, 14, 1, 5]
alpha = 105
b = 0
Green = myMagicTrend > myMagicTrend[1]
Red = myMagicTrend < myMagicTrend[1]
If Green THEN
r = 0
g = 255
ELSIF Red THEN
r = 255
g = 0
ENDIF
DrawVline(BarIndex) coloured(r,g,b,alpha)
Return

16. • 322 days ago #

Thanks Roberto,

even with the instructions i didn’t get any further.
What I want is just a vertical one line for long (red) and one line for short (green). Not permanent.

17. • 322 days ago #

• • 322 days ago #
• • 322 days ago #

There you go:

myMagicTrend = CALL “Magic Trend custom”[20, 14, 1, 5]
alpha = 105
b = 0
Green = myMagicTrend > myMagicTrend[1]
Red = myMagicTrend < myMagicTrend[1]
If Green THEN
r = 0
g = 255
Last = 1
ELSIF Red THEN
r = 255
g = 0
Last = 2
ENDIF
IF Last <> Last[1] THEN
DrawVline(BarIndex) coloured(r,g,b,alpha) STYLE(Line,5) //width 1-5
ENDIF
Return

18. • 322 days ago #

exactly 🙂

Thank you all for the help!

19. • 281 days ago #

Ciao Roberto, ho scaricato l’indicatore e come ti avevano già scritto sopra anch’io vedo la linea di un solo colore. Non sono esperto di programmazione, per fare il colore verde e rosso come nella tua foto come devo fare. Devo inserire un’altro pezzo di codice? Nel caso quale e in che posizione? Grazie

Register or

#### Likes

+5 more likes

Related users ' posts
Nicolas
1 week ago
2
Indicators
Well done Nicolas, creative!
Hi Nicolas, please can you explain how to read/use this indicator? thanks!
Nicolas
2 months ago
17
Indicators
Bonjour, quelle est la meilleure UT pour travailler avec cet indicateur?
@RICOU en 1 minutes avec un filtre de tendance ZLSMA 200 et eventuellement un rsi 7 , 69% de...
For people interested in the screener: https://www.prorealcode.com/topic/screener-buy-sell-m...
Nicolas
2 months ago
4
Indicators
Yes, Magic if the variable that contains the value of the line, you can test if it goes up o...
Bonjour Nicolas, merci pour cet indicateur. Utilisant pour l'instant la création simplifié p...
Merci d'ouvrir un sujet sur le forum avec une description complète du système.
Nicolas
2 months ago
1
Indicators
Is it possible to add histogram with only increasing bars?
Nicolas
2 months ago
3
Indicators
Merci beaucoup Nicolas, Il a l'air vraiment interessant. Je vais le tester ;-)
Bonjour de la Bretagne, merci Nicolas toujours parfait! (serait il possible d'avoir le SCR ? )
Merci de formuler la demande dans le forum des screeners.
luxrun
4 months ago
0
Indicators
Jiacky
10 months ago
0
Indicators
Sever
1 year ago
0
Indicators
Sever
1 year 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
2 years 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
2 years ago
12
Indicators
Hi Roberto, sorry for my confusing previous posts (forget them). My request is very simple,...
Please start a new topic in ProOrder support.
OK
Newbie
2 years ago
0
Indicators
Nicolas
2 years ago
v10.3
15
Indicators
A première vue, sa à l'air d'être un indicateur très puissant sur de petites temporalités, j...
Bonjour Nicolas, Comment transformer cet indicateur en bot sur PRT ?
Cela a déjà été fait, voir ce sujet: https://www.prorealcode.com/topic/strategia-con-lindica...
Nicolas
2 years 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
2 years 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
3 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
3 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
3 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

Top