RSI Candle Advanced V2 for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
GGQSpvb.png

Creator Message:
As the period value is longer than 14, the RSI value sticks to the value of 50 and becomes useless.

Also, when the period value is less than 14, it moves excessively, so it is difficult for us to see the movement of the RSI .

So, using the period value and the RSI value as variables, I tried to make it easier to identify the RSI value through a new function expression.

This is how RSI Advanced was developed.

Period below 14 reduce the volatility of RSI , and period above 14 increase the volatility of RSI , allowing overbought and oversold zones to work properly and give you a better view of the trend.

By applying the custom algorithm so that the 'RSI Advanced' with period on a 5-minute timeframe has the same value as the 'original RSI' with period on a 60-minute timeframe.

As another example, an 'RSI Advanced' with a period in a 60-minute time frame has the same value as an 'original RSI' with a period in a 240-minute time frame.

CODE:

#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Dicargo_Beam
#indicator('RSI Candle Advanced V2')
declare lower;
input src = close;
input rsiLength = 14;#, 'RSI Length')
input rsiAdvanced = yes;#, 'RSI Advanced ?? (Recommend)')
input plotStyle = {default Candle, Bar, Line};#itle='Candle or Bar or Line?'
input overBought = 70;
input overSold = 30;
input LookBackRight = 5; # "Pivot Lookback Right"
input LookBackLeft = 5; # "Pivot Lookback Left"
input MaxLookback = 60; # "Max of Lookback Range"
input MinLookback = 5; # "Min of Lookback Range"
input DivBull = yes; # "Plot Bullish"
input DivBear = yes; # "Plot Bearish"
input DivHiddenBull = no; # "Plot Hidden Bullish"
input DivHiddenBear = no; # "Plot Hidden Bearish"

def na = Double.NaN;
def last = isNaN(close);
def Style = if plotStyle==plotStyle.Candle then 1 else
if plotStyle==plotStyle.Bar then -1 else 0;
# if plotStyle==plotStyle.Line then 0 else Style[1];
def u = Max(src - src[1], 0);
def d = Max(src[1] - src, 0);

def ru = WildersAverage(u, rsiLength);
def rd = WildersAverage(d, rsiLength);

def a = 1 / rsiLength;

def ruh = a * Max(high - close[1], 0) + (1 - a) * WildersAverage(u, rsiLength)[1];
def rdh = a * Max(close[1] - high, 0) + (1 - a) * WildersAverage(d, rsiLength)[1];

def rul = a * Max(low - close[1], 0) + (1 - a) * WildersAverage(u, rsiLength)[1];
def rdl = a * Max(close[1] - low, 0) + (1 - a) * WildersAverage(d, rsiLength)[1];

def ruo = a * Max(open - close[1], 0) + (1 - a) * WildersAverage(u, rsiLength)[1];
def rdo = a * Max(close[1] - open, 0) + (1 - a) * WildersAverage(d, rsiLength)[1];

#function(rsi, len) =>
script rsifunction {
input rsi = 50;
input len = 14;
def f = -Power(AbsValue(AbsValue(rsi - 50) - 50), 1 + Power(len / 14, 0.618) - 1) / Power(50, Power(len / 14, 0.618) - 1) + 50;
def rsiadvanced = if rsi > 50 then f + 50 else -f + 50;
plot rsifunction = rsiadvanced;
}

def rsiha = 100 - 100 / (1 + ruh / rdh);
def rsila = 100 - 100 / (1 + rul / rdl);
def rsia = 100 - 100 / (1 + ru / rd);
def rsioa = 100 - 100 / (1 + ruo / rdo);

def rsih = if rsiAdvanced then rsifunction(rsiha, rsiLength) else rsiha;
def rsil = if rsiAdvanced then rsifunction(rsila, rsiLength) else rsila;
def rsic = if rsiAdvanced then rsifunction(rsia, rsiLength) else rsia;
def rsio = if rsiAdvanced then rsifunction(rsioa, rsiLength) else rsioa;

def col = open<close;
def cohi = Style>0 and col;
def coLo = Style>0 and !col;
def Barhi = Style<0 and col;
def BarLo = Style<0 and !col;

