All The Moving Average Ribbons for ThinkorSwim

Xiuying

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);

TV.png

TOS.png


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:
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

Active 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.
 

Chemmy

Member
VIP
Hi, hopefully this is what you're looking for:

UyyYxPL.png


The code is a bit brute-force, and I'm sure it can be improved with a script, but this should do the job for now:

Code:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Violent
#//@version=4
#study("Moving Average Ribbon", shorttitle="MAR", overlay=true)
## ported by Chemmy for usethinkscript.com

input src = close;
input ma = averagetype.Simple;
input length = 1;
input start = 5;
input maNumber = 32;

def count = length * start;

def getMa = count + (length * 0);

plot ma1 = MovingAverage(ma, src, (count + (length * 0)));
ma1.sethiding(maNumber<1);
ma1.assignValueColor(if ma1>src then color.CYAN else color.MAGENTA);

plot ma2 = MovingAverage(ma, src, (count + (length * 1)));
ma2.sethiding(maNumber<2);
ma2.assignValueColor(if ma2>src then color.CYAN else color.MAGENTA);

plot ma3 = MovingAverage(ma, src, (count + (length * 2)));
ma3.sethiding(maNumber<3);
ma3.assignValueColor(if ma3>src then color.CYAN else color.MAGENTA);

plot ma4 = MovingAverage(ma, src, (count + (length * 3)));
ma4.sethiding(maNumber<4);
ma4.assignValueColor(if ma4>src then color.CYAN else color.MAGENTA);

plot ma5 = MovingAverage(ma, src, (count + (length * 4)));
ma5.sethiding(maNumber<5);
ma5.assignValueColor(if ma5>src then color.CYAN else color.MAGENTA);

plot ma6 = MovingAverage(ma, src, (count + (length * 5)));
ma6.sethiding(maNumber<6);
ma6.assignValueColor(if ma6>src then color.CYAN else color.MAGENTA);

plot ma7 = MovingAverage(ma, src, (count + (length * 6)));
ma7.sethiding(maNumber<7);
ma7.assignValueColor(if ma7>src then color.CYAN else color.MAGENTA);

plot ma8 = MovingAverage(ma, src, (count + (length * 7)));
ma8.sethiding(maNumber<8);
ma8.assignValueColor(if ma8>src then color.CYAN else color.MAGENTA);

plot ma9 = MovingAverage(ma, src, (count + (length * 8)));
ma9.sethiding(maNumber<9);
ma9.assignValueColor(if ma9>src then color.CYAN else color.MAGENTA);

plot ma10 = MovingAverage(ma, src, (count + (length * 9)));
ma10.sethiding(maNumber<10);
ma10.assignValueColor(if ma10>src then color.CYAN else color.MAGENTA);

plot ma11 = MovingAverage(ma, src, (count + (length * 10)));
ma11.sethiding(maNumber<1);
ma11.assignValueColor(if ma11>src then color.CYAN else color.MAGENTA);

plot ma12 = MovingAverage(ma, src, (count + (length * 11)));
ma12.sethiding(maNumber<12);
ma12.assignValueColor(if ma12>src then color.CYAN else color.MAGENTA);

plot ma13 = MovingAverage(ma, src, (count + (length * 12)));
ma13.sethiding(maNumber<13);
ma13.assignValueColor(if ma13>src then color.CYAN else color.MAGENTA);

plot ma14 = MovingAverage(ma, src, (count + (length * 13)));
ma14.sethiding(maNumber<14);
ma14.assignValueColor(if ma14>src then color.CYAN else color.MAGENTA);

plot ma15 = MovingAverage(ma, src, (count + (length * 14)));
ma15.sethiding(maNumber<15);
ma15.assignValueColor(if ma15>src then color.CYAN else color.MAGENTA);

plot ma16 = MovingAverage(ma, src, (count + (length * 15)));
ma16.sethiding(maNumber<16);
ma16.assignValueColor(if ma16>src then color.CYAN else color.MAGENTA);

