
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: