Slim Ribbon Chart Setup For ThinkOrSwim

bNahum

New member
somebody here posted a study i think it was called slim ribbon? Anyway, I modified it and got this. The default settings seem to work the best, but the settings are all adjustable. Use this with your filtering studies for momentum and cycles to verify the best signals, though this almost works pretty good on its own.

The filter inputs (L for long and s for short) are the SMA it uses to filter bullish/bearish trends.
the sensitivity inputs for L and S are the SMA it uses to determine which SMA will act as the exit.

**** I would like to see if someone can convert this to a strategy so i can see which settings are optimal for each equity. Can someone do that? Im SUPER curious how this would perform just as a standalone buy/sell signal.

thanks!

https://tos.mx/CEerPVb

Also, idk how to make my image into a link that would allow me to post it. ill update if i figure it out

xwr77hY.png

input price = close;

input superfast_length = 5;

input fast_length = 9;

input slow_length = 18;

input filterL = 18;

input filterS = 18;

input sensitivityL = 12;

input sensitivityS = 9;

input displace = 0;



def mov_avg5 = simpleMovingAvg(price[-displace], superfast_length);

def mov_avg9 = simpleMovingAvg(price[-displace], fast_length);

def mov_avg18 = simpleMovingAvg(price[-displace], slow_length);

def mov_avg45 = simpleMovingAvg(price[-displace], 45);

def mov_avg150 = simpleMovingAvg(price[-displace], 150);

def filter_L = simpleMovingAvg(price[-displace], filterL);

def filter_S = simpleMovingAvg(price[-displace], filterS);

def sens_L = simpleMovingAvg(price[-displace], sensitivityL);

def sens_S = simpleMovingAvg(price[-displace], sensitivityS);



#moving averages

Plot Superfast = mov_avg5;

plot Fast = mov_avg9;

plot Slow = mov_avg18;



def buy = mov_avg5 > mov_avg9 and close > filter_L;

def stopbuy = close < sens_L;# or close crosses below BollingerBands("length" = 18)."UpperBand";

def buynow = !buy[1] and buy;

def buysignal = CompoundValue(1, if buynow and !stopbuy then 1 else if buysignal[1]==1 and stopbuy then 0 else buysignal[1], 0);



plot Buy_Signal = buysignal[1] == 0 and buysignal==1;

Buy_signal.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

Buy_signal.setdefaultColor(color.GREEN);

Buy_signal.hidetitle();

Alert(condition = buysignal[1] == 0 and buysignal == 1, text = "Buy Signal", sound = Sound.Bell, "alert type" = Alert.BAR);



plot Momentum_Down = buysignal[1] ==1 and buysignal==0;

Momentum_down.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

Momentum_Down.setdefaultColor(color.cyan);

Momentum_down.hidetitle();

Alert(condition = buysignal[1] == 1 and buysignal == 0, text = "Momentum_Down", sound = Sound.Bell, "alert type" = Alert.BAR);



def sell = mov_avg5 < mov_avg9 and close < filter_S;

def stopsell = close > sens_S; #or close crosses above BollingerBands("length" = 18)."LowerBand";

def sellnow = !sell[1] and sell;

def sellsignal = CompoundValue(1, if sellnow and !stopsell then 1 else if sellsignal[1]==1 and stopsell then 0 else sellsignal[1], 0);



Plot Sell_Signal = sellsignal[1] ==0 and sellsignal;

Sell_signal.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);

sell_signal.setDefaultColor(color.red);

Sell_signal.hidetitle();

Alert(condition = sellsignal[1] == 0 and sellsignal == 1, text = "Sell Signal", sound = Sound.Bell, "alert type" = Alert.BAR);



Plot Momentum_Up = sellsignal[1]==1 and sellSignal==0;

Momentum_up.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_up);

Momentum_up.setDefaultColor(color.orange);

Momentum_up.hidetitle();

Alert(condition = sellsignal[1] == 1 and sellSignal == 0, text = "Momentum_Up", sound = Sound.Bell, "alert type" = Alert.BAR);



plot Colorbars = if buysignal ==1 then 1 else if sellsignal ==1 then 2 else if buysignal ==0 or sellsignal==0 then 3 else 0;

colorbars.hide();

Colorbars.definecolor("Buy_Signal_Bars", color.green);

Colorbars.definecolor("Sell_Signal_Bars", color.red);

Colorbars.definecolor("Neutral", color.yellow);



AssignPriceColor(if Colorbars ==1 then colorbars.color("buy_signal_bars") else if colorbars ==2 then colorbars.color("Sell_Signal_bars") else colorbars.color("neutral"));

superfast.setdefaultcolor(color.white);
fast.setdefaultColor(color.cyan);
slow.setdefaultColor(color.yellow);
#end
 
Last edited:
Give this a shot. I cleaned up some things and commented out the "def mov_avg45" and "def mov_avg150" lines, since those moving averages aren't used for anything (that I could see).

One thing to keep in mind... when you have the AddOrder commands in a script, TOS implements the orders at the open of bar after the one that triggered the buy/sell. I don't know if there's a way to change that or not, so that's how this one works.