plot ma17 = MovingAverage(ma, src, (count + (length * 16)));
ma17.sethiding(maNumber<17);
ma17.assignValueColor(if ma17>src then color.CYAN else color.MAGENTA);

plot ma18 = MovingAverage(ma, src, (count + (length * 17)));
ma18.sethiding(maNumber<18);
ma18.assignValueColor(if ma18>src then color.CYAN else color.MAGENTA);

plot ma19 = MovingAverage(ma, src, (count + (length * 18)));
ma19.sethiding(maNumber<19);
ma19.assignValueColor(if ma19>src then color.CYAN else color.MAGENTA);

plot ma20 = MovingAverage(ma, src, (count + (length * 19)));
ma20.sethiding(maNumber<20);
ma20.assignValueColor(if ma20>src then color.CYAN else color.MAGENTA);

plot ma21 = MovingAverage(ma, src, (count + (length * 20)));
ma21.sethiding(maNumber<21);
ma21.assignValueColor(if ma21>src then color.CYAN else color.MAGENTA);

plot ma22 = MovingAverage(ma, src, (count + (length * 21)));
ma22.sethiding(maNumber<22);
ma22.assignValueColor(if ma22>src then color.CYAN else color.MAGENTA);

plot ma23 = MovingAverage(ma, src, (count + (length * 22)));
ma23.sethiding(maNumber<23);
ma23.assignValueColor(if ma23>src then color.CYAN else color.MAGENTA);

plot ma24 = MovingAverage(ma, src, (count + (length * 23)));
ma24.sethiding(maNumber<24);
ma24.assignValueColor(if ma24>src then color.CYAN else color.MAGENTA);

plot ma25 = MovingAverage(ma, src, (count + (length * 24)));
ma25.sethiding(maNumber<25);
ma25.assignValueColor(if ma25>src then color.CYAN else color.MAGENTA);

plot ma26 = MovingAverage(ma, src, (count + (length * 25)));
ma26.sethiding(maNumber<26);
ma26.assignValueColor(if ma26>src then color.CYAN else color.MAGENTA);

plot ma27 = MovingAverage(ma, src, (count + (length * 26)));
ma27.sethiding(maNumber<27);
ma27.assignValueColor(if ma27>src then color.CYAN else color.MAGENTA);

plot ma28 = MovingAverage(ma, src, (count + (length * 27)));
ma28.sethiding(maNumber<28);
ma28.assignValueColor(if ma28>src then color.CYAN else color.MAGENTA);

plot ma29 = MovingAverage(ma, src, (count + (length * 28)));
ma29.sethiding(maNumber<29);
ma29.assignValueColor(if ma29>src then color.CYAN else color.MAGENTA);

plot ma30 = MovingAverage(ma, src, (count + (length * 29)));
ma30.sethiding(maNumber<30);
ma30.assignValueColor(if ma30>src then color.CYAN else color.MAGENTA);

plot ma31 = MovingAverage(ma, src, (count + (length * 30)));
ma31.sethiding(maNumber<31);
ma31.assignValueColor(if ma31>src then color.CYAN else color.MAGENTA);

plot ma32 = MovingAverage(ma, src, (count + (length * 31)));
ma32.sethiding(maNumber<32);
ma32.assignValueColor(if ma32>src then color.CYAN else color.MAGENTA);

#END CODE
 

Cybersloth

New member
VIP
Hi, hopefully this is what you're looking for:

UyyYxPL.png


The code is a bit brute-force, and I'm sure it can be improved with a script, but this should do the job for now:

Code:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Violent
#//@version=4
#study("Moving Average Ribbon", shorttitle="MAR", overlay=true)
## ported by Chemmy for usethinkscript.com

input src = close;
input ma = averagetype.Simple;
input length = 1;
input start = 5;
input maNumber = 32;

def count = length * start;

def getMa = count + (length * 0);

plot ma1 = MovingAverage(ma, src, (count + (length * 0)));
ma1.sethiding(maNumber<1);
ma1.assignValueColor(if ma1>src then color.CYAN else color.MAGENTA);