plot midLine = if last then na else 50;
midLine.SetDefaultColor(Color.DARK_GRAY);
plot obLevel = if last then na else overBought;
obLevel.SetDefaultColor(Color.GRAY);
plot osLevel = if last then na else overSold;
osLevel.SetDefaultColor(Color.GRAY);


plot AdvRsiLine = if Style==0 then rsic else na;#, color=cold)
AdvRsiLine.AssignValueColor(if col then Color.GREEN else Color.RED);

AddChart(high = if cohi then rsih else na, low = if cohi then rsil else na, open = if cohi then rsic else na, close = if cohi then rsio else na,
type = ChartType.CANDLE, growcolor = CreateColor(38,166,154));

AddChart(high = if coLo then rsih else na , low = if coLo then rsil else na, open = if coLo then rsio else na, close = if coLo then rsic else na,
type = ChartType.CANDLE, growcolor = CreateColor(239,83,80));

AddChart(high = if Barhi then rsih else na, low = if Barhi then rsil else na, open = if Barhi then rsic else na, close = if Barhi then rsio else na,
type = ChartType.BAR, growcolor = CreateColor(38,166,154));

AddChart(high = if BarLo then rsih else na , low = if BarLo then rsil else na, open = if BarLo then rsio else na, close = if BarLo then rsic else na,
type = ChartType.BAR, growcolor = CreateColor(239,83,80));

#---- Background
AddCloud(obLevel, osLevel, CreateColor(56,0,56));
#-- Price color


#----Div-----------
def rsisrc = (rsih + rsil) / 2;
def divSrc = rsisrc;

def h = high;
def l = low;

