RMI Trend Sniper for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
97wf4FM.png


Author Message:
he "RMI Trend Sniper" is a powerful trend-following indicator designed to help traders identify potential buy and sell signals in the market.
It combines elements of the Relative Strength Index (RSI) and the Money Flow Index (MFI) to provide a comprehensive view of market momentum and strength.

CODE - Updated - Added MTF option

CSS:
# https://www.tradingview.com/v/rtD9lc5D/
#// This source code is subject to the terms of the Mozilla Public License 2.0 at
#// © TZack88
#indicator('RMI Trend Sniper', overlay=true,max_labels_count = 500)
# converted and mod by Sam4Cok@Samer800    - 10/2023
# Updated by Sam4Cok@Samer800    - Added MTF option - 11/2023
#// ** ---> Inputs ------------- {
input colorBars = no;
input timeframe = {Default "Chart", "Custom"};
input customTimeframe = AggregationPeriod.FIFTEEN_MIN;
input rmiLength = 14;     # "RMI Length "
input lookbackPeriod = 20;
input barRangeCalMethod = {default "High/Low", "ATR"};
input atrLength     = 100;
input PositiveAbove = 66;     # "Positive above"
input NegativeBelow = 30;     # "Negative below"
input showRmiLine = yes;      # "Show Range MA "
input showBand = yes;

def na = Double.NaN;
def mtf = timeframe == timeframe."Custom";
def hilo = barRangeCalMethod == barRangeCalMethod."High/Low";
#- MTF
def tfS = Fundamental(FundamentalType = FundamentalType.HLC3);
def tfV = Fundamental(FundamentalType = FundamentalType.VOLUME);
def tfC = Fundamental(FundamentalType = FundamentalType.CLOSE);
def tfH = Fundamental(FundamentalType = FundamentalType.HIGH);
def tfL = Fundamental(FundamentalType = FundamentalType.LOW);
def mtfS = Fundamental(FundamentalType = FundamentalType.HLC3, Period = customTimeframe);
def mtfv = Fundamental(FundamentalType = FundamentalType.VOLUME, Period = customTimeframe);
def mtfC = Fundamental(FundamentalType = FundamentalType.CLOSE, Period = customTimeframe);
def mtfH = Fundamental(FundamentalType = FundamentalType.HIGH, Period = customTimeframe);
def mtfL = Fundamental(FundamentalType = FundamentalType.LOW, Period = customTimeframe);

def s = if mtf then mtfS else tfC;
def v = if mtf then mtfV else tfV;
def c = if mtf then mtfC else tfC;
def h = if mtf then mtfH else tfH;
def l = if mtf then mtfL else tfL;

#-- Color
DefineGlobalColor("up",  CreateColor(0, 188, 212));
DefineGlobalColor("up2", CreateColor(0, 66, 75));
DefineGlobalColor("up1", CreateColor(0, 31, 35));
DefineGlobalColor("dn",  CreateColor(255, 82, 82));
DefineGlobalColor("dn2", CreateColor(62, 32, 32));
DefineGlobalColor("dn1", CreateColor(23, 12, 12));

def tr = TrueRange(h, c, l);
def nATR = WildersAverage(tr, 30);
def band_ = Min(nATR * 0.3,  c * (0.3 / 100));
def Band = band_[20] * 4;
def atrRange =  WildersAverage(tr, atrLength);
def hiLoRange = h - l;
def barRange = if hilo then hiLoRange else atrRange;

#// the same on pine
Script mfi {
input src = hlc3;
input length = 20;
input vol = volume;
    def change = src - src[1];
    def upper = sum(vol * (if change <= 0.0 then 0.0 else src), length);
    def lower = sum(vol * (if change >= 0.0 then 0.0 else src), length);
    def mfi = 100.0 - (100.0 / (1.0 + upper / lower));
    plot out = if isNaN(mfi) then 0 else mfi;
}
#method rangeMA(float Range,Prd)=>
script rangeMA {
    input Range = 0;
    input Prd = 20;
    input cMTF = close;
    def sumRng = Sum(Range, Prd);
    def weight = Range / sumRng;
    def sum    = Sum(cMTF * weight, Prd);
    def tw     = Sum(weight, Prd);
    def rangeMA = sum / tw;
    plot out = rangeMA;
}
def change = c - c[1];
def up = WildersAverage( max(change, 0), rmiLength);
def dn = WildersAverage(-min(change, 0), rmiLength);
def rsi = if dn == 0 then 100 else
          if up == 0 then 0   else 100 - (100 / (1 + up / dn));