plot ma2 = MovingAverage(ma, src, (count + (length * 1)));
ma2.sethiding(maNumber<2);
ma2.assignValueColor(if ma2>src then color.CYAN else color.MAGENTA);

plot ma3 = MovingAverage(ma, src, (count + (length * 2)));
ma3.sethiding(maNumber<3);
ma3.assignValueColor(if ma3>src then color.CYAN else color.MAGENTA);

plot ma4 = MovingAverage(ma, src, (count + (length * 3)));
ma4.sethiding(maNumber<4);
ma4.assignValueColor(if ma4>src then color.CYAN else color.MAGENTA);

plot ma5 = MovingAverage(ma, src, (count + (length * 4)));
ma5.sethiding(maNumber<5);
ma5.assignValueColor(if ma5>src then color.CYAN else color.MAGENTA);

plot ma6 = MovingAverage(ma, src, (count + (length * 5)));
ma6.sethiding(maNumber<6);
ma6.assignValueColor(if ma6>src then color.CYAN else color.MAGENTA);

plot ma7 = MovingAverage(ma, src, (count + (length * 6)));
ma7.sethiding(maNumber<7);
ma7.assignValueColor(if ma7>src then color.CYAN else color.MAGENTA);

plot ma8 = MovingAverage(ma, src, (count + (length * 7)));
ma8.sethiding(maNumber<8);
ma8.assignValueColor(if ma8>src then color.CYAN else color.MAGENTA);

plot ma9 = MovingAverage(ma, src, (count + (length * 8)));
ma9.sethiding(maNumber<9);
ma9.assignValueColor(if ma9>src then color.CYAN else color.MAGENTA);

plot ma10 = MovingAverage(ma, src, (count + (length * 9)));
ma10.sethiding(maNumber<10);
ma10.assignValueColor(if ma10>src then color.CYAN else color.MAGENTA);

plot ma11 = MovingAverage(ma, src, (count + (length * 10)));
ma11.sethiding(maNumber<1);
ma11.assignValueColor(if ma11>src then color.CYAN else color.MAGENTA);

plot ma12 = MovingAverage(ma, src, (count + (length * 11)));
ma12.sethiding(maNumber<12);
ma12.assignValueColor(if ma12>src then color.CYAN else color.MAGENTA);

plot ma13 = MovingAverage(ma, src, (count + (length * 12)));
ma13.sethiding(maNumber<13);
ma13.assignValueColor(if ma13>src then color.CYAN else color.MAGENTA);

plot ma14 = MovingAverage(ma, src, (count + (length * 13)));
ma14.sethiding(maNumber<14);
ma14.assignValueColor(if ma14>src then color.CYAN else color.MAGENTA);

plot ma15 = MovingAverage(ma, src, (count + (length * 14)));
ma15.sethiding(maNumber<15);
ma15.assignValueColor(if ma15>src then color.CYAN else color.MAGENTA);

plot ma16 = MovingAverage(ma, src, (count + (length * 15)));
ma16.sethiding(maNumber<16);
ma16.assignValueColor(if ma16>src then color.CYAN else color.MAGENTA);

plot ma17 = MovingAverage(ma, src, (count + (length * 16)));
ma17.sethiding(maNumber<17);
ma17.assignValueColor(if ma17>src then color.CYAN else color.MAGENTA);

plot ma18 = MovingAverage(ma, src, (count + (length * 17)));
ma18.sethiding(maNumber<18);
ma18.assignValueColor(if ma18>src then color.CYAN else color.MAGENTA);

plot ma19 = MovingAverage(ma, src, (count + (length * 18)));
ma19.sethiding(maNumber<19);
ma19.assignValueColor(if ma19>src then color.CYAN else color.MAGENTA);

plot ma20 = MovingAverage(ma, src, (count + (length * 19)));
ma20.sethiding(maNumber<20);
ma20.assignValueColor(if ma20>src then color.CYAN else color.MAGENTA);

plot ma21 = MovingAverage(ma, src, (count + (length * 20)));
ma21.sethiding(maNumber<21);
ma21.assignValueColor(if ma21>src then color.CYAN else color.MAGENTA);