Here's the code:
Code:
# *** Slim Ribbon Strategy ***
# In TOS, under Tools, select Add ("+"), Strategy. Delete sample code and paste this code into the window.
# Save the script, then add to your chart.

input price = close;
input superfast_length = 5;
input fast_length = 9;
input med_length = 18;
#input long_length = 45;  #this MA is not used
#input superlong_length = 150;  #this MA is not used
input filterL = 18;  #long position trend indicator
input filterS = 18;  #short position trend indicator
input sensitivityL = 12;  #defines a stop for long positions
input sensitivityS = 9;  #defines stop for short positions
input displace = 0;


def mov_avgSF = simpleMovingAvg(price[-displace], superfast_length);
def mov_avgF = simpleMovingAvg(price[-displace], fast_length);
def mov_avgM = simpleMovingAvg(price[-displace], med_length);
#def mov_avgL = simpleMovingAvg(price[-displace], long_length);  #not used
#def mov_avgSL = simpleMovingAvg(price[-displace], superlong_length);  #not used

def filter_L = simpleMovingAvg(price[-displace], filterL);
def filter_S = simpleMovingAvg(price[-displace], filterS);

def sens_L = simpleMovingAvg(price[-displace], sensitivityL);
def sens_S = simpleMovingAvg(price[-displace], sensitivityS);


#moving averages
plot Superfast = mov_avgSF;
Superfast.setdefaultcolor(color.white);
plot Fast = mov_avgF;
Fast.setdefaultColor(color.cyan);
plot Slow = mov_avgM;
Slow.setdefaultColor(color.yellow);
 

def buy = mov_avgSF > mov_avgF and close > filter_L;

def stopbuy = close < sens_L; # or close crosses below BollingerBands("length" = 18)."UpperBand";

def buynow = !buy[1] and buy;

def buySignal = CompoundValue(1, if buynow and !stopbuy then 1 else if buySignal[1] == 1 and stopbuy then 0 else buySignal[1], 0);


plot Buy_Signal = buySignal[1] == 0 and buySignal == 1;
Buy_Signal.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Buy_Signal.setdefaultColor(color.GREEN);
Buy_Signal.hidetitle();

Alert(condition = buySignal[1] == 0 and buySignal == 1, text = "Buy Signal", sound = Sound.Bell, "alert type" = Alert.BAR);

 
plot Momentum_Down = buySignal[1] == 1 and buySignal == 0;
Momentum_Down.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Momentum_Down.setdefaultColor(color.cyan);
Momentum_Down.hidetitle();

Alert(condition = buySignal[1] == 1 and buySignal == 0, text = "Momentum_Down", sound = Sound.Bell, "alert type" = Alert.BAR);

AddOrder(OrderType.BUY_TO_OPEN, Buy_Signal, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "Buy Long");
AddOrder(OrderType.SELL_TO_CLOSE, Momentum_Down, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "Sell Long");

def sell = mov_avgSF < mov_avgF and close < filter_S;

def stopsell = close > sens_S; #or close crosses above BollingerBands("length" = 18)."LowerBand";

def sellnow = !sell[1] and sell;

def sellSignal = CompoundValue(1, if sellnow and !stopsell then 1 else if sellSignal[1] == 1 and stopsell then 0 else sellSignal[1], 0);

 
Plot Sell_Signal = sellSignal[1] == 0 and sellSignal;
Sell_signal.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Sell_signal.setDefaultColor(color.red);
Sell_signal.hidetitle();

Alert(condition = sellSignal[1] == 0 and sellSignal == 1, text = "Sell Signal", sound = Sound.Bell, "alert type" = Alert.BAR);
 

Plot Momentum_Up = sellSignal[1] == 1 and sellSignal == 0;
Momentum_Up.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Momentum_Up.setDefaultColor(color.orange);
Momentum_Up.hidetitle();

Alert(condition = sellSignal[1] == 1 and sellSignal == 0, text = "Momentum_Up", sound = Sound.Bell, "alert type" = Alert.BAR);

AddOrder(OrderType.SELL_TO_OPEN, Sell_Signal, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "Sell Short");
AddOrder(OrderType.BUY_TO_CLOSE, Momentum_Up, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "Buy Short");

plot Colorbars = if buySignal == 1 then 1 else if sellSignal == 1 then 2 else if buySignal == 0 or sellSignal== 0 then 3 else 0;
Colorbars.hide();
Colorbars.definecolor("Buy_Signal_Bars", color.green);
Colorbars.definecolor("Sell_Signal_Bars", color.red);
Colorbars.definecolor("Neutral", color.yellow);
AssignPriceColor(if Colorbars == 1 then Colorbars.color("buy_signal_bars") else if Colorbars == 2 then Colorbars.color("Sell_Signal_bars") else  Colorbars.color("neutral"));

#end
 
Give this a shot. I cleaned up some things and commented out the "def mov_avg45" and "def mov_avg150" lines, since those moving averages aren't used for anything (that I could see).

One thing to keep in mind... when you have the AddOrder commands in a script, TOS implements the orders at the open of bar after the one that triggered the buy/sell. I don't know if there's a way to change that or not, so that's how this one works.

Here's the code:
Code:
# *** Slim Ribbon Strategy ***
# In TOS, under Tools, select Add ("+"), Strategy. Delete sample code and paste this code into the window.
# Save the script, then add to your chart.

input price = close;
input superfast_length = 5;
input fast_length = 9;
input med_length = 18;
#input long_length = 45;  #this MA is not used
#input superlong_length = 150;  #this MA is not used
input filterL = 18;  #long position trend indicator
input filterS = 18;  #short position trend indicator
input sensitivityL = 12;  #defines a stop for long positions
input sensitivityS = 9;  #defines stop for short positions
input displace = 0;


def mov_avgSF = simpleMovingAvg(price[-displace], superfast_length);
def mov_avgF = simpleMovingAvg(price[-displace], fast_length);
def mov_avgM = simpleMovingAvg(price[-displace], med_length);
#def mov_avgL = simpleMovingAvg(price[-displace], long_length);  #not used
#def mov_avgSL = simpleMovingAvg(price[-displace], superlong_length);  #not used

def filter_L = simpleMovingAvg(price[-displace], filterL);
def filter_S = simpleMovingAvg(price[-displace], filterS);

def sens_L = simpleMovingAvg(price[-displace], sensitivityL);
def sens_S = simpleMovingAvg(price[-displace], sensitivityS);


#moving averages
plot Superfast = mov_avgSF;
Superfast.setdefaultcolor(color.white);
plot Fast = mov_avgF;
Fast.setdefaultColor(color.cyan);
plot Slow = mov_avgM;
Slow.setdefaultColor(color.yellow);
 

def buy = mov_avgSF > mov_avgF and close > filter_L;

def stopbuy = close < sens_L; # or close crosses below BollingerBands("length" = 18)."UpperBand";

def buynow = !buy[1] and buy;

def buySignal = CompoundValue(1, if buynow and !stopbuy then 1 else if buySignal[1] == 1 and stopbuy then 0 else buySignal[1], 0);


plot Buy_Signal = buySignal[1] == 0 and buySignal == 1;
Buy_Signal.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Buy_Signal.setdefaultColor(color.GREEN);
Buy_Signal.hidetitle();

Alert(condition = buySignal[1] == 0 and buySignal == 1, text = "Buy Signal", sound = Sound.Bell, "alert type" = Alert.BAR);

 
plot Momentum_Down = buySignal[1] == 1 and buySignal == 0;
Momentum_Down.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Momentum_Down.setdefaultColor(color.cyan);
Momentum_Down.hidetitle();

Alert(condition = buySignal[1] == 1 and buySignal == 0, text = "Momentum_Down", sound = Sound.Bell, "alert type" = Alert.BAR);

AddOrder(OrderType.BUY_TO_OPEN, Buy_Signal, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "Buy Long");
AddOrder(OrderType.SELL_TO_CLOSE, Momentum_Down, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "Sell Long");

def sell = mov_avgSF < mov_avgF and close < filter_S;

def stopsell = close > sens_S; #or close crosses above BollingerBands("length" = 18)."LowerBand";

def sellnow = !sell[1] and sell;

def sellSignal = CompoundValue(1, if sellnow and !stopsell then 1 else if sellSignal[1] == 1 and stopsell then 0 else sellSignal[1], 0);

 
Plot Sell_Signal = sellSignal[1] == 0 and sellSignal;
Sell_signal.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Sell_signal.setDefaultColor(color.red);
Sell_signal.hidetitle();

Alert(condition = sellSignal[1] == 0 and sellSignal == 1, text = "Sell Signal", sound = Sound.Bell, "alert type" = Alert.BAR);
 

Plot Momentum_Up = sellSignal[1] == 1 and sellSignal == 0;
Momentum_Up.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Momentum_Up.setDefaultColor(color.orange);
Momentum_Up.hidetitle();

Alert(condition = sellSignal[1] == 1 and sellSignal == 0, text = "Momentum_Up", sound = Sound.Bell, "alert type" = Alert.BAR);

AddOrder(OrderType.SELL_TO_OPEN, Sell_Signal, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "Sell Short");
AddOrder(OrderType.BUY_TO_CLOSE, Momentum_Up, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "Buy Short");

plot Colorbars = if buySignal == 1 then 1 else if sellSignal == 1 then 2 else if buySignal == 0 or sellSignal== 0 then 3 else 0;
Colorbars.hide();
Colorbars.definecolor("Buy_Signal_Bars", color.green);
Colorbars.definecolor("Sell_Signal_Bars", color.red);
Colorbars.definecolor("Neutral", color.yellow);
AssignPriceColor(if Colorbars == 1 then Colorbars.color("buy_signal_bars") else if Colorbars == 2 then Colorbars.color("Sell_Signal_bars") else  Colorbars.color("neutral"));

#end
You're awesome bud! Thanks!
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
472 Online
Create Post

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.
Back
Top