script FindPivots {
input dat = close; # default data or study being evaluated
input HL = 0; # default high or low pivot designation, -1 low, +1 high
input lbL = 5; # default Pivot Lookback Left
input lbR = 1; # default Pivot Lookback Right
##############
def _nan; # used for non-number returns
def _BN; # the current barnumber
def _VStop; # confirms that the lookforward period continues the pivot trend
def _V; # the Value at the actual pivot point
##############
_BN = BarNumber();
_nan = Double.NaN;
_VStop = if !isNaN(dat) and lbr > 0 and lbl > 0 then
fold a = 1 to lbR + 1 with b=1 while b do
if HL > 0 then dat > GetValue(dat,-a) else dat < GetValue(dat,-a) else _nan;
if (HL > 0) {
_V = if _BN > lbL and dat == Highest(dat, lbL+1) and _VStop
then dat else _nan;
} else {
_V = if _BN > lbL and dat == Lowest(dat, lbL+1) and _VStop
then dat else _nan;
}
plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
#valuewhen (Cond, source, lbr, occurrence)
script valuewhen {
input cond = 0;
input src = close;
input MinLookback = 5;
input MaxLookback = 60;
input occurrence = 0;
def n = occurrence + 1;
def offset = fold j = MinLookback to MaxLookback + 1 with p=1 while p < n + 1
do p + ( if p == n then j - n else if cond[j]==yes then 1 else 0 );
plot price = GetValue(src, offset-1);}
#_inRange(cond) =>
script _inRange {
input cond = yes;
input rangeUpper = 60;
input rangeLower = 5;
def bars = if cond then 0 else bars[1] + 1;
def inrange = (rangeLower <= bars) and (bars <= rangeUpper);
plot retrun = inRange;
}
def pl = findpivots(divSrc,-1, LookBackLeft, LookBackRight);
def ph = findpivots(divSrc, 1, LookBackLeft, LookBackRight);

def plFound = if !isNaN(pl) then 1 else 0;
def phFound = if !isNaN(ph) then 1 else 0;

def vlFound = valuewhen(plFound, divSrc, MinLookback, MaxLookback, 1);
def vhFound = valuewhen(phFound, divSrc, MinLookback, MaxLookback, 1);

def plPrice = valuewhen(plFound, l, MinLookback, MaxLookback, 1);
def phPrice = valuewhen(phFound, h, MinLookback, MaxLookback, 1);

#// Regular Bullish
def oscHL = divSrc > vlFound and _inRange(plFound[1],MaxLookback,MinLookback);
def priceLL = l < plPrice;
def bullCond = DivBull and plFound and oscHL and priceLL;
#// Hidden Bullish
def oscLL = divSrc < vlFound and _inRange(plFound[1],MaxLookback,MinLookback);
def priceHL = l > plPrice;
def hiddenBullCond = DivHiddenBull and plFound and oscLL and priceHL;

#// Regular Bearish
def oscLH = divSrc < vhFound and _inRange(phFound[1],MaxLookback,MinLookback);
def priceHH = h > phPrice;
def bearCond = DivBear and phFound and oscLH and priceHH;
#// Hidden Bearish
def oscHH = divSrc > vhFound and _inRange(phFound[1],MaxLookback,MinLookback);
def priceLH = h < phPrice;
def hiddenBearCond = DivHiddenBear and phFound and oscHH and priceLH;

#------ Bubbles
addchartbubble(bullCond, if Style!=0 then rsil else divSrc, "R", color.GREEN, no);
addchartbubble(bearCond, if Style!=0 then rsih else divSrc, "R", CreateColor(156,39,176), yes);
addchartbubble(hiddenBullCond, if Style!=0 then rsil else divSrc, "H", color.DARK_green, no);
addchartbubble(hiddenBearCond, if Style!=0 then rsih else divSrc, "H", color.DARK_red, yes);

#--- END CODE
 
Last edited by a moderator:
@samer800 : Thank you for another TradingView to TOS conversion...Would it be possible to take the AddChartBubbles off of the RSI Candle Advanced V2 indicator and put them right on the Chart?
 
@samer800 : I've gone ahead and tried my best to customize your RSI Candle Advanced V2 script to take the AddChartBubbles off of the RSI Candle Advanced V2 indicator and put them right on the Chart...While I was partially successful, I can't seem to get the AddChartBubble to attach to the corresponding candle on the upper chart...

202301180802-Advanced-RSI-Candles-UPPER.jpg


Here is the customized RSI Candle Advanced V2 Upper script:

Code:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Dicargo_Beam
#indicator('RSI Candle Advanced V2')

#declare lower;
declare upper;

input src = close;
input rsiLength = 14;#, 'RSI Length')
input rsiAdvanced = yes;#, 'RSI Advanced ?? (Recommend)')
input plotStyle = {Candle, Bar, default Line};#itle='Candle or Bar or Line?'
input overBought = 70;
input overSold = 30;
input LookBackRight = 5; # "Pivot Lookback Right"
input LookBackLeft = 5; # "Pivot Lookback Left"
input MaxLookback = 60; # "Max of Lookback Range"
input MinLookback = 5; # "Min of Lookback Range"
input DivBull = yes; # "Plot Bullish"
input DivBear = yes; # "Plot Bearish"
input DivHiddenBull = yes; # "Plot Hidden Bullish"
input DivHiddenBear = yes; # "Plot Hidden Bearish"

def na = Double.NaN;
def last = isNaN(close);

#def Style = if plotStyle==plotStyle.Candle then 1 else if plotStyle==plotStyle.Bar then -1 else 0;
# if plotStyle==plotStyle.Line then 0 else Style[1];
def Style = if plotStyle == plotStyle.Line then 0 else na;

def u = Max(src - src[1], 0);
def d = Max(src[1] - src, 0);

def ru = WildersAverage(u, rsiLength);
def rd = WildersAverage(d, rsiLength);

def a = 1 / rsiLength;

def ruh = a * Max(high - close[1], 0) + (1 - a) * WildersAverage(u, rsiLength)[1];
def rdh = a * Max(close[1] - high, 0) + (1 - a) * WildersAverage(d, rsiLength)[1];

def rul = a * Max(low - close[1], 0) + (1 - a) * WildersAverage(u, rsiLength)[1];
def rdl = a * Max(close[1] - low, 0) + (1 - a) * WildersAverage(d, rsiLength)[1];

def ruo = a * Max(open - close[1], 0) + (1 - a) * WildersAverage(u, rsiLength)[1];
def rdo = a * Max(close[1] - open, 0) + (1 - a) * WildersAverage(d, rsiLength)[1];

#function(rsi, len) =>
script rsifunction {
    input rsi = 50;
    input len = 14;
    def f = -Power(AbsValue(AbsValue(rsi - 50) - 50), 1 + Power(len / 14, 0.618) - 1) / Power(50, Power(len / 14, 0.618) - 1) + 50;
    def rsiadvanced = if rsi > 50 then f + 50 else -f + 50;
    plot rsifunction = rsiadvanced;
}

def rsiha = 100 - 100 / (1 + ruh / rdh);
def rsila = 100 - 100 / (1 + rul / rdl);
def rsia = 100 - 100 / (1 + ru / rd);
def rsioa = 100 - 100 / (1 + ruo / rdo);

def rsih = if rsiAdvanced then rsifunction(rsiha, rsiLength) else rsiha;
def rsil = if rsiAdvanced then rsifunction(rsila, rsiLength) else rsila;
def rsic = if rsiAdvanced then rsifunction(rsia, rsiLength) else rsia;
def rsio = if rsiAdvanced then rsifunction(rsioa, rsiLength) else rsioa;

def col = open<close;
#def cohi = Style>0 and col;
#def coLo = Style>0 and !col;
#def Barhi = Style<0 and col;
#def BarLo = Style<0 and !col;

def cohi = Style==0 and col;
def coLo = Style==0 and !col;
def Barhi = Style==0 and col;
def BarLo = Style==0 and !col;

#plot midLine = if last then na else 50;
#midLine.SetDefaultColor(Color.DARK_GRAY);
#plot obLevel = if last then na else overBought;
#obLevel.SetDefaultColor(Color.GRAY);
#plot osLevel = if last then na else overSold;
#osLevel.SetDefaultColor(Color.GRAY);

#plot AdvRsiLine = if Style==0 then rsic else na;#, color=cold)
#AdvRsiLine.AssignValueColor(if col then Color.GREEN else Color.RED);

def AdvRsiLine = if Style==0 then rsic else na;#, color=cold)

AddChart(high = if cohi then rsih else na, low = if cohi then rsil else na, open = if cohi then rsic else na, close = if cohi then rsio else na,
type = ChartType.LINE, growcolor = Color.BLACK);

AddChart(high = if coLo then rsih else na , low = if coLo then rsil else na, open = if coLo then rsio else na, close = if coLo then rsic else na,
type = ChartType.LINE, growcolor = Color.BLACK);

AddChart(high = if Barhi then rsih else na, low = if Barhi then rsil else na, open = if Barhi then rsic else na, close = if Barhi then rsio else na,
type = ChartType.LINE, growcolor = Color.BLACK);

AddChart(high = if BarLo then rsih else na , low = if BarLo then rsil else na, open = if BarLo then rsio else na, close = if BarLo then rsic else na,
type = ChartType.LINE, growcolor = Color.BLACK);

#---- Background
#AddCloud(obLevel, osLevel, CreateColor(56,0,56));
#-- Price color


#----Div-----------
def rsisrc = (rsih + rsil) / 2;
def divSrc = rsisrc;

def h = high;
def l = low;

script FindPivots {
    input dat = close; # default data or study being evaluated
    input HL = 0; # default high or low pivot designation, -1 low, +1 high
    input lbL = 5; # default Pivot Lookback Left
    input lbR = 1; # default Pivot Lookback Right
##############
    def _nan; # used for non-number returns
    def _BN; # the current barnumber
    def _VStop; # confirms that the lookforward period continues the pivot trend
    def _V; # the Value at the actual pivot point
##############
    _BN = BarNumber();
    _nan = Double.NaN;
    _VStop = if !isNaN(dat) and lbr > 0 and lbl > 0 then
    fold a = 1 to lbR + 1 with b=1 while b do
    if HL > 0 then dat > GetValue(dat,-a) else dat < GetValue(dat,-a) else _nan;
    if (HL > 0) {
    _V = if _BN > lbL and dat == Highest(dat, lbL+1) and _VStop
    then dat else _nan;
    } else {
    _V = if _BN > lbL and dat == Lowest(dat, lbL+1) and _VStop
    then dat else _nan;
    }
plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
#valuewhen (Cond, source, lbr, occurrence)
script valuewhen {
    input cond = 0;
    input src = close;
    input MinLookback = 5;
    input MaxLookback = 60;
    input occurrence = 0;
    def n = occurrence + 1;
    def offset = fold j = MinLookback to MaxLookback + 1 with p=1 while p < n + 1
    do p + ( if p == n then j - n else if cond[j]==yes then 1 else 0 );
    plot price = GetValue(src, offset-1);}
#_inRange(cond) =>
script _inRange {
    input cond = yes;
    input rangeUpper = 60;
    input rangeLower = 5;
    def bars = if cond then 0 else bars[1] + 1;
    def inrange = (rangeLower <= bars) and (bars <= rangeUpper);
    plot retrun = inRange;
}

def pl = findpivots(divSrc,-1, LookBackLeft, LookBackRight);
def ph = findpivots(divSrc, 1, LookBackLeft, LookBackRight);

def plFound = if !isNaN(pl) then 1 else 0;
def phFound = if !isNaN(ph) then 1 else 0;

def vlFound = valuewhen(plFound, divSrc, MinLookback, MaxLookback, 1);
def vhFound = valuewhen(phFound, divSrc, MinLookback, MaxLookback, 1);

def plPrice = valuewhen(plFound, l, MinLookback, MaxLookback, 1);
def phPrice = valuewhen(phFound, h, MinLookback, MaxLookback, 1);

#// Regular Bullish
def oscHL = divSrc > vlFound and _inRange(plFound[1],MaxLookback,MinLookback);
def priceLL = l < plPrice;
def bullCond = DivBull and plFound and oscHL and priceLL;

#// Hidden Bullish
def oscLL = divSrc < vlFound and _inRange(plFound[1],MaxLookback,MinLookback);
def priceHL = l > plPrice;
def hiddenBullCond = DivHiddenBull and plFound and oscLL and priceHL;

#// Regular Bearish
def oscLH = divSrc < vhFound and _inRange(phFound[1],MaxLookback,MinLookback);
def priceHH = h > phPrice;
def bearCond = DivBear and phFound and oscLH and priceHH;

#// Hidden Bearish
def oscHH = divSrc > vhFound and _inRange(phFound[1],MaxLookback,MinLookback);
def priceLH = h < phPrice;
def hiddenBearCond = DivHiddenBear and phFound and oscHH and priceLH;

#------ Bubbles
addchartbubble(bullCond, if Style==0 then rsil else divSrc, "RB", color.GREEN, no);
addchartbubble(bearCond, if Style==0 then rsih else divSrc, "Rb", Color.RED, yes);
addchartbubble(hiddenBullCond, if Style==0 then rsil else divSrc, "HB", color.DARK_GREEN, no);
addchartbubble(hiddenBearCond, if Style==0 then rsih else divSrc, "Hb", color.DARK_RED, yes);
 
View attachment 17190
Creator Message:
As the period value is longer than 14, the RSI value sticks to the value of 50 and becomes useless.

Also, when the period value is less than 14, it moves excessively, so it is difficult for us to see the movement of the RSI .

So, using the period value and the RSI value as variables, I tried to make it easier to identify the RSI value through a new function expression.

This is how RSI Advanced was developed.

Period below 14 reduce the volatility of RSI , and period above 14 increase the volatility of RSI , allowing overbought and oversold zones to work properly and give you a better view of the trend.

By applying the custom algorithm so that the 'RSI Advanced' with period on a 5-minute timeframe has the same value as the 'original RSI' with period on a 60-minute timeframe.

As another example, an 'RSI Advanced' with a period in a 60-minute time frame has the same value as an 'original RSI' with a period in a 240-minute time frame.

CODE:

#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Dicargo_Beam
#indicator('RSI Candle Advanced V2')
declare lower;
input src = close;
input rsiLength = 14;#, 'RSI Length')
input rsiAdvanced = yes;#, 'RSI Advanced ?? (Recommend)')
input plotStyle = {default Candle, Bar, Line};#itle='Candle or Bar or Line?'
input overBought = 70;
input overSold = 30;
input LookBackRight = 5; # "Pivot Lookback Right"
input LookBackLeft = 5; # "Pivot Lookback Left"
input MaxLookback = 60; # "Max of Lookback Range"
input MinLookback = 5; # "Min of Lookback Range"
input DivBull = yes; # "Plot Bullish"
input DivBear = yes; # "Plot Bearish"
input DivHiddenBull = no; # "Plot Hidden Bullish"
input DivHiddenBear = no; # "Plot Hidden Bearish"

def na = Double.NaN;
def last = isNaN(close);
def Style = if plotStyle==plotStyle.Candle then 1 else
if plotStyle==plotStyle.Bar then -1 else 0;
# if plotStyle==plotStyle.Line then 0 else Style[1];
def u = Max(src - src[1], 0);
def d = Max(src[1] - src, 0);

def ru = WildersAverage(u, rsiLength);
def rd = WildersAverage(d, rsiLength);

def a = 1 / rsiLength;

def ruh = a * Max(high - close[1], 0) + (1 - a) * WildersAverage(u, rsiLength)[1];
def rdh = a * Max(close[1] - high, 0) + (1 - a) * WildersAverage(d, rsiLength)[1];

def rul = a * Max(low - close[1], 0) + (1 - a) * WildersAverage(u, rsiLength)[1];
def rdl = a * Max(close[1] - low, 0) + (1 - a) * WildersAverage(d, rsiLength)[1];

def ruo = a * Max(open - close[1], 0) + (1 - a) * WildersAverage(u, rsiLength)[1];
def rdo = a * Max(close[1] - open, 0) + (1 - a) * WildersAverage(d, rsiLength)[1];

#function(rsi, len) =>
script rsifunction {
input rsi = 50;
input len = 14;
def f = -Power(AbsValue(AbsValue(rsi - 50) - 50), 1 + Power(len / 14, 0.618) - 1) / Power(50, Power(len / 14, 0.618) - 1) + 50;
def rsiadvanced = if rsi > 50 then f + 50 else -f + 50;
plot rsifunction = rsiadvanced;
}

def rsiha = 100 - 100 / (1 + ruh / rdh);
def rsila = 100 - 100 / (1 + rul / rdl);
def rsia = 100 - 100 / (1 + ru / rd);
def rsioa = 100 - 100 / (1 + ruo / rdo);

def rsih = if rsiAdvanced then rsifunction(rsiha, rsiLength) else rsiha;
def rsil = if rsiAdvanced then rsifunction(rsila, rsiLength) else rsila;
def rsic = if rsiAdvanced then rsifunction(rsia, rsiLength) else rsia;
def rsio = if rsiAdvanced then rsifunction(rsioa, rsiLength) else rsioa;

def col = open<close;
def cohi = Style>0 and col;
def coLo = Style>0 and !col;
def Barhi = Style<0 and col;
def BarLo = Style<0 and !col;

plot midLine = if last then na else 50;
midLine.SetDefaultColor(Color.DARK_GRAY);
plot obLevel = if last then na else overBought;
obLevel.SetDefaultColor(Color.GRAY);
plot osLevel = if last then na else overSold;
osLevel.SetDefaultColor(Color.GRAY);


plot AdvRsiLine = if Style==0 then rsic else na;#, color=cold)
AdvRsiLine.AssignValueColor(if col then Color.GREEN else Color.RED);

AddChart(high = if cohi then rsih else na, low = if cohi then rsil else na, open = if cohi then rsic else na, close = if cohi then rsio else na,
type = ChartType.CANDLE, growcolor = CreateColor(38,166,154));

AddChart(high = if coLo then rsih else na , low = if coLo then rsil else na, open = if coLo then rsio else na, close = if coLo then rsic else na,
type = ChartType.CANDLE, growcolor = CreateColor(239,83,80));

AddChart(high = if Barhi then rsih else na, low = if Barhi then rsil else na, open = if Barhi then rsic else na, close = if Barhi then rsio else na,
type = ChartType.BAR, growcolor = CreateColor(38,166,154));

AddChart(high = if BarLo then rsih else na , low = if BarLo then rsil else na, open = if BarLo then rsio else na, close = if BarLo then rsic else na,
type = ChartType.BAR, growcolor = CreateColor(239,83,80));

#---- Background
AddCloud(obLevel, osLevel, CreateColor(56,0,56));
#-- Price color


#----Div-----------
def rsisrc = (rsih + rsil) / 2;
def divSrc = rsisrc;

def h = high;
def l = low;

script FindPivots {
input dat = close; # default data or study being evaluated
input HL = 0; # default high or low pivot designation, -1 low, +1 high
input lbL = 5; # default Pivot Lookback Left
input lbR = 1; # default Pivot Lookback Right
##############
def _nan; # used for non-number returns
def _BN; # the current barnumber
def _VStop; # confirms that the lookforward period continues the pivot trend
def _V; # the Value at the actual pivot point
##############
_BN = BarNumber();
_nan = Double.NaN;
_VStop = if !isNaN(dat) and lbr > 0 and lbl > 0 then
fold a = 1 to lbR + 1 with b=1 while b do
if HL > 0 then dat > GetValue(dat,-a) else dat < GetValue(dat,-a) else _nan;
if (HL > 0) {
_V = if _BN > lbL and dat == Highest(dat, lbL+1) and _VStop
then dat else _nan;
} else {
_V = if _BN > lbL and dat == Lowest(dat, lbL+1) and _VStop
then dat else _nan;
}
plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
#valuewhen (Cond, source, lbr, occurrence)
script valuewhen {
input cond = 0;
input src = close;
input MinLookback = 5;
input MaxLookback = 60;
input occurrence = 0;
def n = occurrence + 1;
def offset = fold j = MinLookback to MaxLookback + 1 with p=1 while p < n + 1
do p + ( if p == n then j - n else if cond[j]==yes then 1 else 0 );
plot price = GetValue(src, offset-1);}
#_inRange(cond) =>
script _inRange {
input cond = yes;
input rangeUpper = 60;
input rangeLower = 5;
def bars = if cond then 0 else bars[1] + 1;
def inrange = (rangeLower <= bars) and (bars <= rangeUpper);
plot retrun = inRange;
}
def pl = findpivots(divSrc,-1, LookBackLeft, LookBackRight);
def ph = findpivots(divSrc, 1, LookBackLeft, LookBackRight);

def plFound = if !isNaN(pl) then 1 else 0;
def phFound = if !isNaN(ph) then 1 else 0;

def vlFound = valuewhen(plFound, divSrc, MinLookback, MaxLookback, 1);
def vhFound = valuewhen(phFound, divSrc, MinLookback, MaxLookback, 1);

def plPrice = valuewhen(plFound, l, MinLookback, MaxLookback, 1);
def phPrice = valuewhen(phFound, h, MinLookback, MaxLookback, 1);

#// Regular Bullish
def oscHL = divSrc > vlFound and _inRange(plFound[1],MaxLookback,MinLookback);
def priceLL = l < plPrice;
def bullCond = DivBull and plFound and oscHL and priceLL;
#// Hidden Bullish
def oscLL = divSrc < vlFound and _inRange(plFound[1],MaxLookback,MinLookback);
def priceHL = l > plPrice;
def hiddenBullCond = DivHiddenBull and plFound and oscLL and priceHL;

#// Regular Bearish
def oscLH = divSrc < vhFound and _inRange(phFound[1],MaxLookback,MinLookback);
def priceHH = h > phPrice;
def bearCond = DivBear and phFound and oscLH and priceHH;
#// Hidden Bearish
def oscHH = divSrc > vhFound and _inRange(phFound[1],MaxLookback,MinLookback);
def priceLH = h < phPrice;
def hiddenBearCond = DivHiddenBear and phFound and oscHH and priceLH;

#------ Bubbles
addchartbubble(bullCond, if Style!=0 then rsil else divSrc, "R", color.GREEN, no);
addchartbubble(bearCond, if Style!=0 then rsih else divSrc, "R", CreateColor(156,39,176), yes);
addchartbubble(hiddenBullCond, if Style!=0 then rsil else divSrc, "H", color.DARK_green, no);
addchartbubble(hiddenBearCond, if Style!=0 then rsih else divSrc, "H", color.DARK_red, yes);

#--- END CODE
Do the bubbles take some time to appear? bc for some reason i got to refresh the chart for them to appear. ty
 

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