plot ma22 = MovingAverage(ma, src, (count + (length * 21)));
ma22.sethiding(maNumber<22);
ma22.assignValueColor(if ma22>src then color.CYAN else color.MAGENTA);

plot ma23 = MovingAverage(ma, src, (count + (length * 22)));
ma23.sethiding(maNumber<23);
ma23.assignValueColor(if ma23>src then color.CYAN else color.MAGENTA);

plot ma24 = MovingAverage(ma, src, (count + (length * 23)));
ma24.sethiding(maNumber<24);
ma24.assignValueColor(if ma24>src then color.CYAN else color.MAGENTA);

plot ma25 = MovingAverage(ma, src, (count + (length * 24)));
ma25.sethiding(maNumber<25);
ma25.assignValueColor(if ma25>src then color.CYAN else color.MAGENTA);

plot ma26 = MovingAverage(ma, src, (count + (length * 25)));
ma26.sethiding(maNumber<26);
ma26.assignValueColor(if ma26>src then color.CYAN else color.MAGENTA);

plot ma27 = MovingAverage(ma, src, (count + (length * 26)));
ma27.sethiding(maNumber<27);
ma27.assignValueColor(if ma27>src then color.CYAN else color.MAGENTA);

plot ma28 = MovingAverage(ma, src, (count + (length * 27)));
ma28.sethiding(maNumber<28);
ma28.assignValueColor(if ma28>src then color.CYAN else color.MAGENTA);

plot ma29 = MovingAverage(ma, src, (count + (length * 28)));
ma29.sethiding(maNumber<29);
ma29.assignValueColor(if ma29>src then color.CYAN else color.MAGENTA);

plot ma30 = MovingAverage(ma, src, (count + (length * 29)));
ma30.sethiding(maNumber<30);
ma30.assignValueColor(if ma30>src then color.CYAN else color.MAGENTA);

plot ma31 = MovingAverage(ma, src, (count + (length * 30)));
ma31.sethiding(maNumber<31);
ma31.assignValueColor(if ma31>src then color.CYAN else color.MAGENTA);

plot ma32 = MovingAverage(ma, src, (count + (length * 31)));
ma32.sethiding(maNumber<32);
ma32.assignValueColor(if ma32>src then color.CYAN else color.MAGENTA);

#END CODE
@Chemmy and @Xiuying , thank you for posting this study and the just-posted variation. While the most straightforward way to utilize this indicator appears to be to wait until all the moving averages have transitioned to one color or another, I'm curious if you make other use of it, and how you interpret/manage the breeching of one or more moving averages once a trend is established? Also, do you use the indicator differently (or at all) when candles are located in the thick of one or both of the colors, and if so, how? Many thanks and thank you again for providing the studies here.
 

samer800

Well-known member
Can anyone help to convert this from TV to TOS? thank you!
https://www.tradingview.com/script/79wPF2EE-Moving-Average-Ribbon/
check out the below.

CODE

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at
#// © Violent
#study("Moving Average Ribbon", shorttitle="MAR", overlay=true)
# Converted and mod by [email protected] - 10/2022

input source =   close;#, "Source")
input Theme  =  {Default Select, Theme1, Theme2};
input ma =   {default SMA, EMA, WMA, McGinley};
input baseLength =   1;    # "Length"
input increment  =    5;    # "Start"
input NoOfMovingAvg = 32;   # "No. of MAs"
input colourFrom = no; # "Colour option"
input showRibbon = no;
input ShowCloud = yes;
input ShowTrendLine = yes;

def na = Double.NaN;
DefineGlobalColor("teal",if Theme == Theme.Theme2 then CreateColor(4,156,179) else
                         if Theme == Theme.Theme1 then CreateColor(178,181,190) else Color.DARK_GREEN);
DefineGlobalColor("purple",if Theme == Theme.Theme2 then CreateColor(123,3,143) else
                           if Theme == Theme.Theme1 then Color.DARK_GRAY else Color.DARK_RED);
