Help adding a DMI condition to Slim Ribbon Study please!

DGreenleaf17

New member
Hello there!

Was wondering if it's possible to add a condition to the Slim Ribbon Study using the original DMI script found on TOS.

Paint Bars red when Slim Ribbon (S.R) shows 8<13<21 and DMI- > 20 and ADX > 20.

Neutral grey bars when conditions aren't met.

Paint Bars Green when S.R. shows 8>13>21 and DMI+ > 20 and ADX > 20.

If it's possible I can pay someone for their time, thank you so much in advance.


Here is the code for the Slim Ribbon Study I have;

#Mr Slim Miller at askSLIM dot com
#SlimRibbonCustom_markos9-7-18
input price = close;

input superfast_length = 8;

input fast_length = 13;

input slow_length = 21;

input displace = 0;



def mov_avg8 = ExpAverage(price[-displace], superfast_length);

def mov_avg13 = ExpAverage(price[-displace], fast_length);

def mov_avg21 = ExpAverage(price[-displace], slow_length);



#moving averages

Plot Superfast = mov_avg8;

plot Fast = mov_avg13;

plot Slow = mov_avg21;



def buy = mov_avg8 > mov_avg13 and mov_avg13 > mov_avg21 and low > mov_avg8;

def stopbuy = mov_avg8 <= mov_avg13;

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.dark_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.yellow);

Momentum_down.hidetitle();

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



def sell = mov_avg8 < mov_avg13 and mov_avg13 < mov_avg21 and high < mov_avg8;

def stopsell = mov_avg8 >= mov_avg13;

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

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.dark_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
 
Here's what I came up with. Note that I modified a script I had already modified to original Slim Ribbon to include Ripster's 34/50 Trend Cloud. Below is the modified code (Note I made it so you can toggle on/off colored bars):

#Mr Slim Miller at askSLIM dot com
#SlimRibbonCustom_markos9-7-18

# All credit to Mr Slim Miller for Original idea
# Credit to markos for conversion to TOS
# Credit to Ripster and Saty Mahajan for Ripster Cloud and Code for overall Trend
# June 2023 added color candles option based on Slim Clouds and ADX/DMI

input price = close;

input superfast_length = 8;

input fast_length = 13;

input slow_length = 21;

input displace = 0;



def mov_avg8 = ExpAverage(price[-displace], superfast_length);

def mov_avg13 = ExpAverage(price[-displace], fast_length);

def mov_avg21 = ExpAverage(price[-displace], slow_length);



#moving averages

Plot Superfast = mov_avg8;

plot Fast = mov_avg13;

plot Slow = mov_avg21;



def buy = mov_avg8 > mov_avg13 and mov_avg13 > mov_avg21 and low > mov_avg8;

def stopbuy = mov_avg8 <= mov_avg13;

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.dark_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.yellow);

Momentum_down.hidetitle();

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



def sell = mov_avg8 < mov_avg13 and mov_avg13 < mov_avg21 and high < mov_avg8;

def stopsell = mov_avg8 >= mov_avg13;

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

Momentum_up.hidetitle();

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


#end

#-------------------------------------- Add Ripster Trend Filter Cloud --------------------------------
input TrendOn = yes;
input TrendEMALow = 34;
input TrendEMAHigh = 50;
DefineGlobalColor("Trend Bullish", Color.CYAN);
DefineGlobalColor("Trend Bearish", Color.LIGHT_ORANGE);
def TrendEMALowValue = ExpAverage(price, TrendEMALow);
def TrendEMAHighValue = ExpAverage(price, TrendEMAHigh);
AddCloud(if TrendOn then TrendEMALowValue else double.nan, TrendEMAHighValue, GlobalColor("Trend Bullish"), GlobalColor("Trend Bearish"));

# ------------------------------------- Add SMA Trend Line -------------------------------------------
input showSMA = no;
input smaLength = 50;

def c = close;
def na = double.nan;


plot sma = if showSMA then Average(c, smaLength) else na;
def smaUp = sma > sma[1];
def smaDown = sma < sma[1];

sma.HideBubble();
sma.DefineColor("Up", Color.CYAN);
sma.DefineColor("Down", Color.red);


sma.AssignValueColor(if smaUP then sma.Color("Up") else if smaDown then sma.Color("Down") else Color.WHITE);
sma.SetLineWeight(1);
sma.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);


# TD Ameritrade IP Company, Inc. (c) 2008-2023
#

#declare lower;

input length = 14;
input averageType = AverageType.WILDERS;

def hiDiff = high - high[1];
def loDiff = low[1] - low;

def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM = if loDiff > hiDiff and loDiff > 0 then loDiff else 0;

def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);
def "DI+" = 100 * MovingAverage(averageType, plusDM, length) / ATR;
def "DI-" = 100 * MovingAverage(averageType, minusDM, length) / ATR;

def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
def ADX = MovingAverage(averageType, DX, length);

#"DI+".SetDefaultColor(GetColor(1));
#"DI-".SetDefaultColor(GetColor(8));
#ADX.SetDefaultColor(GetColor(5));

Def ADXBuy = ADX > 20;

Def DIBuy = "DI+" > 20;
Def DISell = "DI-" > 20;

#--------------------------------------- Mods for Colored Candles based on Slim Ribbon ADX/DMI--------------------------------


input paintBars = no;

Def LongColor = mov_avg8 > mov_avg13 and mov_avg13 > mov_avg21;
Def ShortColor = mov_avg8 < mov_avg13 and mov_avg13 < mov_avg21;


AssignPriceColor(
if paintBars and LongColor and ADXbuy and DIBuy and "DI+" > "DI-" then Color.GREEN
else if paintBars and ShortColor and ADXbuy and DISell and "DI+" < "DI-" then Color.LIGHT_RED
else if paintBars then Color.gray
else Color.CURRENT
);
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
373 Online
Create Post

Similar threads

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