Madrid Moving Average Ribbons for ThinkorSwim

Xiuying

Xiuying

New member
Found this on TradingView and ended up Converting it to TOS.

Been using it on and off the past few days and have been liking it a lot. It's just basic EMA's starting from 5 and increasing by 5 for each level until 100. Seems straight forward on when to get out on a stock that is running.

Code:
#Ended up Converting this script I found on TradingView which was called "Madrid Moving Average Ribbon" and recreated it in TOS
#http://madridjourneyonws.blogspot.com/

#This plots a moving average ribbon, either exponential or standard.
#This study is best viewed with a dark background.  It provides an easy
#and fast way to determine the trend direction and possible reversals.

# Green : Uptrend. Long trading
# Dark Green : Reentry (buy the dip) or downtrend reversal warning
# Red : Downtrend. Short trading
# Dark Red : Short Reentry (sell the peak) or uptrend reversal warning

# To best determine if this is a reentry point or a trend reversal
# the MMARB (Madrid Moving Average Ribbon Bar) study is used.
# This is the bar located at the bottom.  This bar signals when a
# current trend reentry is found (partially filled with opposite dark color)
# or when a trend reversal is ahead (completely filled with opposite dark color).

#Converted/Ported by Xiuying 7/14/2018

input price = close;



plot ma05 = ExpAverage(price, 5);
plot ma10 = ExpAverage(price, 10);
plot ma15 = ExpAverage(price, 15);
plot ma20 = ExpAverage(price, 20);
plot ma25 = ExpAverage(price, 25);
plot ma30 = ExpAverage(price, 30);
plot ma35 = ExpAverage(price, 35);
plot ma40 = ExpAverage(price, 40);
plot ma45 = ExpAverage(price, 45);
plot ma50 = ExpAverage(price, 50);
plot ma55 = ExpAverage(price, 55);
plot ma60 = ExpAverage(price, 60);
plot ma65 = ExpAverage(price, 65);
plot ma70 = ExpAverage(price, 70);
plot ma75 = ExpAverage(price, 75);
plot ma80 = ExpAverage(price, 80);
plot ma85 = ExpAverage(price, 85);
plot ma90 = ExpAverage(price, 90);
plot ma95 = ExpAverage(price, 95);
plot ma100 = ExpAverage(price, 100);


ma05.AssignValueColor( if ma05 >= ma05[1] and ma05>ma100 then color.Green  else if ma05 < ma05[1] and ma05>ma100 then color.Dark_red else if ma05<= ma05[1] and ma05 <ma100 then color.red else if ma05 >= ma05[1] and ma05 < ma100 then color.Dark_green else color.gray);