def maNumber = if NoOfMovingAvg<=0 then 1 else if NoOfMovingAvg>32 then 32 else NoOfMovingAvg;
def Length   = if baseLength<=0 then 1 else baseLength;
def start    = if increment<=0 then 1 else increment;
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [
script nz {
    input data  = close;
    def ret_val = if isNaN(data) then 0 else data;
    plot return = ret_val;
}

#export mcginley(float src, simple int len)=>
script mcginley {
    input src = close;
    input len = 14;
    def mg;
    def t = ExpAverage(src, len);
    mg = if IsNaN(mg[1]) then t else
        CompoundValue(1 ,mg[1] + (src - mg[1]) / (len * Power(src / mg[1], 4)),src);
    plot return = mg;
}

#getMa(c, ma, src, length, start)=>
script getMa {
    input c = 0;
    input type = "SMA";
    input source = close;
    input length = 1;
    input start = 5;
    def count = length * start;
    def len = count + (length * c);
    def avg =
        if type == "SMA"    then SimpleMovingAvg(source, len) else
        if type == "EMA"    then ExpAverage(source, len) else
        if type == "WMA"    then WMA(source, len) else
        if type == "McGinley" then mcginley(source, len) else Double.NaN;
    plot return = avg;
}
def sma1 =  if maNumber >= 1  then getMa(0, ma, source, length, start) else na;
def sma2 =  if maNumber >= 2  then getMa(1, ma, source, length, start) else na;
def sma3 =  if maNumber >= 3  then getMa(2, ma, source, length, start) else na;
def sma4 =  if maNumber >= 4  then getMa(3, ma, source, length, start) else na;
def sma5 =  if maNumber >= 5  then getMa(4, ma, source, length, start) else na;
def sma6 =  if maNumber >= 6  then getMa(5, ma, source, length, start) else na;
def sma7 =  if maNumber >= 7  then getMa(6, ma, source, length, start) else na;
def sma8 =  if maNumber >= 8  then getMa(7, ma, source, length, start) else na;
def sma9 =  if maNumber >= 9  then getMa(8, ma, source, length, start) else na;
def sma10 = if maNumber >= 10 then getMa(9, ma, source, length, start) else na;
def sma11 = if maNumber >= 11 then getMa(10, ma, source, length, start) else na;
def sma12 = if maNumber >= 12 then getMa(11, ma, source, length, start) else na;
def sma13 = if maNumber >= 13 then getMa(12, ma, source, length, start) else na;
def sma14 = if maNumber >= 14 then getMa(13, ma, source, length, start) else na;
def sma15 = if maNumber >= 15 then getMa(14, ma, source, length, start) else na;
def sma16 = if maNumber >= 16 then getMa(15, ma, source, length, start) else na;
def sma17 = if maNumber >= 17 then getMa(16, ma, source, length, start) else na;
def sma18 = if maNumber >= 18 then getMa(17, ma, source, length, start) else na;
def sma19 = if maNumber >= 19 then getMa(18, ma, source, length, start) else na;
def sma20 = if maNumber >= 20 then getMa(19, ma, source, length, start) else na;
def sma21 = if maNumber >= 21 then getMa(20, ma, source, length, start) else na;
def sma22 = if maNumber >= 22 then getMa(21, ma, source, length, start) else na;
def sma23 = if maNumber >= 23 then getMa(22, ma, source, length, start) else na;
def sma24 = if maNumber >= 24 then getMa(23, ma, source, length, start) else na;
def sma25 = if maNumber >= 25 then getMa(24, ma, source, length, start) else na;
def sma26 = if maNumber >= 26 then getMa(25, ma, source, length, start) else na;
def sma27 = if maNumber >= 27 then getMa(26, ma, source, length, start) else na;
def sma28 = if maNumber >= 28 then getMa(27, ma, source, length, start) else na;
def sma29 = if maNumber >= 29 then getMa(28, ma, source, length, start) else na;
def sma30 = if maNumber >= 30 then getMa(29, ma, source, length, start) else na;
def sma31 = if maNumber >= 31 then getMa(30, ma, source, length, start) else na;
def sma32 = if maNumber >= 32 then getMa(31, ma, source, length, start) else na;
#----avg

def sma = (sma1 + nz(sma2) + nz(sma3) + nz(sma4) + nz(sma5) + nz(sma6) + nz(sma7) + nz(sma8) + nz(sma9) + nz(sma10) + nz(sma11) + nz(sma12) + nz(sma13) + nz(sma14) + nz(sma15) + nz(sma16) + nz(sma17) + nz(sma18) + nz(sma19) + nz(sma20) + nz(sma21) + nz(sma22) + nz(sma23) + nz(sma24) + nz(sma25) + nz(sma26) + nz(sma27) + nz(sma28) + nz(sma29) + nz(sma30) + nz(sma31) + nz(sma32))/maNumber;

def smaAvg = getMa(maNumber-1, ma, sma, length, start);
plot avgLine = if !ShowTrendLine then na else smaAvg;
avgLine.AssignValueColor(if smaAvg>smaAvg[1] then GlobalColor("teal") else GlobalColor("purple"));
avgLine.SetLineWeight(2);

#--- Ribbon
def "32" = if !ShowCloud then na else sma32;#,
def "31" = if !ShowCloud then na else sma31;
def "30" = if !ShowCloud then na else sma30;
def "29" = if !ShowCloud then na else sma29;
def "28" = if !ShowCloud then na else sma28;
def "27" = if !ShowCloud then na else sma27;
def "26" = if !ShowCloud then na else sma26;
def "25" = if !ShowCloud then na else sma25;
def "24" = if !ShowCloud then na else sma24;
def "23" = if !ShowCloud then na else sma23;
def "22" = if !ShowCloud then na else sma22;
def "21" = if !ShowCloud then na else sma21;
def "20" = if !ShowCloud then na else sma20;
def "19" = if !ShowCloud then na else sma19;
def "18" = if !ShowCloud then na else sma18;
def "17" = if !ShowCloud then na else sma17;
def "16" = if !ShowCloud then na else sma16;
def "15" = if !ShowCloud then na else sma15;
def "14" = if !ShowCloud then na else sma14;
def "13" = if !ShowCloud then na else sma13;
def "12" = if !ShowCloud then na else sma12;
def "11" = if !ShowCloud then na else sma11;
def "10" = if !ShowCloud then na else sma10;
def "9" = if !ShowCloud then na else sma9;
def "8" = if !ShowCloud then na else sma8;
def "7" = if !ShowCloud then na else sma7;
def "6" = if !ShowCloud then na else sma6;
def "5" = if !ShowCloud then na else sma5;
def "4" = if !ShowCloud then na else sma4;
def "3" = if !ShowCloud then na else sma3;
def "2" = if !ShowCloud then na else sma2;
def "1" = if !ShowCloud then na else sma1;

#### Signals
AddCloud("32","31",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("31","30",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("30","29",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("29","28",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("28","27",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("27","26",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("26","25",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("25","24",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("24","23",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("23","22",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("22","21",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("21","20",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("20","19",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("19","18",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("18","17",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("17","16",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("16","15",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("15","14",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("14","13",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("13","12",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("12","11",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("11","10",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("10","9",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("9","8",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("8","7",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("7","6",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("6","5",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("5","4",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("4","3",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("3","2",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("2","1",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("1",hlc3,GlobalColor("purple"),GlobalColor("teal"),showRibbon);

#---- END CODE
 
Last edited by a moderator:

APOT7

Member
VIP
check out the below.

CODE

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at
#// © Violent
#study("Moving Average Ribbon", shorttitle="MAR", overlay=true)
# Converted and mod by [email protected] - 10/2022

input source =   close;#, "Source")
input Theme  =  {Default Select, Theme1, Theme2};
input ma =   {default SMA, EMA, WMA, McGinley};
input baseLength =   1;    # "Length"
input increment  =    5;    # "Start"
input NoOfMovingAvg = 32;   # "No. of MAs"
input colourFrom = no; # "Colour option"
input showRibbon = no;
input ShowCloud = yes;
input ShowTrendLine = yes;

def na = Double.NaN;
DefineGlobalColor("teal",if Theme == Theme.Theme2 then CreateColor(4,156,179) else
                         if Theme == Theme.Theme1 then CreateColor(178,181,190) else Color.DARK_GREEN);
DefineGlobalColor("purple",if Theme == Theme.Theme2 then CreateColor(123,3,143) else
                           if Theme == Theme.Theme1 then Color.DARK_GRAY else Color.DARK_RED);
def maNumber = if NoOfMovingAvg<=0 then 1 else if NoOfMovingAvg>32 then 32 else NoOfMovingAvg;
def Length   = if baseLength<=0 then 1 else baseLength;
def start    = if increment<=0 then 1 else increment;
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [
script nz {
    input data  = close;
    def ret_val = if isNaN(data) then 0 else data;
    plot return = ret_val;
}

#export mcginley(float src, simple int len)=>
script mcginley {
    input src = close;
    input len = 14;
    def mg;
    def t = ExpAverage(src, len);
    mg = if IsNaN(mg[1]) then t else
        CompoundValue(1 ,mg[1] + (src - mg[1]) / (len * Power(src / mg[1], 4)),src);
    plot return = mg;
}

#getMa(c, ma, src, length, start)=>
script getMa {
    input c = 0;
    input type = "SMA";
    input source = close;
    input length = 1;
    input start = 5;
    def count = length * start;
    def len = count + (length * c);
    def avg =
        if type == "SMA"    then SimpleMovingAvg(source, len) else
        if type == "EMA"    then ExpAverage(source, len) else
        if type == "WMA"    then WMA(source, len) else
        if type == "McGinley" then mcginley(source, len) else Double.NaN;
    plot return = avg;
}
def sma1 =  if maNumber >= 1  then getMa(0, ma, source, length, start) else na;
def sma2 =  if maNumber >= 2  then getMa(1, ma, source, length, start) else na;
def sma3 =  if maNumber >= 3  then getMa(2, ma, source, length, start) else na;
def sma4 =  if maNumber >= 4  then getMa(3, ma, source, length, start) else na;
def sma5 =  if maNumber >= 5  then getMa(4, ma, source, length, start) else na;
def sma6 =  if maNumber >= 6  then getMa(5, ma, source, length, start) else na;
def sma7 =  if maNumber >= 7  then getMa(6, ma, source, length, start) else na;
def sma8 =  if maNumber >= 8  then getMa(7, ma, source, length, start) else na;
def sma9 =  if maNumber >= 9  then getMa(8, ma, source, length, start) else na;
def sma10 = if maNumber >= 10 then getMa(9, ma, source, length, start) else na;
def sma11 = if maNumber >= 11 then getMa(10, ma, source, length, start) else na;
def sma12 = if maNumber >= 12 then getMa(11, ma, source, length, start) else na;
def sma13 = if maNumber >= 13 then getMa(12, ma, source, length, start) else na;
def sma14 = if maNumber >= 14 then getMa(13, ma, source, length, start) else na;
def sma15 = if maNumber >= 15 then getMa(14, ma, source, length, start) else na;
def sma16 = if maNumber >= 16 then getMa(15, ma, source, length, start) else na;
def sma17 = if maNumber >= 17 then getMa(16, ma, source, length, start) else na;
def sma18 = if maNumber >= 18 then getMa(17, ma, source, length, start) else na;
def sma19 = if maNumber >= 19 then getMa(18, ma, source, length, start) else na;
def sma20 = if maNumber >= 20 then getMa(19, ma, source, length, start) else na;
def sma21 = if maNumber >= 21 then getMa(20, ma, source, length, start) else na;
def sma22 = if maNumber >= 22 then getMa(21, ma, source, length, start) else na;
def sma23 = if maNumber >= 23 then getMa(22, ma, source, length, start) else na;
def sma24 = if maNumber >= 24 then getMa(23, ma, source, length, start) else na;
def sma25 = if maNumber >= 25 then getMa(24, ma, source, length, start) else na;
def sma26 = if maNumber >= 26 then getMa(25, ma, source, length, start) else na;
def sma27 = if maNumber >= 27 then getMa(26, ma, source, length, start) else na;
def sma28 = if maNumber >= 28 then getMa(27, ma, source, length, start) else na;
def sma29 = if maNumber >= 29 then getMa(28, ma, source, length, start) else na;
def sma30 = if maNumber >= 30 then getMa(29, ma, source, length, start) else na;
def sma31 = if maNumber >= 31 then getMa(30, ma, source, length, start) else na;
def sma32 = if maNumber >= 32 then getMa(31, ma, source, length, start) else na;
#----avg

def sma = (sma1 + nz(sma2) + nz(sma3) + nz(sma4) + nz(sma5) + nz(sma6) + nz(sma7) + nz(sma8) + nz(sma9) + nz(sma10) + nz(sma11) + nz(sma12) + nz(sma13) + nz(sma14) + nz(sma15) + nz(sma16) + nz(sma17) + nz(sma18) + nz(sma19) + nz(sma20) + nz(sma21) + nz(sma22) + nz(sma23) + nz(sma24) + nz(sma25) + nz(sma26) + nz(sma27) + nz(sma28) + nz(sma29) + nz(sma30) + nz(sma31) + nz(sma32))/maNumber;

def smaAvg = getMa(maNumber-1, ma, sma, length, start);
plot avgLine = if !ShowTrendLine then na else smaAvg;
avgLine.AssignValueColor(if smaAvg>smaAvg[1] then GlobalColor("teal") else GlobalColor("purple"));
avgLine.SetLineWeight(2);

#--- Ribbon
def "32" = if !ShowCloud then na else sma32;#,
def "31" = if !ShowCloud then na else sma31;
def "30" = if !ShowCloud then na else sma30;
def "29" = if !ShowCloud then na else sma29;
def "28" = if !ShowCloud then na else sma28;
def "27" = if !ShowCloud then na else sma27;
def "26" = if !ShowCloud then na else sma26;
def "25" = if !ShowCloud then na else sma25;
def "24" = if !ShowCloud then na else sma24;
def "23" = if !ShowCloud then na else sma23;
def "22" = if !ShowCloud then na else sma22;
def "21" = if !ShowCloud then na else sma21;
def "20" = if !ShowCloud then na else sma20;
def "19" = if !ShowCloud then na else sma19;
def "18" = if !ShowCloud then na else sma18;
def "17" = if !ShowCloud then na else sma17;
def "16" = if !ShowCloud then na else sma16;
def "15" = if !ShowCloud then na else sma15;
def "14" = if !ShowCloud then na else sma14;
def "13" = if !ShowCloud then na else sma13;
def "12" = if !ShowCloud then na else sma12;
def "11" = if !ShowCloud then na else sma11;
def "10" = if !ShowCloud then na else sma10;
def "9" = if !ShowCloud then na else sma9;
def "8" = if !ShowCloud then na else sma8;
def "7" = if !ShowCloud then na else sma7;
def "6" = if !ShowCloud then na else sma6;
def "5" = if !ShowCloud then na else sma5;
def "4" = if !ShowCloud then na else sma4;
def "3" = if !ShowCloud then na else sma3;
def "2" = if !ShowCloud then na else sma2;
def "1" = if !ShowCloud then na else sma1;

#### Signals
AddCloud("32","31",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("31","30",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("30","29",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("29","28",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("28","27",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("27","26",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("26","25",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("25","24",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("24","23",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("23","22",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("22","21",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("21","20",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("20","19",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("19","18",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("18","17",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("17","16",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("16","15",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("15","14",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("14","13",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("13","12",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("12","11",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("11","10",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("10","9",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("9","8",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("8","7",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("7","6",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("6","5",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("5","4",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("4","3",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("3","2",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("2","1",GlobalColor("purple"),GlobalColor("teal"),showRibbon);
AddCloud("1",hlc3,GlobalColor("purple"),GlobalColor("teal"),showRibbon);

#---- END CODE
I'll try it out...thank you!!
 

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Top