def mf = mfi(s, rmiLength, v);
def rsi_mfi = (rsi + mf) / 2;
def ema = ExpAverage(c, 5);
def emaChange = ema - ema[1];
def p_mom = rsi_mfi[1] < PositiveAbove and
            rsi_mfi > PositiveAbove and
            rsi_mfi > NegativeBelow and emaChange > 0;
def n_mom = rsi_mfi < NegativeBelow and emaChange < 0;

#// //  ---> Momentums ------------- {
def positive;
def negative;
if p_mom {
    positive = yes;
    negative = no;
} else
if n_mom {
    positive = no;
    negative = yes;
} else {
    positive = if isNaN(positive[1]) then no else positive[1];
    negative = if isNaN(negative[1]) then no else negative[1];
}
#/ Calculate the RWMA
def rwma1 = rangeMA(barRange, lookbackPeriod, c);

#// Plotting the RWMA.
def upCol = positive;
def colChg = upCol != upCol[1];
def pos = rwma1 - Band;
def neg = rwma1 + Band;
def RWMA = if positive then pos else
           if negative then neg else na;

plot RRTH0 = if showRmiLine then RWMA else na;
plot RRTH1 = if colChg then na else
             if showRmiLine then RWMA else na;

RRTH1.SetLineWeight(2);
RRTH0.AssignValueColor(if upCol then GlobalColor("up") else GlobalColor("dn"));
RRTH1.AssignValueColor(if upCol then GlobalColor("up1") else GlobalColor("dn1"));

#-- Signals
def max = RWMA + Band;
def min = RWMA - Band;

plot sigUp = if positive and !positive[1] then
             if showRmiLine then RWMA else
             if showBand then min else low - ATR(Length=30) else na;
plot sigDn = if negative and !negative[1] then
             if showRmiLine then RWMA else
             if showBand then max else high + ATR(Length=30) else na;

sigUp.SetLineWeight(3);
sigDn.SetLineWeight(3);
sigUp.SetStyle(Curve.POINTS);
sigDn.SetStyle(Curve.POINTS);
sigUp.SetDefaultColor(GlobalColor("up"));
sigDn.SetDefaultColor(GlobalColor("dn"));
#-- Band

def top = if showBand then max else na;
def bot = if showBand then min else na;

AddCloud(if upCol then top else bot,
         if upCol then bot else top, GlobalColor("up2"), GlobalColor("dn2"));

#-- Bar Color
AssignPriceColor(if !colorBars then Color.CURRENT else
                 if upCol then Color.GREEN else Color.RED);

#-- END of CODE
 
Last edited:

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

How would a scan find stocks in current uptrend or in downtrend. I see how to scan for the trigger up/down signal but didn't know how to say current "trendline is blue" or "trendline is red" Thanks
 
97wf4FM.png


Author Message:
he "RMI Trend Sniper" is a powerful trend-following indicator designed to help traders identify potential buy and sell signals in the market.
It combines elements of the Relative Strength Index (RSI) and the Money Flow Index (MFI) to provide a comprehensive view of market momentum and strength.

CODE:

CSS:
# https://www.tradingview.com/v/rtD9lc5D/
#// This source code is subject to the terms of the Mozilla Public License 2.0 at
#// © TZack88
#indicator('RMI Trend Sniper', overlay=true,max_labels_count = 500)
# converted and mod by Sam4Cok@Samer800    - 10/2023
#// ** ---> Inputs ------------- {
input colorBars = yes;
input rmiLength = 14;     # "RMI Length "
input barRangeCalMethod = {default "High - Low", "ATR"};
input atrLength     = 100;
input PositiveAbove = 66;     # "Positive above"
input NegativeBelow = 30;     # "Negative below"
input showRmiLine = yes;      # "Show Range MA "
input showBand = yes;

def na = Double.NaN;
def hilo = barRangeCalMethod == barRangeCalMethod. "High - Low";
def hMTF = high;
def lMTF = low;
def cMTF = close;
def vMTF = volume;

#-- Color
DefineGlobalColor("up",  CreateColor(0, 188, 212));
DefineGlobalColor("up1", CreateColor(0, 118, 134));
DefineGlobalColor("up2", CreateColor(0, 66, 75));
DefineGlobalColor("up3", CreateColor(0, 31, 35));

DefineGlobalColor("dn",  CreateColor(255, 82, 82));
DefineGlobalColor("dn1", CreateColor(121, 52, 52));
DefineGlobalColor("dn2", CreateColor(62, 32, 32));
DefineGlobalColor("dn3", CreateColor(23, 12, 12));

