Magic Trend Indicator

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.

Share this

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

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

  2. murre87 • 09/14/2021 #

    How can i use this in a strategy?

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

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

  5. murre87 • 09/14/2021 #

    Wich timeframe and index are used in your picture?

  6. Johann • 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?

    • Lavallette • 09/14/2021 #

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

    • robertogozzi • 09/14/2021 #

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

  7. Lavallette • 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.
    Could you please advice?
    Cheers.

  8. robertogozzi • 09/14/2021 #

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

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

    (see below)

  10. robertogozzi • 09/14/2021 #

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

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

    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

    • robertogozzi • 09/14/2021 #

      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

    • Thomas • 09/14/2021 #

      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

    • Thomas • 09/14/2021 #
    • robertogozzi • 09/14/2021 #

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

    Ahhh, I think it rang now. MANY THANKS. I shouldn’t have used “Background” in the query:
    Instead of:
    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. johann8 • 09/14/2021 #

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

    Thanks 🙂

    • Nicolas • 09/14/2021 #

      use DRAWVLINE in replacement of BACKGROUNDCOLOR.

  15. johann8 • 09/14/2021 #

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

    • robertogozzi • 09/14/2021 #

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

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

    https://www.prorealcode.com/wp-content/uploads/2016/02/DRAWVLINE-example.png

    • robertogozzi • 09/14/2021 #
    • robertogozzi • 09/14/2021 #

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

    exactly 🙂

    Thank you all for the help!

  19. max_92 • 09/14/2021 #

    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

avatar
Register or

Likes

avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar

+8 more likes

Related users ' posts
Guillaume Mcm I gave the above message fix ;)
Tradingrob Is it possible to put the itf-file in the right way here in Prorealcode? so the right 'trend...
Guillaume Mcm Update link ;) https://www.prorealcode.com/topic/trend-histogramme-cci-mise-a-jour-suite-...
Screw27 Hi man, I installed the indicator and i don't know why but my graph it is so big
HelixKing sounds interesting I'll take a look
Godo Bonjour Souhait Sam, Après de nombreux essais pour le mettre en format afin d'utiliser ce c...
Nicolas Il faut supprimer celles qui existent dans la fenêtre d'optimisation et les créer en dur dan...
crusoe76 hi there, anyone can help making this strategy work, i have a message saying replace variabl...
Screw27 Salut nicolas j'aimerais savoir tes résulats grace a cettte methode
eva.g.forsgren It dose not work, I get a strap instead of candels???????????????????????????????????????????
Nicolas That indicator is the one below the chart. The indicator to put on the price chart is this o...
pyhrus P.S : IG , que j'ai contacté ,m'indique que la version V11 , ne sera pas disponible avant un...
Hasardeur Dear Nicolas, is there someting at the arry to modify in order to run the trend at the actu...
MALIMALO Dear Nicolas, just try touse your indicator with backtest but it's not working. is anybody...
ribes65 Bonjour Nicolas, Merci pour votre travail. Est-il envisageable de créer un screener pour ...
Nicolas Bien sûr, merci de formuler une demande dans le forum des screeners pour prorealtime. En res...
ipbvba Est il possible de le transformer en indicateur (pour ne plus avoir les lignes mais uniqueme...
supertiti Bonjour Nicolas, Je ne comprend pas bien , le trend change de couleur quand les prix sont a...
Nicolas Oui ce serait possible, cependant l'indicateur est bien prévu pour conserver la couleur de l...
supertiti Quand tu pourras si tu peux nous coder la troisième couleur cela améliorerait les trades cou...
Nicolas How to import file page: in the help section of the website explains howto
kenssa import through the indicator page/window in the Proreal time
chicoteca Buenas, no consigo que se me muestre en el chart de DAX. ¿Cómo procedo? Gracias.-
frenqle Hi There.. It seems the TSL stop loss is not working.. it does not respond is that correct?
Ciccarelli Franco Per lasciare che la strategia venga eseguita (dopo aver importato il file): Basta eliminare...
JADINVEST Hello Jan, hello everyone, Thanks Jan for this strategy! Since 2020, have any of you found a...
Stockastiss Can this code be simply transferred into Backtestingcode so one doesnt need to use call ? (i...
Vonasi Sorry for the late reply. Add the code to your strategy and remove line 5 and line 39. Chang...
viktorthunss Hi! How many averages are there? Can I see the somewhere?
leofi https://www.prorealcode.com/topic/simple-average-with-visual-color/
leofi Go visit www.prorealcode.com/topic/simple-average-with-visual-color/ and watch 2em post
Dritan Hi,I am new on Prorealtime and coding.I downloaded the indi but I have it on a separate wind...
Nicolas Just add it on the price series.
yomisadiku Hello Nicolas, Can I use high and low price at lines hh=max(hh,close) and ll=min(ll,close) ...
Nicolas Yes you can do that, the impact will be that the trailing stop line will be much close to th...
Byggtrader Hi Nicolas! How do I get the indicator in the price chart? It only stays under i new chart.
Nicolas Just add it on the price chart by using the wrench on the left upper side of the chart (pric...
Dom Hello, hello....je commence le trading et découvre par la même occasion le codage....et ce n...
Nicolas Merci, ça fait plaisir !
Be-n Bonjour tout le monde ! Dans l'indicateur de tendance, j'ai du mal à saisir la nuance entre ...
Globalmarkets79 Thank you Vonasi for the answer. I have an other question. When i tried to run the indicator...
Vonasi Lines is either 0 or 1 to turn on or off the drawing of them. Once again if you download and...
Globalmarkets79 Thank you Vonasi, this indicator is very helpful!!!
Nicolas
5 years ago
Bateson Merci pour la réponse Nicolas. C'est bien ce que j'ai fait mais ça ne fonctionne toujours pa...
Enzo Paliotti Veramente ottimo, era quello che cercavo, si potrebbe modificare inserendo come variazione a...
Nicolas Perché no, chiedetelo con una descrizione dettagliata nel forum degli indicatori, per favore!
jiddan78 how to convert to afl amibroker ?
Nicolas We do not supply free coding assistance for AFL Amibroker on the website. You can ask for pa...
Ngomsi @ Vonasi, how to use timeframe , 13 minutes ,21 minutes, 34 minutes,et 55 minutes with this...
manchokcity can we have it in mql4 platform? or how or which platform do we use it?
camporan I don't use MetaTrader so I won't be able to do the translation myself. Sorry!
Alexander9 This can for amibroker ? . Thanks

Top