ma10.AssignValueColor(if ma10 >= ma10[1] and ma05>ma100
then color.Green  else if ma10 < ma10[1] and ma05>ma100
then color.Dark_red else if ma10<= ma10[1] and ma05 <ma100
then color.red else if ma10 >= ma10[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma15.AssignValueColor(if ma15 >= ma15[1] and ma05>ma100
then color.Green  else if ma15 < ma15[1] and ma05>ma100
then color.Dark_red else if ma15<= ma15[1] and ma05 <ma100
then color.red else if ma15 >= ma15[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma20.AssignValueColor(if ma20 >= ma20[1] and ma05>ma100
then color.Green  else if ma20 < ma20[1] and ma05>ma100
then color.Dark_red else if ma20<= ma20[1] and ma05 <ma100
then color.red else if ma20 >= ma20[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma25.AssignValueColor(if ma25 >= ma25[1] and ma05>ma100
then color.Green  else if ma25 < ma25[1] and ma05>ma100
then color.Dark_red else if ma25<= ma25[1] and ma05 <ma100
then color.red else if ma25 >= ma25[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma30.AssignValueColor(if ma30 >= ma30[1] and ma05>ma100
then color.Green  else if ma30 < ma30[1] and ma05>ma100
then color.Dark_red else if ma30<= ma30[1] and ma05 <ma100
then color.red else if ma30 >= ma30[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma35.AssignValueColor(if ma35 >= ma35[1] and ma05>ma100
then color.Green  else if ma35 < ma35[1] and ma05>ma100
then color.Dark_red else if ma35<= ma35[1] and ma05 <ma100
then color.red else if ma35 >= ma35[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma40.AssignValueColor(if ma40 >= ma40[1] and ma05>ma100
then color.Green  else if ma40 < ma40[1] and ma05>ma100
then color.Dark_red else if ma40<= ma40[1] and ma05 <ma100
then color.red else if ma40 >= ma40[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma45.AssignValueColor(if ma45 >= ma45[1] and ma05>ma100
then color.Green  else if ma45 < ma45[1] and ma05>ma100
then color.Dark_red else if ma45<= ma45[1] and ma05 <ma100
then color.red else if ma45 >= ma45[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma50.AssignValueColor(if ma50 >= ma50[1] and ma05>ma100
then color.Green  else if ma50 < ma50[1] and ma05>ma100
then color.Dark_red else if ma50<= ma50[1] and ma05 <ma100
then color.red else if ma50 >= ma50[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma55.AssignValueColor(if ma55 >= ma55[1] and ma05>ma100
then color.Green  else if ma55 < ma55[1] and ma05>ma100
then color.Dark_red else if ma55<= ma55[1] and ma05 <ma100
then color.red else if ma55 >= ma55[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma60.AssignValueColor(if ma60 >= ma60[1] and ma05>ma100
then color.Green  else if ma60 < ma60[1] and ma05>ma100
then color.Dark_red else if ma60<= ma60[1] and ma05 <ma100
then color.red else if ma60 >= ma60[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma65.AssignValueColor(if ma65 >= ma65[1] and ma05>ma100
then color.Green  else if ma65 < ma65[1] and ma05>ma100
then color.Dark_red else if ma65<= ma65[1] and ma05 <ma100
then color.red else if ma65 >= ma65[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma70.AssignValueColor(if ma70 >= ma70[1] and ma05>ma100
then color.Green  else if ma70 < ma70[1] and ma05>ma100
then color.Dark_red else if ma70<= ma70[1] and ma05 <ma100
then color.red else if ma70 >= ma70[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma75.AssignValueColor(if ma75 >= ma75[1] and ma05>ma100
then color.Green  else if ma75 < ma75[1] and ma05>ma100
then color.Dark_red else if ma75<= ma75[1] and ma05 <ma100
then color.red else if ma75 >= ma75[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma80.AssignValueColor(if ma80 >= ma80[1] and ma05>ma100
then color.Green  else if ma80 < ma80[1] and ma05>ma100
then color.Dark_red else if ma80<= ma80[1] and ma05 <ma100
then color.red else if ma80 >= ma80[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma85.AssignValueColor(if ma85 >= ma85[1] and ma05>ma100
then color.Green  else if ma85 < ma85[1] and ma05>ma100
then color.Dark_red else if ma85<= ma85[1] and ma05 <ma100
then color.red else if ma85 >= ma85[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma90.AssignValueColor(if ma90 >= ma90[1] and ma05>ma100
then color.Green  else if ma90 < ma90[1] and ma05>ma100
then color.Dark_red else if ma90<= ma90[1] and ma05 <ma100
then color.red else if ma90 >= ma90[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma95.AssignValueColor(if ma95 >= ma95[1] and ma05>ma100
then color.Green  else if ma95 < ma95[1] and ma05>ma100
then color.Dark_red else if ma95<= ma95[1] and ma05 <ma100
then color.red else if ma95 >= ma95[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma100.AssignValueColor(if ma100 >= ma100[1] and ma05>ma100
then color.Green  else if ma100 < ma100[1] and ma05>ma100
then color.Dark_red else if ma100<= ma100[1] and ma05 <ma100
then color.red else if ma100 >= ma100[1] and ma05 < ma100
then color.Dark_green else color.gray);




https://www.tradingview.com/script/1JKqmEKy-Madrid-Moving-Average-Ribbon/
https://tos.mx/XV3Nomw
Updated: Added the Lower Study that is suppose to go with the Ribbons called MMARB. Added an option to change the width, However with my eyes it's still tripping me a bit out looking at it.

https://tos.mx/ji96cTz

Code:
#Ended up Converting this script I found on TradingView which was called "MMARB" and recreated it in TOS
#http://madridjourneyonws.blogspot.com/

#This plots a moving average ribbon, either exponential or standard.
#This study is best viewed with a dark background.  It provides an easy
#and fast way to determine the trend direction and possible reversals.

# Green : Uptrend. Long trading
# Dark Green : Reentry (buy the dip) or downtrend reversal warning
# Red : Downtrend. Short trading
# Dark Red : Short Reentry (sell the peak) or uptrend reversal warning

# To best determine if this is a reentry point or a trend reversal
# the MMARB (Madrid Moving Average Ribbon Bar) study is used.
# This is the bar located at the bottom.  This bar signals when a
# current trend reentry is found (partially filled with opposite dark color)
# or when a trend reversal is ahead (completely filled with opposite dark color).
#This is to go along with Madrid Ribbons

#Converted/Ported by Xiuying 7/15/2018

Declare Lower;

input price = close;
input Width = 3;


def ma05 = ExpAverage(price, 5);
def ma10 = ExpAverage(price, 10);
def ma15 = ExpAverage(price, 15);
def ma20 = ExpAverage(price, 20);
def ma25 = ExpAverage(price, 25);
def ma30 = ExpAverage(price, 30);
def ma35 = ExpAverage(price, 35);
def ma40 = ExpAverage(price, 40);
def ma45 = ExpAverage(price, 45);
def ma50 = ExpAverage(price, 50);
def ma55 = ExpAverage(price, 55);
def ma60 = ExpAverage(price, 60);
def ma65 = ExpAverage(price, 65);
def ma70 = ExpAverage(price, 70);
def ma75 = ExpAverage(price, 75);
def ma80 = ExpAverage(price, 80);
def ma85 = ExpAverage(price, 85);
def ma90 = ExpAverage(price, 90);
def ma95 = ExpAverage(price, 95);
def ma100 = ExpAverage(price, 100);

plot ma5 = 5;
plot ma010 = 10;
plot ma015 = 15;
plot ma020 = 20;
plot ma025 = 25;
plot ma030 = 30;
plot ma035 = 35;
plot ma040 = 40;
plot ma045 = 45;
plot ma050 = 50;
plot ma055 = 55;
plot ma060 = 60;
plot ma065 = 65;
plot ma070 = 70;
plot ma075 = 75;
plot ma080 = 80;
plot ma085 = 85;
plot ma090 = 90;
plot ma095 = 95;
plot ma0100 = 100;


ma5.AssignValueColor( if ma05 >= ma05[1] and ma05>ma100 then color.Green  else if ma05 < ma05[1] and ma05>ma100 then color.Dark_red else if ma05<= ma05[1] and ma05 <ma100 then color.red else if ma05 >= ma05[1] and ma05 < ma100 then color.Dark_green else color.gray);


ma010.AssignValueColor(if ma10 >= ma10[1] and ma05>ma100
then color.Green  else if ma10 < ma10[1] and ma05>ma100
then color.Dark_red else if ma10<= ma10[1] and ma05 <ma100
then color.red else if ma10 >= ma10[1] and ma05 < ma100
then color.Dark_green else color.gray);


ma015.AssignValueColor(if ma15 >= ma15[1] and ma05>ma100
then color.Green  else if ma15 < ma15[1] and ma05>ma100
then color.Dark_red else if ma15<= ma15[1] and ma05 <ma100
then color.red else if ma15 >= ma15[1] and ma05 < ma100
then color.Dark_green else color.gray);


ma020.AssignValueColor(if ma20 >= ma20[1] and ma05>ma100
then color.Green  else if ma20 < ma20[1] and ma05>ma100
then color.Dark_red else if ma20<= ma20[1] and ma05 <ma100
then color.red else if ma20 >= ma20[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma025.AssignValueColor(if ma25 >= ma25[1] and ma05>ma100
then color.Green  else if ma25 < ma25[1] and ma05>ma100
then color.Dark_red else if ma25<= ma25[1] and ma05 <ma100
then color.red else if ma25 >= ma25[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma030.AssignValueColor(if ma30 >= ma30[1] and ma05>ma100
then color.Green  else if ma30 < ma30[1] and ma05>ma100
then color.Dark_red else if ma30<= ma30[1] and ma05 <ma100
then color.red else if ma30 >= ma30[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma035.AssignValueColor(if ma35 >= ma35[1] and ma05>ma100
then color.Green  else if ma35 < ma35[1] and ma05>ma100
then color.Dark_red else if ma35<= ma35[1] and ma05 <ma100
then color.red else if ma35 >= ma35[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma040.AssignValueColor(if ma40 >= ma40[1] and ma05>ma100
then color.Green  else if ma40 < ma40[1] and ma05>ma100
then color.Dark_red else if ma40<= ma40[1] and ma05 <ma100
then color.red else if ma40 >= ma40[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma045.AssignValueColor(if ma45 >= ma45[1] and ma05>ma100
then color.Green  else if ma45 < ma45[1] and ma05>ma100
then color.Dark_red else if ma45<= ma45[1] and ma05 <ma100
then color.red else if ma45 >= ma45[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma050.AssignValueColor(if ma50 >= ma50[1] and ma05>ma100
then color.Green  else if ma50 < ma50[1] and ma05>ma100
then color.Dark_red else if ma50<= ma50[1] and ma05 <ma100
then color.red else if ma50 >= ma50[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma055.AssignValueColor(if ma55 >= ma55[1] and ma05>ma100
then color.Green  else if ma55 < ma55[1] and ma05>ma100
then color.Dark_red else if ma55<= ma55[1] and ma05 <ma100
then color.red else if ma55 >= ma55[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma060.AssignValueColor(if ma60 >= ma60[1] and ma05>ma100
then color.Green  else if ma60 < ma60[1] and ma05>ma100
then color.Dark_red else if ma60<= ma60[1] and ma05 <ma100
then color.red else if ma60 >= ma60[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma065.AssignValueColor(if ma65 >= ma65[1] and ma05>ma100
then color.Green  else if ma65 < ma65[1] and ma05>ma100
then color.Dark_red else if ma65<= ma65[1] and ma05 <ma100
then color.red else if ma65 >= ma65[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma070.AssignValueColor(if ma70 >= ma70[1] and ma05>ma100
then color.Green  else if ma70 < ma70[1] and ma05>ma100
then color.Dark_red else if ma70<= ma70[1] and ma05 <ma100
then color.red else if ma70 >= ma70[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma075.AssignValueColor(if ma75 >= ma75[1] and ma05>ma100
then color.Green  else if ma75 < ma75[1] and ma05>ma100
then color.Dark_red else if ma75<= ma75[1] and ma05 <ma100
then color.red else if ma75 >= ma75[1] and ma05 < ma100
then color.Dark_green else color.gray);


ma080.AssignValueColor(if ma80 >= ma80[1] and ma05>ma100
then color.Green  else if ma80 < ma80[1] and ma05>ma100
then color.Dark_red else if ma80<= ma80[1] and ma05 <ma100
then color.red else if ma80 >= ma80[1] and ma05 < ma100
then color.Dark_green else color.gray);


ma085.AssignValueColor(if ma85 >= ma85[1] and ma05>ma100
then color.Green  else if ma85 < ma85[1] and ma05>ma100
then color.Dark_red else if ma85<= ma85[1] and ma05 <ma100
then color.red else if ma85 >= ma85[1] and ma05 < ma100
then color.Dark_green else color.gray);


ma090.AssignValueColor(if ma90 >= ma90[1] and ma05>ma100
then color.Green  else if ma90 < ma90[1] and ma05>ma100
then color.Dark_red else if ma90<= ma90[1] and ma05 <ma100
then color.red else if ma90 >= ma90[1] and ma05 < ma100
then color.Dark_green else color.gray);


ma095.AssignValueColor(if ma95 >= ma95[1] and ma05>ma100
then color.Green  else if ma95 < ma95[1] and ma05>ma100
then color.Dark_red else if ma95<= ma95[1] and ma05 <ma100
then color.red else if ma95 >= ma95[1] and ma05 < ma100
then color.Dark_green else color.gray);


ma0100.AssignValueColor(if ma100 >= ma100[1] and ma05>ma100
then color.Green  else if ma100 < ma100[1] and ma05>ma100
then color.Dark_red else if ma100<= ma100[1] and ma05 <ma100
then color.red else if ma100 >= ma100[1] and ma05 < ma100
then color.Dark_green else color.gray);

ma5 .setLineWeight(width);
ma010 .setLineWeight(width);
ma015 .setLineWeight(width);
ma020 .setLineWeight(width);
ma025 .setLineWeight(width);
ma030 .setLineWeight(width);
ma035 .setLineWeight(width);
ma040 .setLineWeight(width);
ma045 .setLineWeight(width);
ma050 .setLineWeight(width);
ma055 .setLineWeight(width);
ma060 .setLineWeight(width);
ma065 .setLineWeight(width);
ma070 .setLineWeight(width);
ma075 .setLineWeight(width);
ma080 .setLineWeight(width);
ma085 .setLineWeight(width);
ma090 .setLineWeight(width);
ma095 .setLineWeight(width);
ma0100 .setLineWeight(width);
 
Last edited:
G

gjervis

New member
2019 Donor
VIP
Nice Xiuying, i copied the code, however i am not seeing the bar at the bottom
 
technicallydreaming

technicallydreaming

Member
Visually, this is one of the coolest looking studies I have seen. Thank you. The lower study is a bit confusing, but I think I get the basics. Anyone can provide more detail on it?
 
scott69

scott69

New member
Very nice visually. I've been using MA rainbows (ribbons) for several decades, first starting in excel charts, then in Metastock charts, and now in TOS. I've kept it simple to identify a trend and strength. On a 15 minute chart (I trade on 1 minute chart) , I have 5 different color MAs, 20, 40, 60, 80, 100 periods. That MA rainbow and a 14 period wilder ADX. That's it for larger period trend identification. When the ribbon MAs cross and start to expand, with rising ADX, that is time to look for a trigger on 1 minute chart. I try to keep it very simple, so for me the fewer MAs, the easier it is to see the crosses. Ultimately I will probably code some of my ideas so they are signaled programmatically, but for now it is all visual for me. Your study visually shows more "power" or "strength" if I can use those words.
 

Similar threads

Top