def nATR = ATR(Length = 30);
def band_ = Min(nATR * 0.3,  cMTF * (0.3 / 100));
def Band = band_[20] * 4;
def tr = TrueRange(hMTF, cMTF, lMTF);
def atrRange =  WildersAverage(tr, atrLength);
def hiLoRange = hMTF - lMTF;
def barRange = if hilo then hiLoRange else atrRange;

#method rangeMA(float Range,Prd)=>
script rangeMA {
    input Range = 0;
    input Prd = 20;
    input cMTF = close;
    def sumRng = Sum(Range, Prd);
    def weight = Range / sumRng;
    def sum    = Sum(cMTF * weight, Prd);
    def tw     = Sum(weight, Prd);
    def rangeMA = sum / tw;
    plot out = rangeMA;
}

def rsi = RSI(Price = cMTF, length = rmiLength);
def MTF = Average(moneyflow(hMTF, cMTF, lMTF, vMTF, rmiLength),1);
def mf = MTF;#MoneyFlowIndex(Length = rmiLength);
def rsi_mfi = (rsi + mf) / 2;
def ema = ExpAverage(cMTF, 5);
def emaChange = ema - ema[1];
def p_mom = rsi_mfi[1] < PositiveAbove and
      rsi_mfi > PositiveAbove and
      rsi_mfi > NegativeBelow and
       emaChange > 0;
def n_mom = rsi_mfi < NegativeBelow and emaChange < 0;

#// //  ---> Momentums ------------- {
def positive;#    = false
def negative;# = false
if p_mom {
    positive = yes;
    negative = no;
} else
if n_mom {
    positive = no;
    negative = yes;
} else {
    positive = positive[1];
    negative = negative[1];
}
#/ Calculate the RWMA
def rwma1 = rangeMA(barRange, 20, cMTF);

#// Plotting the RWMA.
def upCol = positive;
def RWMA = if positive then rwma1 - Band else
           if negative then rwma1 + Band else na;

plot RRTH  = if upCol - upCol[1] then na else
             if showRmiLine then RWMA else na;
plot RRTH1 = if showRmiLine then RWMA else na;
plot RRTH2 = if upCol - upCol[1] then na else
             if showRmiLine then RWMA else na;
plot RRTH3 = if showRmiLine then RWMA else na;

RRTH1.SetLineWeight(2);
RRTH2.SetLineWeight(3);
RRTH3.SetLineWeight(4);
RRTH.AssignValueColor(if upCol then GlobalColor("up") else GlobalColor("dn"));
RRTH1.AssignValueColor(if upCol then GlobalColor("up1") else GlobalColor("dn1"));
RRTH2.AssignValueColor(if upCol then GlobalColor("up2") else GlobalColor("dn2"));
RRTH3.AssignValueColor(if upCol then GlobalColor("up3") else GlobalColor("dn3"));

#-- Signals
def max = RWMA + Band;
def min = RWMA - Band;

plot sigUp = if positive and !positive[1] then
             if showRmiLine then RWMA else
             if showBand then min else low - nATR else na;
plot sigDn = if negative and !negative[1] then
             if showRmiLine then RWMA else
             if showBand then max else high + nATR else na;

sigUp.SetLineWeight(3);
sigDn.SetLineWeight(3);
sigUp.SetStyle(Curve.POINTS);
sigDn.SetStyle(Curve.POINTS);
sigUp.SetDefaultColor(GlobalColor("up"));
sigDn.SetDefaultColor(GlobalColor("dn"));
#-- Band

def top = if showBand then max else na;#, "RRTH", alpha)
def bottom = if showBand then min else na;#, "RRTH", alpha)

AddCloud(if upCol then top else bottom,
         if upCol then bottom else top, GlobalColor("up2"), GlobalColor("dn2"));

#-- Bar Color
AssignPriceColor(if !colorBars then Color.CURRENT else
                 if upCol then GlobalColor("up") else GlobalColor("dn"));

#-- END of CODE
Hello,

I pasted this code on thinkscript and it didnt work for me. Rather it changed my bar colors to all red. Please is there anyway you can send me the updated script so i can test the indicator on a 1 day timeframe
 
Hello,

I pasted this code on thinkscript and it didnt work for me. Rather it changed my bar colors to all red. Please is there anyway you can send me the updated script so i can test the indicator on a 1 day timeframe
I just updated the posed code with MTF option. pls try
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
402 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