L3 Banker Fund Flow Trend Oscillator for ThinkOrSwim

@samer800 Is it possible to get an MTF version of this indicator? Thank you so much for all you are doing!
check the below:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © blackcat1402
#study("[blackcat] L3 Banker Fund Flow Trend Oscillator", overlay=false)
# Converted and mod by Sam4Cok@Samer800 - 02/2023
# Update - added option for MTF - 02/2024
declare lower;
#//functions
input BarColor = no;
input timeframe = {default "Chart", "Custom"};
input customTimeframe = AggregationPeriod.FIVE_MIN;
input SmoothingLength = 13;
input SourceType = {default "High/Low", "CCHOL"};
def na = Double.NaN;
def last = IsNaN(close);
def tf = customTimeframe;
def c;
def h;
def l;
def o;
def cchol;
switch (timeframe) {
case "Custom" :
    c = close(Period = tf);
    h = high(Period = tf);
    l = low(Period = tf);
    o = open(Period = tf);
    cchol = (2 * close(Period = tf) + high(Period = tf) + low(Period = tf) + open(Period = tf)) / 5;
default :
    c = close;
    h = high;
    l = low;
    o = open;
    cchol = (2 * close + high + low + open) / 5;
}
#//define typical price for banker fund
#def cchol = (2 * c + h + l + o) / 5;
def hilo = SourceType == SourceType."High/Low";
#xrf(values, length) =>
script xrf {
    input values = close;
    input length = 34;
    def r_val;# = float(na)
    r_val = fold i = 0 to length + 1 with p=values do
            if IsNaN(p) or !IsNaN(values[i]) then values[i] else p;
    plot out = if length >= 1 then r_val else Double.NaN;
}
#xsa(src,len,wei) =>
script xsa {
    input src = close;
    input len = 5;
    input wei = 1;
    def sumf = CompoundValue(1, sumf[1] - src[len] + src , src);
    def ma   = if IsNaN(src[len]) then Double.NaN else sumf / len;
    def out  = if IsNaN(out[1]) then ma else (src * wei + out[1] * (len - wei)) / len;
    plot return = out;
}
def hh = Highest(h, 27);
def ll = Lowest(l, 27);
def wmCal = (c - ll) / (hh - ll) * 100;

#//set up a simple model of banker fund flow trend   
def fundtrend = (3 * xsa(wmCal, 5, 1) - 2 * xsa(xsa(wmCal, 5, 1), 3, 1) - 50) * 1.032 + 50;

#//lowest low with mid term fib # 34
def lol = Lowest(if hilo then l else cchol, 34);
#//highest high with mid term fib # 34
def hoh = Highest(if hilo then h else cchol, 34);
#//define banker fund flow bull bear line
def bullbear = (cchol - lol) / (hoh - lol) * 100;
def bullbearline = ExpAverage(bullbear, SmoothingLength);
#//define banker entry signal
def bankerentry = Crosses(fundtrend, bullbearline, CrossingDirection.ABOVE) and bullbearline < 25;
def bankerExit = Crosses(fundtrend, bullbearline, CrossingDirection.BELOW) and bullbearline > 75;

#//banker increase position with green candle
def UpCandle = if last then na else fundtrend > bullbearline;
def WeakUp   = if last then na else fundtrend < (xrf(fundtrend * 0.95, 1));
def DnCandle = if last then na else fundtrend < bullbearline;
def WeakDn   = if last then na else fundtrend < bullbearline and fundtrend > (xrf(fundtrend * 0.95, 1));

# Plot the new Chart
#//banker fund entry with yellow candle
plot SigUp = if bankerentry and !bankerentry[1] then 15 else 0;
plot SigDn = if bankerExit and !bankerExit[1] then 85 else 100;
SigUp.SetDefaultColor(Color.YELLOW);
SigDn.SetDefaultColor(Color.MAGENTA);

AddChart(high = if UpCandle then bullbearline else na , low = fundtrend , open = fundtrend,  close =  bullbearline,
         type = ChartType.CANDLE, growcolor =  CreateColor(7, 205, 15));

AddChart(high = if WeakUp then bullbearline else na , low = fundtrend , open = fundtrend,  close = bullbearline,
         type = ChartType.CANDLE, growcolor =  Color.LIGHT_GREEN); #CreateColor(188, 245, 188));

AddChart(high = if DnCandle then bullbearline else na , low = fundtrend , open = bullbearline,  close =   fundtrend,
         type = ChartType.CANDLE, growcolor =  Color.RED);

AddChart(high = if WeakDn then bullbearline else na , low = fundtrend , open = bullbearline,  close =   fundtrend,
         type = ChartType.CANDLE, growcolor =  Color.PINK);

#/overbought and oversold threshold lines
def h1 = if last then na else 80;
def h2 = if last then na else 20;
def h3 = 10;
def h4 = 90;
plot h5 = if last then na else 50;
h5.SetDefaultColor(Color.DARK_GRAY);

AddCloud(h2, h3, CreateColor(157, 157, 0));#color=color.yellow,transp=70)
AddCloud(h4, h1, CreateColor(157, 0 , 157));#=color.fuchsia,transp=70)

AssignPriceColor(if !BarColor then Color.CURRENT else
                 if bankerentry then Color.CYAN else
                 if bankerExit then Color.MAGENTA else
                 if WeakDn then Color.DARK_RED else
                 if DnCandle then Color.RED else
                 if WeakUp then Color.DARK_GREEN else
                 if UpCandle then Color.GREEN else Color.CURRENT);



#---- END CODE
 

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

@samer800 Is it possible to add a divergence line? Or is that not supported due to the "AddChart" code?

1717369981466.png
 
I added some colored dots when the indicator is "oversold/overbought". Just add this to the bottom of code.

Code:
plot OB = if fundtrend > 90 and fundtrend < 100 then 105 else na;
plot OBX = if fundtrend > 100 then 105 else na;
OB.SetDefaultColor(Color.DARK_RED);
OBX.SetDefaultColor(Color.white);
OB.SetPaintingStrategy(PaintingStrategy.POINTS);
OBX.SetPaintingStrategy(PaintingStrategy.POINTS);

plot OSX = if fundtrend < 0 then -5 else na;
plot OS = if fundtrend < 10 and fundtrend > 0 then -5 else na;
OS.SetDefaultColor(Color.DARK_GREEN);
OSX.SetDefaultColor(Color.white);
OS.SetPaintingStrategy(PaintingStrategy.POINTS);
OSX.SetPaintingStrategy(PaintingStrategy.POINTS);

1717373309246.png
 
@samer800 Is it possible to add a divergence line? Or is that not supported due to the "AddChart" code?

View attachment 22023
check the below:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © blackcat1402
#study("[blackcat] L3 Banker Fund Flow Trend Oscillator", overlay=false)
# Converted and mod by Sam4Cok@Samer800 - 02/2023
# Update - added option for MTF - 02/2024
# updated - Added plot option and Divergences - 06/2024

declare lower;
#//functions
input BarColor = no;
input plotStyle = {Default "Candles", "Lines"};
input showSignalLine = yes;
input timeframe = {default "Chart", "Custom"};
input customTimeframe = AggregationPeriod.FIFTEEN_MIN;
input SourceType = {"High/Low",default "Open/Close"};
input smoothingType = AverageType.EXPONENTIAL;
input SmoothingLength = 13;
input upperThreshold = 75;
input lowerThreshold = 25;

def na = Double.NaN;
def last = IsNaN(close);
def can = plotStyle==plotStyle."Candles";
def tf = customTimeframe;
def c;
def h;
def l;
def o;
def typ;
switch (timeframe) {
case "Custom" :
    c = close(Period = tf);
    h = high(Period = tf);
    l = low(Period = tf);
    o = open(Period = tf);
    typ = (2 * close(Period = tf) + high(Period = tf) + low(Period = tf) + open(Period = tf)) / 5;
default :
    c = close;
    h = high;
    l = low;
    o = open;
    typ = (2 * close + high + low + open) / 5;
}
#//define typical price for banker fund
def hilo = SourceType == SourceType."High/Low";
def srcHi = if hilo then h else Max(o, c);
def srcLo = if hilo then l else Min(o, c);
#xrf(values, length) =>
script xrf {
    input values = close;
    input length = 34;
    def r_val = fold i = 0 to length + 1 with p=Double.NaN do
            if (IsNaN(p) or !IsNaN(values[i])) then values[i] else p;
    plot out = if length >= 1 then r_val else Double.NaN;
}
#xsa(src,len,wei) =>
script xsa {
    input src = close;
    input len = 5;
    input wei = 1;
    def sumf = CompoundValue(1, sumf[1] - src[len] + src , src);
    def ma   = if IsNaN(src[len]) then Double.NaN else sumf / len;
    def out  = CompoundValue(1, (src * wei + out[1] * (len - wei)) / len, ma);
    plot return = out;
}

def hh = Highest(h, 27);
def ll = Lowest(l, 27);
def wmCal = (c - ll) / (hh - ll) * 100;
def xsaWM5 = xsa(wmCal, 5, 1);
def xsaWM3 = xsa(xsaWM5, 3, 1);
#//set up a simple model of banker fund flow trend   
def fundtrend = (3 * xsaWM5 - 2 * xsaWM3 - 50) * 1.032 + 50;

#//lowest low with mid term fib # 34
def lol = Lowest(srcLo, 34);
#//highest high with mid term fib # 34
def hoh = Highest(srcHi, 34);
#//define banker fund flow bull bear line
def bullbear = (typ - lol) / (hoh - lol) * 100;
def bullbearline = MovingAverage(smoothingType, bullbear, SmoothingLength);
#//define banker entry signal
def bankerentry = (fundtrend Crosses Above bullbearline) and bullbearline < lowerThreshold;
def bankerExit  = (fundtrend Crosses Below bullbearline) and bullbearline > upperThreshold;

#//banker increase position with green candle
def xrf1 = xrf(fundtrend * 0.95, 1);
def UpCandle = if last or !can then na else fundtrend > bullbearline;
def WeakUp   = if last or !can then na else fundtrend < xrf1;
def DnCandle = if last or !can then na else fundtrend < bullbearline;
def WeakDn   = if last or !can then na else fundtrend < bullbearline and fundtrend > xrf1;

#-- clouds
def weak = !can and fundtrend < xrf1;
AddCloud(if weak or weak[1] then fundtrend else na, bullbearline, Color.DARK_GREEN, Color.RED, yes);
AddCloud(if can then na else fundtrend, bullbearline, Color.GREEN, Color.DARK_RED, yes);

# Plot the new Chart
#//banker fund entry with yellow candle
def condUp = bankerentry and !bankerentry[1];
def condDn = bankerExit and !bankerExit[1];
plot SigUp = if !showSignalLine then na else if condUp then 15 else 0;
plot SigDn = if !showSignalLine then na else if condDn then 85 else 100;

SigUp.AssignValueColor(if condUp or condUp[1] then Color.YELLOW else CreateColor(98, 98, 0));
SigDn.AssignValueColor(if condDn or condDn[1] then Color.MAGENTA else CreateColor(98, 0, 98));

AddChart(high = if UpCandle then bullbearline else na , low = fundtrend , open = fundtrend,  close =  bullbearline,
         type = ChartType.CANDLE, growcolor = CreateColor(7, 205, 15));

AddChart(high = if WeakUp then bullbearline else na , low = fundtrend , open = fundtrend,  close = bullbearline,
         type = ChartType.CANDLE, growcolor =  Color.LIGHT_GREEN); #CreateColor(188, 245, 188));

AddChart(high = if DnCandle then bullbearline else na , low = fundtrend , open = bullbearline,  close =   fundtrend,
         type = ChartType.CANDLE, growcolor =  Color.RED);

AddChart(high = if WeakDn then bullbearline else na , low = fundtrend , open = bullbearline,  close =   fundtrend,
         type = ChartType.CANDLE, growcolor =  Color.PINK);

#/overbought and oversold threshold lines
def h1 = if last then na else 80;
def h2 = if last then na else 20;
def h3 = 10;
def h4 = 90;

plot h5 = if last then na else 50;
h5.SetDefaultColor(Color.DARK_GRAY);

AddCloud(h2, h3, CreateColor(117, 117, 0));
AddCloud(h4, h1, Color.PLUM);

#-- bar Color
def col = if isNaN(fundtrend) then col[1] else
         if fundtrend > 100 then 255 else if fundtrend<0 then 0 else fundtrend * 2.55;

AssignPriceColor(if !BarColor then Color.CURRENT else
                 if bankerentry then Color.CYAN else
                 if bankerExit then Color.MAGENTA else CreateColor(255 - col, col, 0));

#----Div-----------
input ShowLastDivLines = yes;
input DivBull = yes;      # "Plot Bullish"
input DivBear = yes;      # "Plot Bearish"
input PivotLookbackRight = 5;  # "Pivot Lookback Right"
input PivotLookbackLeft  = 10; # "Pivot Lookback Left"
input MaxLookback = 60;   # "Max of Lookback Range"
input MinLookback = 5;    # "Min of Lookback Range"

def divSrc = fundtrend;
def maxx = Max(fundtrend, bullbearline);
def minn = Min(fundtrend, bullbearline);

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 + 1 and dat == Highest(dat, lbL + 1) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > lbL + 1 and dat == Lowest(dat, lbL + 1) and _VStop
            then dat else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
#_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, PivotLookbackLeft, PivotLookbackRight);
def ph_ = findpivots(divSrc, 1, PivotLookbackLeft, PivotLookbackRight);
def pl = !isNaN(pl_);
def ph = !isNaN(ph_);
def pll = lowest(divSrc,PivotLookbackLeft +1);
def phh = highest(divSrc,PivotLookbackLeft+1);
def sll = lowest(l, PivotLookbackLeft +1);
def shh = highest(h, PivotLookbackLeft+1);
#-- Pvt Low
def plStart  = if pl then yes else plStart[1];
def plFound  = if (plStart and pl) then 1 else 0;
def vlFound1 = if plFound then divSrc else vlFound1[1];
def vlFound_ = if vlFound1!=vlFound1[1] then vlFound1[1] else vlFound_[1];
def vlFound  = if !vlFound_ then pll else vlFound_;
def plPrice1 = if plFound then l else plPrice1[1];
def plPrice_ = if plPrice1!=plPrice1[1] then plPrice1[1] else plPrice_[1];
def plPrice  = if !plPrice_ then sll else plPrice_;
#-- Pvt High
def phStart = if ph then yes else phStart[1];
def phFound = if (phStart and ph) then 1 else 0;
def vhFound1 = if phFound then divSrc else vhFound1[1];
def vhFound_ = if vhFound1!=vhFound1[1] then vhFound1[1] else vhFound_[1];
def vhFound = if !vhFound_ then phh else vhFound_;
def phPrice1 = if phFound then h else phPrice1[1];
def phPrice_ = if phPrice1!=phPrice1[1] then phPrice1[1] else phPrice_[1];
def phPrice = if !phPrice_ then shh else phPrice_;
#// Regular Bullish
def inRangePl = _inRange(plFound[1],MaxLookback,MinLookback);
def oscHL = divSrc > vlFound and inRangePl;
def priceLL = l < plPrice and divSrc <= 40;
def bullCond = plFound and oscHL and priceLL;

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

#------ Bubbles
def bullBub  = DivBull and bullCond;
def bearBub  = DivBear and bearCond;

addchartbubble(bullBub, minn, "R", Color.CYAN, no);
addchartbubble(bearBub, maxx, "R", CreateColor(176,39,176), yes);

##### Lines
def bar = BarNumber();
#-- Bear Line
def lastPhBar = if ph then bar else lastPhBar[1];
def prePhBar = if lastPhBar!=lastPhBar[1] then lastPhBar[1] else prePhBar[1];
def priorPHBar = if bearCond then prePhBar else priorPHBar[1];
#-- Bull Line
def lastPlBar = if pl then bar else lastPlBar[1];
def prePlBar = if lastPlBar!=lastPlBar[1] then lastPlBar[1] else prePlBar[1];
def priorPLBar = if bullCond then prePlBar else priorPLBar[1];

def lastBullBar = if bullCond then bar else lastBullBar[1];
def lastBearBar = if bearCond then bar else lastBearBar[1];

def hiStart = bar == HighestAll(priorPHBar);
def hiEnd   = bar == HighestAll(lastBearBar);
def loStart = bar == HighestAll(priorPLBar);
def loEnd   = bar == HighestAll(lastBullBar);

def pivotHigh = if hiStart then maxx else if hiEnd then maxx else na;#if HighPivots then bullbearline else na;
def pivotLow  = if loStart then minn else if loEnd then minn else na;

plot PlotHline = if ShowLastDivLines then pivotHigh else na;
PlotHline.EnableApproximation();
PlotHline.SetDefaultColor(Color.WHITE);
PlotHline.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

plot PlotLline = if ShowLastDivLines then pivotLow else na;
PlotLline.EnableApproximation();
PlotLline.SetDefaultColor(Color.CYAN);
PlotLline.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);


#---- END CODE
 
check the below:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © blackcat1402
#study("[blackcat] L3 Banker Fund Flow Trend Oscillator", overlay=false)
# Converted and mod by Sam4Cok@Samer800 - 02/2023
# Update - added option for MTF - 02/2024
# updated - Added plot option and Divergences - 06/2024

declare lower;
#//functions
input BarColor = no;
input plotStyle = {Default "Candles", "Lines"};
input showSignalLine = yes;
input timeframe = {default "Chart", "Custom"};
input customTimeframe = AggregationPeriod.FIFTEEN_MIN;
input SourceType = {"High/Low",default "Open/Close"};
input smoothingType = AverageType.EXPONENTIAL;
input SmoothingLength = 13;
input upperThreshold = 75;
input lowerThreshold = 25;

def na = Double.NaN;
def last = IsNaN(close);
def can = plotStyle==plotStyle."Candles";
def tf = customTimeframe;
def c;
def h;
def l;
def o;
def typ;
switch (timeframe) {
case "Custom" :
    c = close(Period = tf);
    h = high(Period = tf);
    l = low(Period = tf);
    o = open(Period = tf);
    typ = (2 * close(Period = tf) + high(Period = tf) + low(Period = tf) + open(Period = tf)) / 5;
default :
    c = close;
    h = high;
    l = low;
    o = open;
    typ = (2 * close + high + low + open) / 5;
}
#//define typical price for banker fund
def hilo = SourceType == SourceType."High/Low";
def srcHi = if hilo then h else Max(o, c);
def srcLo = if hilo then l else Min(o, c);
#xrf(values, length) =>
script xrf {
    input values = close;
    input length = 34;
    def r_val = fold i = 0 to length + 1 with p=Double.NaN do
            if (IsNaN(p) or !IsNaN(values[i])) then values[i] else p;
    plot out = if length >= 1 then r_val else Double.NaN;
}
#xsa(src,len,wei) =>
script xsa {
    input src = close;
    input len = 5;
    input wei = 1;
    def sumf = CompoundValue(1, sumf[1] - src[len] + src , src);
    def ma   = if IsNaN(src[len]) then Double.NaN else sumf / len;
    def out  = CompoundValue(1, (src * wei + out[1] * (len - wei)) / len, ma);
    plot return = out;
}

def hh = Highest(h, 27);
def ll = Lowest(l, 27);
def wmCal = (c - ll) / (hh - ll) * 100;
def xsaWM5 = xsa(wmCal, 5, 1);
def xsaWM3 = xsa(xsaWM5, 3, 1);
#//set up a simple model of banker fund flow trend  
def fundtrend = (3 * xsaWM5 - 2 * xsaWM3 - 50) * 1.032 + 50;

#//lowest low with mid term fib # 34
def lol = Lowest(srcLo, 34);
#//highest high with mid term fib # 34
def hoh = Highest(srcHi, 34);
#//define banker fund flow bull bear line
def bullbear = (typ - lol) / (hoh - lol) * 100;
def bullbearline = MovingAverage(smoothingType, bullbear, SmoothingLength);
#//define banker entry signal
def bankerentry = (fundtrend Crosses Above bullbearline) and bullbearline < lowerThreshold;
def bankerExit  = (fundtrend Crosses Below bullbearline) and bullbearline > upperThreshold;

#//banker increase position with green candle
def xrf1 = xrf(fundtrend * 0.95, 1);
def UpCandle = if last or !can then na else fundtrend > bullbearline;
def WeakUp   = if last or !can then na else fundtrend < xrf1;
def DnCandle = if last or !can then na else fundtrend < bullbearline;
def WeakDn   = if last or !can then na else fundtrend < bullbearline and fundtrend > xrf1;

#-- clouds
def weak = !can and fundtrend < xrf1;
AddCloud(if weak or weak[1] then fundtrend else na, bullbearline, Color.DARK_GREEN, Color.RED, yes);
AddCloud(if can then na else fundtrend, bullbearline, Color.GREEN, Color.DARK_RED, yes);

# Plot the new Chart
#//banker fund entry with yellow candle
def condUp = bankerentry and !bankerentry[1];
def condDn = bankerExit and !bankerExit[1];
plot SigUp = if !showSignalLine then na else if condUp then 15 else 0;
plot SigDn = if !showSignalLine then na else if condDn then 85 else 100;

SigUp.AssignValueColor(if condUp or condUp[1] then Color.YELLOW else CreateColor(98, 98, 0));
SigDn.AssignValueColor(if condDn or condDn[1] then Color.MAGENTA else CreateColor(98, 0, 98));

AddChart(high = if UpCandle then bullbearline else na , low = fundtrend , open = fundtrend,  close =  bullbearline,
         type = ChartType.CANDLE, growcolor = CreateColor(7, 205, 15));

AddChart(high = if WeakUp then bullbearline else na , low = fundtrend , open = fundtrend,  close = bullbearline,
         type = ChartType.CANDLE, growcolor =  Color.LIGHT_GREEN); #CreateColor(188, 245, 188));

AddChart(high = if DnCandle then bullbearline else na , low = fundtrend , open = bullbearline,  close =   fundtrend,
         type = ChartType.CANDLE, growcolor =  Color.RED);

AddChart(high = if WeakDn then bullbearline else na , low = fundtrend , open = bullbearline,  close =   fundtrend,
         type = ChartType.CANDLE, growcolor =  Color.PINK);

#/overbought and oversold threshold lines
def h1 = if last then na else 80;
def h2 = if last then na else 20;
def h3 = 10;
def h4 = 90;

plot h5 = if last then na else 50;
h5.SetDefaultColor(Color.DARK_GRAY);

AddCloud(h2, h3, CreateColor(117, 117, 0));
AddCloud(h4, h1, Color.PLUM);

#-- bar Color
def col = if isNaN(fundtrend) then col[1] else
         if fundtrend > 100 then 255 else if fundtrend<0 then 0 else fundtrend * 2.55;

AssignPriceColor(if !BarColor then Color.CURRENT else
                 if bankerentry then Color.CYAN else
                 if bankerExit then Color.MAGENTA else CreateColor(255 - col, col, 0));

#----Div-----------
input ShowLastDivLines = yes;
input DivBull = yes;      # "Plot Bullish"
input DivBear = yes;      # "Plot Bearish"
input PivotLookbackRight = 5;  # "Pivot Lookback Right"
input PivotLookbackLeft  = 10; # "Pivot Lookback Left"
input MaxLookback = 60;   # "Max of Lookback Range"
input MinLookback = 5;    # "Min of Lookback Range"

def divSrc = fundtrend;
def maxx = Max(fundtrend, bullbearline);
def minn = Min(fundtrend, bullbearline);

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 + 1 and dat == Highest(dat, lbL + 1) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > lbL + 1 and dat == Lowest(dat, lbL + 1) and _VStop
            then dat else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
#_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, PivotLookbackLeft, PivotLookbackRight);
def ph_ = findpivots(divSrc, 1, PivotLookbackLeft, PivotLookbackRight);
def pl = !isNaN(pl_);
def ph = !isNaN(ph_);
def pll = lowest(divSrc,PivotLookbackLeft +1);
def phh = highest(divSrc,PivotLookbackLeft+1);
def sll = lowest(l, PivotLookbackLeft +1);
def shh = highest(h, PivotLookbackLeft+1);
#-- Pvt Low
def plStart  = if pl then yes else plStart[1];
def plFound  = if (plStart and pl) then 1 else 0;
def vlFound1 = if plFound then divSrc else vlFound1[1];
def vlFound_ = if vlFound1!=vlFound1[1] then vlFound1[1] else vlFound_[1];
def vlFound  = if !vlFound_ then pll else vlFound_;
def plPrice1 = if plFound then l else plPrice1[1];
def plPrice_ = if plPrice1!=plPrice1[1] then plPrice1[1] else plPrice_[1];
def plPrice  = if !plPrice_ then sll else plPrice_;
#-- Pvt High
def phStart = if ph then yes else phStart[1];
def phFound = if (phStart and ph) then 1 else 0;
def vhFound1 = if phFound then divSrc else vhFound1[1];
def vhFound_ = if vhFound1!=vhFound1[1] then vhFound1[1] else vhFound_[1];
def vhFound = if !vhFound_ then phh else vhFound_;
def phPrice1 = if phFound then h else phPrice1[1];
def phPrice_ = if phPrice1!=phPrice1[1] then phPrice1[1] else phPrice_[1];
def phPrice = if !phPrice_ then shh else phPrice_;
#// Regular Bullish
def inRangePl = _inRange(plFound[1],MaxLookback,MinLookback);
def oscHL = divSrc > vlFound and inRangePl;
def priceLL = l < plPrice and divSrc <= 40;
def bullCond = plFound and oscHL and priceLL;

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

#------ Bubbles
def bullBub  = DivBull and bullCond;
def bearBub  = DivBear and bearCond;

addchartbubble(bullBub, minn, "R", Color.CYAN, no);
addchartbubble(bearBub, maxx, "R", CreateColor(176,39,176), yes);

##### Lines
def bar = BarNumber();
#-- Bear Line
def lastPhBar = if ph then bar else lastPhBar[1];
def prePhBar = if lastPhBar!=lastPhBar[1] then lastPhBar[1] else prePhBar[1];
def priorPHBar = if bearCond then prePhBar else priorPHBar[1];
#-- Bull Line
def lastPlBar = if pl then bar else lastPlBar[1];
def prePlBar = if lastPlBar!=lastPlBar[1] then lastPlBar[1] else prePlBar[1];
def priorPLBar = if bullCond then prePlBar else priorPLBar[1];

def lastBullBar = if bullCond then bar else lastBullBar[1];
def lastBearBar = if bearCond then bar else lastBearBar[1];

def hiStart = bar == HighestAll(priorPHBar);
def hiEnd   = bar == HighestAll(lastBearBar);
def loStart = bar == HighestAll(priorPLBar);
def loEnd   = bar == HighestAll(lastBullBar);

def pivotHigh = if hiStart then maxx else if hiEnd then maxx else na;#if HighPivots then bullbearline else na;
def pivotLow  = if loStart then minn else if loEnd then minn else na;

plot PlotHline = if ShowLastDivLines then pivotHigh else na;
PlotHline.EnableApproximation();
PlotHline.SetDefaultColor(Color.WHITE);
PlotHline.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

plot PlotLline = if ShowLastDivLines then pivotLow else na;
PlotLline.EnableApproximation();
PlotLline.SetDefaultColor(Color.CYAN);
PlotLline.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);


#---- END CODE
Wow, that looks fantastic! You are so amazing! I salute you!!
 
Any Chance I can get someone to create a custom watchlist column kind of like the ttm squeeze histogram columns but for the L3 Banker indicator. I'd like to set up 3 columns for different time frames. 3 min, 15 min and 1 hour.
 
View attachment 17706

Author Message:

Background
The large funds or banker fund are often referred to as Whale. Whale can have a significant impact on the price movements in various markets, especially in cryptocurrency . Therefore, how to monitor Whale trends is of great significance both in terms of fundamentals and technical aspects.

Function
L3 Banker Fund Flow Trend Oscillator can give you a model of complete banker fund flow operation in cycles. Although the script is not so complicated, it is comprehensive to disclose the price trend. That is the reason why I list this as Level 3. Each cycle of banker fund flow may have 5 steps in max as entry, increase position, decrease position, exit, and weak rebound for exit.

Key Signal
1. banker fund entry with blue candle
2. banker increase position with green candle
3. banker decrease position with white candle
4. banker fund exit/quit with red candle
5. banker fund weak rebound with pink candle

Pros and Cons
Pros:
1. Model banker fund behavior in complete cycles
2. Overbought and oversold can be directly observed due to oscillator nature
3. the transition points are clear for entry or exit

Cons:
1. Simple modelling, no further complex behaviors can be disclosed
2. trade by trend following the banker fund, it is still under the trend analysis prerequisite

CODE - Upper Study - 08/2024

CSS:
#// Indicator for TOS
#// @ozgurhan
# inspired from [blackcat] L3 Banker Fund Flow Trend Oscillator" script by © blackcat1402
# indicator('Support Resistance', overlay=true)
# Converted by Sam4Cok@Samer800    - 08/2024
#//functions
input BarColor = no;
input displayOptions = {Default "Banker Entry", "Banker Exit", "Banker Entry/Exit"};
input SourceType = {default "High/Low", "Open/Close"};
input smoothingType = AverageType.EXPONENTIAL;
input SmoothingLength = 13;
input upperThreshold = 75;
input lowerThreshold = 25;

def na = Double.NaN;
def last = IsNaN(close);
def entext = displayOptions==displayOptions."Banker Entry/Exit";
def enter = displayOptions==displayOptions."Banker Entry" or entext;
def exit = displayOptions==displayOptions."Banker Exit" or entext;
def typ = (2 * close + high + low + open) / 5;
def srcHi;
def srcLo;

switch (SourceType) {
case "Open/Close" :
    srcHi = Max(open, close);
    srcLo = Min(open, close);
default :
    srcHi = high;
    srcLo = low ;
}
#xsa(src,len,wei) =>
script xsa {
    input src = close;
    input len = 5;
    input wei = 1;
    def sumf = CompoundValue(1, sumf[1] - src[len] + src , src);
    def ma   = if IsNaN(src[len]) then 0 else sumf / len;
    def out  = CompoundValue(1, (src * wei + out[1] * (len - wei)) / len, ma);
    plot return = out;
}

def hh = Highest(srcHi, 27);
def ll = Lowest(srcLo, 27);
def wmCal = (close - ll) / (hh - ll) * 100;
def xsaWM5 = xsa(wmCal, 5, 1);
def xsaWM3 = xsa(xsaWM5, 3, 1);
#//set up a simple model of banker fund flow trend  
def fundtrend = (3 * xsaWM5 - 2 * xsaWM3 - 50) * 1.032 + 50;

#//lowest low with mid term fib # 34
def lol = Lowest(srcLo, 34);
#//highest high with mid term fib # 34
def hoh = Highest(srcHi, 34);
#//define banker fund flow bull bear line
def bullbear = (typ - lol) / (hoh - lol) * 100;
def bullbearline = MovingAverage(smoothingType, bullbear, SmoothingLength);
#//define banker entry signal
def bankerentry = if !enter then na else
            (fundtrend>bullbearline) and (fundtrend[1]<=bullbearline[1]) and bullbearline<lowerThreshold;
def bankerExit  = if !exit then na else
            (fundtrend<bullbearline) and (fundtrend[1]>=bullbearline[1]) and bullbearline>upperThreshold;

def bar = BarNumber();
def price1;
def cnt1;
def price2;
def cnt2;
def price3;
def cnt3;
def price4;
def cnt4;
def price5;
def cnt5;
if bankerentry {
    price5 = price4[1];
    price4 = price3[1];
    price3 = price2[1];
    price2 = price1[1];
    price1 = close;
    cnt5   = cnt4[1];
    cnt4   = cnt3[1];
    cnt3   = cnt2[1];
    cnt2   = cnt1[1];
    cnt1   = bar;
} else {
    price5 = price5[1];
    price4 = price4[1];
    price3 = price3[1];
    price2 = price2[1];
    price1 = price1[1];
    cnt5   = cnt5[1];
    cnt4   = cnt4[1];
    cnt3   = cnt3[1];
    cnt2   = cnt2[1];
    cnt1   = cnt1[1];
}
def start = Min(cnt2, cnt1);
def p5 = if price5 then HighestAll(InertiaAll(price5, 2)) else p5[1];
def p4 = if price4 then HighestAll(InertiaAll(price4, 2)) else p4[1];
def p3 = if price3 then HighestAll(InertiaAll(price3, 2)) else p3[1];
def p2 = if price2 then HighestAll(InertiaAll(price2, 2)) else p2[1];
def p1 = if price1 then HighestAll(InertiaAll(price1, 2)) else p1[1];

def l5 = if bar >= HighestAll(cnt5) then p5 else na;
def l4 = if bar >= HighestAll(cnt4) then p4 else na;
def l3 = if bar >= HighestAll(cnt3) then p3 else na;
def Top = if bar >= HighestAll(start) then p2 else na;
def Bot = if bar >= HighestAll(start) then p1 else na;
def limitUp = if Top and Bot then Max(Top, Bot) else na;
def limitDn = if Top and Bot then Min(Top, Bot) else na;

def crossed_above = if high > limitUp then 1 else
                    if low  < limitDn then -1 else crossed_above[1];
def cross = if last then cross[1] else crossed_above;
def col = HighestAll(InertiaAll(cross, 2));

plot boxTop = if !last and Top then Top else na;
plot boxBot = if !last and Bot then Bot else na;
boxTop.AssignValueColor(if col > 0 then Color.GREEN else
                        if col < 0 then Color.RED else Color.GRAY);
boxBot.AssignValueColor(if col > 0 then Color.GREEN else
                        if col < 0 then Color.RED else Color.GRAY);

plot Line5 = if !last and l5 then l5 else na;
plot Line4 = if !last and l4 then l4 else na;
plot Line3 = if !last and l3 then l3 else na;
Line5.SetStyle(Curve.MEDIUM_DASH);
Line4.SetStyle(Curve.MEDIUM_DASH);
Line3.SetStyle(Curve.MEDIUM_DASH);
Line5.AssignValueColor(if col > 0 then Color.DARK_GREEN else
                       if col < 0 then Color.DARK_RED else Color.GRAY);
Line4.AssignValueColor(if col > 0 then Color.DARK_GREEN else
                       if col < 0 then Color.DARK_RED else Color.GRAY);
Line3.AssignValueColor(if col > 0 then Color.DARK_GREEN else
                       if col < 0 then Color.DARK_RED else Color.GRAY);

#-- Cloud

AddCloud(if last then na else
         if col > 0 then limitUp else limitDn,
         if col > 0 then limitDn else limitUp, Color.DARK_GREEN, Color.DARK_RED);

#-- exit
def priceE1;
def cntE1;
def priceE2;
def cntE2;
def priceE3;
def cntE3;
def priceE4;
def cntE4;
def priceE5;
def cntE5;
if bankerExit {
    priceE5 = priceE4[1];
    priceE4 = priceE3[1];
    priceE3 = priceE2[1];
    priceE2 = priceE1[1];
    priceE1 = close;
    cntE5   = cntE4[1];
    cntE4   = cntE3[1];
    cntE3   = cntE2[1];
    cntE2   = cntE1[1];
    cntE1   = bar;
} else {
    priceE5 = priceE5[1];
    priceE4 = priceE4[1];
    priceE3 = priceE3[1];
    priceE2 = priceE2[1];
    priceE1 = priceE1[1];
    cntE5   = cntE5[1];
    cntE4   = cntE4[1];
    cntE3   = cntE3[1];
    cntE2   = cntE2[1];
    cntE1   = cntE1[1];
}
def startE = Min(cntE2, cntE1);
def pE5 = if priceE5 then HighestAll(InertiaAll(priceE5, 2)) else pE5[1];
def pE4 = if priceE4 then HighestAll(InertiaAll(priceE4, 2)) else pE4[1];
def pE3 = if priceE3 then HighestAll(InertiaAll(priceE3, 2)) else pE3[1];
def pE2 = if priceE2 then HighestAll(InertiaAll(priceE2, 2)) else pE2[1];
def pE1 = if priceE1 then HighestAll(InertiaAll(priceE1, 2)) else pE1[1];

def lE5 = if bar >= HighestAll(cntE5) then pE5 else na;
def lE4 = if bar >= HighestAll(cntE4) then pE4 else na;
def lE3 = if bar >= HighestAll(cntE3) then pE3 else na;
def TopE = if bar >= HighestAll(startE) then pE2 else na;
def BotE = if bar >= HighestAll(startE) then pE1 else na;
def limitUpE = if TopE and BotE then Max(TopE, BotE) else na;
def limitDnE = if TopE and BotE then Min(TopE, BotE) else na;

def crossed_Below = if high > limitUpE then -1 else
                    if low  < limitDnE then 1 else crossed_Below[1];
def crossE = if last then crossE[1] else crossed_below;
def colE = HighestAll(InertiaAll(crossE, 2));

plot boxTopE = if !last and TopE then TopE else na;
plot boxBotE = if !last and BotE then BotE else na;
boxTopE.AssignValueColor(if colE > 0 then Color.GREEN else
                         if colE < 0 then Color.RED else Color.GRAY);
boxBotE.AssignValueColor(if colE > 0 then Color.GREEN else
                         if colE < 0 then Color.RED else Color.GRAY);

plot LineE5 = if !last and lE5 then lE5 else na;
plot LineE4 = if !last and lE4 then lE4 else na;
plot LineE3 = if !last and lE3 then lE3 else na;
LineE5.SetStyle(Curve.MEDIUM_DASH);
LineE4.SetStyle(Curve.MEDIUM_DASH);
LineE3.SetStyle(Curve.MEDIUM_DASH);
LineE5.AssignValueColor(if colE > 0 then Color.DARK_GREEN else
                        if colE < 0 then Color.DARK_RED else Color.GRAY);
LineE4.AssignValueColor(if colE > 0 then Color.DARK_GREEN else
                        if colE < 0 then Color.DARK_RED else Color.GRAY);
LineE3.AssignValueColor(if colE > 0 then Color.DARK_GREEN else
                        if colE < 0 then Color.DARK_RED else Color.GRAY);

#-- Cloud

AddCloud(if last then na else
         if colE > 0 then limitUpE else limitDnE,
         if colE > 0 then limitDnE else limitUpE, Color.DARK_GREEN, Color.DARK_RED);

#---- END CODE

CODE - Lower Study - Added divergences and plot style - 06/2024

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © blackcat1402
#study("[blackcat] L3 Banker Fund Flow Trend Oscillator", overlay=false)
# Converted and mod by Sam4Cok@Samer800 - 02/2023
# Update - added option for MTF - 02/2024
# updated - Added plot option and Divergences - 06/2024

declare lower;
#//functions
input BarColor = no;
input plotStyle = {Default "Candles", "Lines"};
input showSignalLine = yes;
input timeframe = {default "Chart", "Custom"};
input customTimeframe = AggregationPeriod.FIFTEEN_MIN;
input SourceType = {"High/Low",default "Open/Close"};
input smoothingType = AverageType.EXPONENTIAL;
input SmoothingLength = 13;
input upperThreshold = 75;
input lowerThreshold = 25;

def na = Double.NaN;
def last = IsNaN(close);
def can = plotStyle==plotStyle."Candles";
def tf = customTimeframe;
def c;
def h;
def l;
def o;
def typ;
switch (timeframe) {
case "Custom" :
    c = close(Period = tf);
    h = high(Period = tf);
    l = low(Period = tf);
    o = open(Period = tf);
    typ = (2 * close(Period = tf) + high(Period = tf) + low(Period = tf) + open(Period = tf)) / 5;
default :
    c = close;
    h = high;
    l = low;
    o = open;
    typ = (2 * close + high + low + open) / 5;
}
#//define typical price for banker fund
def hilo = SourceType == SourceType."High/Low";
def srcHi = if hilo then h else Max(o, c);
def srcLo = if hilo then l else Min(o, c);
#xrf(values, length) =>
script xrf {
    input values = close;
    input length = 34;
    def r_val = fold i = 0 to length + 1 with p=Double.NaN do
            if (IsNaN(p) or !IsNaN(values[i])) then values[i] else p;
    plot out = if length >= 1 then r_val else Double.NaN;
}
#xsa(src,len,wei) =>
script xsa {
    input src = close;
    input len = 5;
    input wei = 1;
    def sumf = CompoundValue(1, sumf[1] - src[len] + src , src);
    def ma   = if IsNaN(src[len]) then Double.NaN else sumf / len;
    def out  = CompoundValue(1, (src * wei + out[1] * (len - wei)) / len, ma);
    plot return = out;
}

def hh = Highest(h, 27);
def ll = Lowest(l, 27);
def wmCal = (c - ll) / (hh - ll) * 100;
def xsaWM5 = xsa(wmCal, 5, 1);
def xsaWM3 = xsa(xsaWM5, 3, 1);
#//set up a simple model of banker fund flow trend 
def fundtrend = (3 * xsaWM5 - 2 * xsaWM3 - 50) * 1.032 + 50;

#//lowest low with mid term fib # 34
def lol = Lowest(srcLo, 34);
#//highest high with mid term fib # 34
def hoh = Highest(srcHi, 34);
#//define banker fund flow bull bear line
def bullbear = (typ - lol) / (hoh - lol) * 100;
def bullbearline = MovingAverage(smoothingType, bullbear, SmoothingLength);
#//define banker entry signal
def bankerentry = (fundtrend Crosses Above bullbearline) and bullbearline < lowerThreshold;
def bankerExit  = (fundtrend Crosses Below bullbearline) and bullbearline > upperThreshold;

#//banker increase position with green candle
def xrf1 = xrf(fundtrend * 0.95, 1);
def UpCandle = if last or !can then na else fundtrend > bullbearline;
def WeakUp   = if last or !can then na else fundtrend < xrf1;
def DnCandle = if last or !can then na else fundtrend < bullbearline;
def WeakDn   = if last or !can then na else fundtrend < bullbearline and fundtrend > xrf1;

#-- clouds
def weak = !can and fundtrend < xrf1;
AddCloud(if weak or weak[1] then fundtrend else na, bullbearline, Color.DARK_GREEN, Color.RED, yes);
AddCloud(if can then na else fundtrend, bullbearline, Color.GREEN, Color.DARK_RED, yes);

# Plot the new Chart
#//banker fund entry with yellow candle
def condUp = bankerentry and !bankerentry[1];
def condDn = bankerExit and !bankerExit[1];
plot SigUp = if !showSignalLine then na else if condUp then 15 else 0;
plot SigDn = if !showSignalLine then na else if condDn then 85 else 100;

SigUp.AssignValueColor(if condUp or condUp[1] then Color.YELLOW else CreateColor(98, 98, 0));
SigDn.AssignValueColor(if condDn or condDn[1] then Color.MAGENTA else CreateColor(98, 0, 98));

AddChart(high = if UpCandle then bullbearline else na , low = fundtrend , open = fundtrend,  close =  bullbearline,
         type = ChartType.CANDLE, growcolor = CreateColor(7, 205, 15));

AddChart(high = if WeakUp then bullbearline else na , low = fundtrend , open = fundtrend,  close = bullbearline,
         type = ChartType.CANDLE, growcolor =  Color.LIGHT_GREEN); #CreateColor(188, 245, 188));

AddChart(high = if DnCandle then bullbearline else na , low = fundtrend , open = bullbearline,  close =   fundtrend,
         type = ChartType.CANDLE, growcolor =  Color.RED);

AddChart(high = if WeakDn then bullbearline else na , low = fundtrend , open = bullbearline,  close =   fundtrend,
         type = ChartType.CANDLE, growcolor =  Color.PINK);

#/overbought and oversold threshold lines
def h1 = if last then na else 80;
def h2 = if last then na else 20;
def h3 = 10;
def h4 = 90;

plot h5 = if last then na else 50;
h5.SetDefaultColor(Color.DARK_GRAY);

AddCloud(h2, h3, CreateColor(117, 117, 0));
AddCloud(h4, h1, Color.PLUM);

#-- bar Color
def col = if isNaN(fundtrend) then col[1] else
         if fundtrend > 100 then 255 else if fundtrend<0 then 0 else fundtrend * 2.55;

AssignPriceColor(if !BarColor then Color.CURRENT else
                 if bankerentry then Color.CYAN else
                 if bankerExit then Color.MAGENTA else CreateColor(255 - col, col, 0));

#----Div-----------
input ShowLastDivLines = yes;
input DivBull = yes;      # "Plot Bullish"
input DivBear = yes;      # "Plot Bearish"
input PivotLookbackRight = 5;  # "Pivot Lookback Right"
input PivotLookbackLeft  = 10; # "Pivot Lookback Left"
input MaxLookback = 60;   # "Max of Lookback Range"
input MinLookback = 5;    # "Min of Lookback Range"

def divSrc = fundtrend;
def maxx = Max(fundtrend, bullbearline);
def minn = Min(fundtrend, bullbearline);

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 + 1 and dat == Highest(dat, lbL + 1) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > lbL + 1 and dat == Lowest(dat, lbL + 1) and _VStop
            then dat else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
#_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, PivotLookbackLeft, PivotLookbackRight);
def ph_ = findpivots(divSrc, 1, PivotLookbackLeft, PivotLookbackRight);
def pl = !isNaN(pl_);
def ph = !isNaN(ph_);
def pll = lowest(divSrc,PivotLookbackLeft +1);
def phh = highest(divSrc,PivotLookbackLeft+1);
def sll = lowest(l, PivotLookbackLeft +1);
def shh = highest(h, PivotLookbackLeft+1);
#-- Pvt Low
def plStart  = if pl then yes else plStart[1];
def plFound  = if (plStart and pl) then 1 else 0;
def vlFound1 = if plFound then divSrc else vlFound1[1];
def vlFound_ = if vlFound1!=vlFound1[1] then vlFound1[1] else vlFound_[1];
def vlFound  = if !vlFound_ then pll else vlFound_;
def plPrice1 = if plFound then l else plPrice1[1];
def plPrice_ = if plPrice1!=plPrice1[1] then plPrice1[1] else plPrice_[1];
def plPrice  = if !plPrice_ then sll else plPrice_;
#-- Pvt High
def phStart = if ph then yes else phStart[1];
def phFound = if (phStart and ph) then 1 else 0;
def vhFound1 = if phFound then divSrc else vhFound1[1];
def vhFound_ = if vhFound1!=vhFound1[1] then vhFound1[1] else vhFound_[1];
def vhFound = if !vhFound_ then phh else vhFound_;
def phPrice1 = if phFound then h else phPrice1[1];
def phPrice_ = if phPrice1!=phPrice1[1] then phPrice1[1] else phPrice_[1];
def phPrice = if !phPrice_ then shh else phPrice_;
#// Regular Bullish
def inRangePl = _inRange(plFound[1],MaxLookback,MinLookback);
def oscHL = divSrc > vlFound and inRangePl;
def priceLL = l < plPrice and divSrc <= 40;
def bullCond = plFound and oscHL and priceLL;

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

#------ Bubbles
def bullBub  = DivBull and bullCond;
def bearBub  = DivBear and bearCond;

addchartbubble(bullBub, minn, "R", Color.CYAN, no);
addchartbubble(bearBub, maxx, "R", CreateColor(176,39,176), yes);

##### Lines
def bar = BarNumber();
#-- Bear Line
def lastPhBar = if ph then bar else lastPhBar[1];
def prePhBar = if lastPhBar!=lastPhBar[1] then lastPhBar[1] else prePhBar[1];
def priorPHBar = if bearCond then prePhBar else priorPHBar[1];
#-- Bull Line
def lastPlBar = if pl then bar else lastPlBar[1];
def prePlBar = if lastPlBar!=lastPlBar[1] then lastPlBar[1] else prePlBar[1];
def priorPLBar = if bullCond then prePlBar else priorPLBar[1];

def lastBullBar = if bullCond then bar else lastBullBar[1];
def lastBearBar = if bearCond then bar else lastBearBar[1];

def hiStart = bar == HighestAll(priorPHBar);
def hiEnd   = bar == HighestAll(lastBearBar);
def loStart = bar == HighestAll(priorPLBar);
def loEnd   = bar == HighestAll(lastBullBar);

def pivotHigh = if hiStart then maxx else if hiEnd then maxx else na;#if HighPivots then bullbearline else na;
def pivotLow  = if loStart then minn else if loEnd then minn else na;

plot PlotHline = if ShowLastDivLines then pivotHigh else na;
PlotHline.EnableApproximation();
PlotHline.SetDefaultColor(Color.WHITE);
PlotHline.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

plot PlotLline = if ShowLastDivLines then pivotLow else na;
PlotLline.EnableApproximation();
PlotLline.SetDefaultColor(Color.CYAN);
PlotLline.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);


#---- END CODE
CODE :

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © blackcat1402
#study("[blackcat] L3 Banker Fund Flow Trend Oscillator", overlay=false)
# Converted and mod by Sam4Cok@Samer800 - 02/2023
declare lower;
#//functions
input BarColor = yes;
input SmoothingLength = 13;
def na = Double.NaN;
def last = isNaN(close[1]);
#xrf(values, length) =>
script xrf {
    input values = close;
    input length = 34;
    def r_val;# = float(na)
    r_val = if length >= 1 then
                fold i = 0 to length +1 with p=values do
             if IsNaN(p) or !IsNaN(values[i]) then values[i] else p else Double.NaN;
    plot out = r_val;
}
#xsa(src,len,wei) =>
script xsa {
    input src = close;
    input len = 5;
    input wei = 1;
    def sumf;# = 0.0
    def ma;# = 0.0
    def out;# = 0.0
    sumf = CompoundValue(1, sumf[1] - src[len] + src , src);
    ma   = if IsNaN(src[len]) then Double.NaN else sumf / len;
    out  = if IsNaN(out[1]) then ma else (src * wei + out[1] * (len - wei)) / len;
    plot return = out;
}
def wmCal = (close - Lowest(low, 27)) / (Highest(high, 27) - Lowest(low, 27)) * 100;

#//set up a simple model of banker fund flow trend
def fundtrend = (3 * xsa(wmCal, 5, 1) - 2 * xsa(xsa(wmCal, 5, 1), 3, 1) - 50) * 1.032 + 50;
#//define typical price for banker fund
def typ = (2 * close + high + low + open) / 5;
#//lowest low with mid term fib # 34
def lol = Lowest(low, 34);
#//highest high with mid term fib # 34
def hoh = Highest(high, 34);
#//define banker fund flow bull bear line
def bullbear = (typ - lol) / (hoh - lol) * 100;
def bullbearline = ExpAverage(bullbear, SmoothingLength);
#//define banker entry signal
def bankerentry = Crosses(fundtrend, bullbearline, CrossingDirection.ABOVE) and bullbearline < 25;

#//banker increase position with green candle
def UpCandle = fundtrend > bullbearline;
def WeakUp   = fundtrend < (xrf(fundtrend * 0.95, 1));
def DnCandle = fundtrend < bullbearline;
def WeakDn   = fundtrend < bullbearline and fundtrend > (xrf(fundtrend * 0.95, 1));

# Plot the new Chart
#//banker fund entry with yellow candle
AddChart(high = if bankerentry then 100 else na, low = 0 , open = 100,  close = 0,
         type = ChartType.CANDLE, growcolor =  CreateColor(26, 70, 85));

AddChart(high = if UpCandle then bullbearline else na , low = fundtrend , open = fundtrend,  close =  bullbearline,
         type = ChartType.CANDLE, growcolor =  CreateColor(7,205,15));

AddChart(high = if WeakUp then bullbearline else na , low = fundtrend , open = fundtrend,  close = bullbearline,
         type = ChartType.CANDLE, growcolor =  CreateColor(188,245,188));

AddChart(high = if DnCandle then bullbearline else na , low = fundtrend , open = bullbearline,  close =   fundtrend,
         type = ChartType.CANDLE, growcolor =  Color.RED);

AddChart(high = if WeakDn then bullbearline else na , low = fundtrend , open = bullbearline,  close =   fundtrend,
         type = ChartType.CANDLE, growcolor =  Color.PINK);

#/overbought and oversold threshold lines
def h1 = if last then na else 80;
def h2 = if last then na else 20;
def h3 = 10;
def h4 = 90;
plot h5 = if last then na else 50;
h5.SetDefaultColor(Color.DARK_GRAY);

AddCloud(h2, h3, CreateColor(157,157,0));#color=color.yellow,transp=70)
AddCloud(h4, h1, CreateColor(157,0 ,157));#=color.fuchsia,transp=70)

AssignPriceColor(if !BarColor then Color.CURRENT else
                 if bankerentry then Color.CYAN else
                 if WeakDn then Color.DARK_RED else
                 if DnCandle then Color.RED else
                 if WeakUp then Color.DARK_GREEN else
                 if UpCandle then Color.GREEN else Color.CURRENT);



#---- END CODE
Hi, there is a scanner for bankentry, may I know if there any way to scan when the divergence has formed?
 
@samer800
Thanks for your post. You show three different blocks of code. I understand the first two. What does the third set of code do for you. ---- "B"

I have installed your first two sets of code. I am not seeing any blue nor white candles. I'm not sure why. --- "B"
 
Last edited by a moderator:
View attachment 17706

Author Message:

Background
The large funds or banker fund are often referred to as Whale. Whale can have a significant impact on the price movements in various markets, especially in cryptocurrency . Therefore, how to monitor Whale trends is of great significance both in terms of fundamentals and technical aspects.

Function
L3 Banker Fund Flow Trend Oscillator can give you a model of complete banker fund flow operation in cycles. Although the script is not so complicated, it is comprehensive to disclose the price trend. That is the reason why I list this as Level 3. Each cycle of banker fund flow may have 5 steps in max as entry, increase position, decrease position, exit, and weak rebound for exit.

Key Signal
1. banker fund entry with blue candle
2. banker increase position with green candle
3. banker decrease position with white candle
4. banker fund exit/quit with red candle
5. banker fund weak rebound with pink candle

Pros and Cons
Pros:
1. Model banker fund behavior in complete cycles
2. Overbought and oversold can be directly observed due to oscillator nature
3. the transition points are clear for entry or exit

Cons:
1. Simple modelling, no further complex behaviors can be disclosed
2. trade by trend following the banker fund, it is still under the trend analysis prerequisite

CODE - Upper Study - 08/2024

CSS:
#// Indicator for TOS
#// @ozgurhan
# inspired from [blackcat] L3 Banker Fund Flow Trend Oscillator" script by © blackcat1402
# indicator('Support Resistance', overlay=true)
# Converted by Sam4Cok@Samer800    - 08/2024
#//functions
input BarColor = no;
input displayOptions = {Default "Banker Entry", "Banker Exit", "Banker Entry/Exit"};
input SourceType = {default "High/Low", "Open/Close"};
input smoothingType = AverageType.EXPONENTIAL;
input SmoothingLength = 13;
input upperThreshold = 75;
input lowerThreshold = 25;

def na = Double.NaN;
def last = IsNaN(close);
def entext = displayOptions==displayOptions."Banker Entry/Exit";
def enter = displayOptions==displayOptions."Banker Entry" or entext;
def exit = displayOptions==displayOptions."Banker Exit" or entext;
def typ = (2 * close + high + low + open) / 5;
def srcHi;
def srcLo;

switch (SourceType) {
case "Open/Close" :
    srcHi = Max(open, close);
    srcLo = Min(open, close);
default :
    srcHi = high;
    srcLo = low ;
}
#xsa(src,len,wei) =>
script xsa {
    input src = close;
    input len = 5;
    input wei = 1;
    def sumf = CompoundValue(1, sumf[1] - src[len] + src , src);
    def ma   = if IsNaN(src[len]) then 0 else sumf / len;
    def out  = CompoundValue(1, (src * wei + out[1] * (len - wei)) / len, ma);
    plot return = out;
}

def hh = Highest(srcHi, 27);
def ll = Lowest(srcLo, 27);
def wmCal = (close - ll) / (hh - ll) * 100;
def xsaWM5 = xsa(wmCal, 5, 1);
def xsaWM3 = xsa(xsaWM5, 3, 1);
#//set up a simple model of banker fund flow trend 
def fundtrend = (3 * xsaWM5 - 2 * xsaWM3 - 50) * 1.032 + 50;

#//lowest low with mid term fib # 34
def lol = Lowest(srcLo, 34);
#//highest high with mid term fib # 34
def hoh = Highest(srcHi, 34);
#//define banker fund flow bull bear line
def bullbear = (typ - lol) / (hoh - lol) * 100;
def bullbearline = MovingAverage(smoothingType, bullbear, SmoothingLength);
#//define banker entry signal
def bankerentry = if !enter then na else
            (fundtrend>bullbearline) and (fundtrend[1]<=bullbearline[1]) and bullbearline<lowerThreshold;
def bankerExit  = if !exit then na else
            (fundtrend<bullbearline) and (fundtrend[1]>=bullbearline[1]) and bullbearline>upperThreshold;

def bar = BarNumber();
def price1;
def cnt1;
def price2;
def cnt2;
def price3;
def cnt3;
def price4;
def cnt4;
def price5;
def cnt5;
if bankerentry {
    price5 = price4[1];
    price4 = price3[1];
    price3 = price2[1];
    price2 = price1[1];
    price1 = close;
    cnt5   = cnt4[1];
    cnt4   = cnt3[1];
    cnt3   = cnt2[1];
    cnt2   = cnt1[1];
    cnt1   = bar;
} else {
    price5 = price5[1];
    price4 = price4[1];
    price3 = price3[1];
    price2 = price2[1];
    price1 = price1[1];
    cnt5   = cnt5[1];
    cnt4   = cnt4[1];
    cnt3   = cnt3[1];
    cnt2   = cnt2[1];
    cnt1   = cnt1[1];
}
def start = Min(cnt2, cnt1);
def p5 = if price5 then HighestAll(InertiaAll(price5, 2)) else p5[1];
def p4 = if price4 then HighestAll(InertiaAll(price4, 2)) else p4[1];
def p3 = if price3 then HighestAll(InertiaAll(price3, 2)) else p3[1];
def p2 = if price2 then HighestAll(InertiaAll(price2, 2)) else p2[1];
def p1 = if price1 then HighestAll(InertiaAll(price1, 2)) else p1[1];

def l5 = if bar >= HighestAll(cnt5) then p5 else na;
def l4 = if bar >= HighestAll(cnt4) then p4 else na;
def l3 = if bar >= HighestAll(cnt3) then p3 else na;
def Top = if bar >= HighestAll(start) then p2 else na;
def Bot = if bar >= HighestAll(start) then p1 else na;
def limitUp = if Top and Bot then Max(Top, Bot) else na;
def limitDn = if Top and Bot then Min(Top, Bot) else na;

def crossed_above = if high > limitUp then 1 else
                    if low  < limitDn then -1 else crossed_above[1];
def cross = if last then cross[1] else crossed_above;
def col = HighestAll(InertiaAll(cross, 2));

plot boxTop = if !last and Top then Top else na;
plot boxBot = if !last and Bot then Bot else na;
boxTop.AssignValueColor(if col > 0 then Color.GREEN else
                        if col < 0 then Color.RED else Color.GRAY);
boxBot.AssignValueColor(if col > 0 then Color.GREEN else
                        if col < 0 then Color.RED else Color.GRAY);

plot Line5 = if !last and l5 then l5 else na;
plot Line4 = if !last and l4 then l4 else na;
plot Line3 = if !last and l3 then l3 else na;
Line5.SetStyle(Curve.MEDIUM_DASH);
Line4.SetStyle(Curve.MEDIUM_DASH);
Line3.SetStyle(Curve.MEDIUM_DASH);
Line5.AssignValueColor(if col > 0 then Color.DARK_GREEN else
                       if col < 0 then Color.DARK_RED else Color.GRAY);
Line4.AssignValueColor(if col > 0 then Color.DARK_GREEN else
                       if col < 0 then Color.DARK_RED else Color.GRAY);
Line3.AssignValueColor(if col > 0 then Color.DARK_GREEN else
                       if col < 0 then Color.DARK_RED else Color.GRAY);

#-- Cloud

AddCloud(if last then na else
         if col > 0 then limitUp else limitDn,
         if col > 0 then limitDn else limitUp, Color.DARK_GREEN, Color.DARK_RED);

#-- exit
def priceE1;
def cntE1;
def priceE2;
def cntE2;
def priceE3;
def cntE3;
def priceE4;
def cntE4;
def priceE5;
def cntE5;
if bankerExit {
    priceE5 = priceE4[1];
    priceE4 = priceE3[1];
    priceE3 = priceE2[1];
    priceE2 = priceE1[1];
    priceE1 = close;
    cntE5   = cntE4[1];
    cntE4   = cntE3[1];
    cntE3   = cntE2[1];
    cntE2   = cntE1[1];
    cntE1   = bar;
} else {
    priceE5 = priceE5[1];
    priceE4 = priceE4[1];
    priceE3 = priceE3[1];
    priceE2 = priceE2[1];
    priceE1 = priceE1[1];
    cntE5   = cntE5[1];
    cntE4   = cntE4[1];
    cntE3   = cntE3[1];
    cntE2   = cntE2[1];
    cntE1   = cntE1[1];
}
def startE = Min(cntE2, cntE1);
def pE5 = if priceE5 then HighestAll(InertiaAll(priceE5, 2)) else pE5[1];
def pE4 = if priceE4 then HighestAll(InertiaAll(priceE4, 2)) else pE4[1];
def pE3 = if priceE3 then HighestAll(InertiaAll(priceE3, 2)) else pE3[1];
def pE2 = if priceE2 then HighestAll(InertiaAll(priceE2, 2)) else pE2[1];
def pE1 = if priceE1 then HighestAll(InertiaAll(priceE1, 2)) else pE1[1];

def lE5 = if bar >= HighestAll(cntE5) then pE5 else na;
def lE4 = if bar >= HighestAll(cntE4) then pE4 else na;
def lE3 = if bar >= HighestAll(cntE3) then pE3 else na;
def TopE = if bar >= HighestAll(startE) then pE2 else na;
def BotE = if bar >= HighestAll(startE) then pE1 else na;
def limitUpE = if TopE and BotE then Max(TopE, BotE) else na;
def limitDnE = if TopE and BotE then Min(TopE, BotE) else na;

def crossed_Below = if high > limitUpE then -1 else
                    if low  < limitDnE then 1 else crossed_Below[1];
def crossE = if last then crossE[1] else crossed_below;
def colE = HighestAll(InertiaAll(crossE, 2));

plot boxTopE = if !last and TopE then TopE else na;
plot boxBotE = if !last and BotE then BotE else na;
boxTopE.AssignValueColor(if colE > 0 then Color.GREEN else
                         if colE < 0 then Color.RED else Color.GRAY);
boxBotE.AssignValueColor(if colE > 0 then Color.GREEN else
                         if colE < 0 then Color.RED else Color.GRAY);

plot LineE5 = if !last and lE5 then lE5 else na;
plot LineE4 = if !last and lE4 then lE4 else na;
plot LineE3 = if !last and lE3 then lE3 else na;
LineE5.SetStyle(Curve.MEDIUM_DASH);
LineE4.SetStyle(Curve.MEDIUM_DASH);
LineE3.SetStyle(Curve.MEDIUM_DASH);
LineE5.AssignValueColor(if colE > 0 then Color.DARK_GREEN else
                        if colE < 0 then Color.DARK_RED else Color.GRAY);
LineE4.AssignValueColor(if colE > 0 then Color.DARK_GREEN else
                        if colE < 0 then Color.DARK_RED else Color.GRAY);
LineE3.AssignValueColor(if colE > 0 then Color.DARK_GREEN else
                        if colE < 0 then Color.DARK_RED else Color.GRAY);

#-- Cloud

AddCloud(if last then na else
         if colE > 0 then limitUpE else limitDnE,
         if colE > 0 then limitDnE else limitUpE, Color.DARK_GREEN, Color.DARK_RED);

#---- END CODE

CODE - Lower Study - Added divergences and plot style - 06/2024

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © blackcat1402
#study("[blackcat] L3 Banker Fund Flow Trend Oscillator", overlay=false)
# Converted and mod by Sam4Cok@Samer800 - 02/2023
# Update - added option for MTF - 02/2024
# updated - Added plot option and Divergences - 06/2024

declare lower;
#//functions
input BarColor = no;
input plotStyle = {Default "Candles", "Lines"};
input showSignalLine = yes;
input timeframe = {default "Chart", "Custom"};
input customTimeframe = AggregationPeriod.FIFTEEN_MIN;
input SourceType = {"High/Low",default "Open/Close"};
input smoothingType = AverageType.EXPONENTIAL;
input SmoothingLength = 13;
input upperThreshold = 75;
input lowerThreshold = 25;

def na = Double.NaN;
def last = IsNaN(close);
def can = plotStyle==plotStyle."Candles";
def tf = customTimeframe;
def c;
def h;
def l;
def o;
def typ;
switch (timeframe) {
case "Custom" :
    c = close(Period = tf);
    h = high(Period = tf);
    l = low(Period = tf);
    o = open(Period = tf);
    typ = (2 * close(Period = tf) + high(Period = tf) + low(Period = tf) + open(Period = tf)) / 5;
default :
    c = close;
    h = high;
    l = low;
    o = open;
    typ = (2 * close + high + low + open) / 5;
}
#//define typical price for banker fund
def hilo = SourceType == SourceType."High/Low";
def srcHi = if hilo then h else Max(o, c);
def srcLo = if hilo then l else Min(o, c);
#xrf(values, length) =>
script xrf {
    input values = close;
    input length = 34;
    def r_val = fold i = 0 to length + 1 with p=Double.NaN do
            if (IsNaN(p) or !IsNaN(values[i])) then values[i] else p;
    plot out = if length >= 1 then r_val else Double.NaN;
}
#xsa(src,len,wei) =>
script xsa {
    input src = close;
    input len = 5;
    input wei = 1;
    def sumf = CompoundValue(1, sumf[1] - src[len] + src , src);
    def ma   = if IsNaN(src[len]) then Double.NaN else sumf / len;
    def out  = CompoundValue(1, (src * wei + out[1] * (len - wei)) / len, ma);
    plot return = out;
}

def hh = Highest(h, 27);
def ll = Lowest(l, 27);
def wmCal = (c - ll) / (hh - ll) * 100;
def xsaWM5 = xsa(wmCal, 5, 1);
def xsaWM3 = xsa(xsaWM5, 3, 1);
#//set up a simple model of banker fund flow trend
def fundtrend = (3 * xsaWM5 - 2 * xsaWM3 - 50) * 1.032 + 50;

#//lowest low with mid term fib # 34
def lol = Lowest(srcLo, 34);
#//highest high with mid term fib # 34
def hoh = Highest(srcHi, 34);
#//define banker fund flow bull bear line
def bullbear = (typ - lol) / (hoh - lol) * 100;
def bullbearline = MovingAverage(smoothingType, bullbear, SmoothingLength);
#//define banker entry signal
def bankerentry = (fundtrend Crosses Above bullbearline) and bullbearline < lowerThreshold;
def bankerExit  = (fundtrend Crosses Below bullbearline) and bullbearline > upperThreshold;

#//banker increase position with green candle
def xrf1 = xrf(fundtrend * 0.95, 1);
def UpCandle = if last or !can then na else fundtrend > bullbearline;
def WeakUp   = if last or !can then na else fundtrend < xrf1;
def DnCandle = if last or !can then na else fundtrend < bullbearline;
def WeakDn   = if last or !can then na else fundtrend < bullbearline and fundtrend > xrf1;

#-- clouds
def weak = !can and fundtrend < xrf1;
AddCloud(if weak or weak[1] then fundtrend else na, bullbearline, Color.DARK_GREEN, Color.RED, yes);
AddCloud(if can then na else fundtrend, bullbearline, Color.GREEN, Color.DARK_RED, yes);

# Plot the new Chart
#//banker fund entry with yellow candle
def condUp = bankerentry and !bankerentry[1];
def condDn = bankerExit and !bankerExit[1];
plot SigUp = if !showSignalLine then na else if condUp then 15 else 0;
plot SigDn = if !showSignalLine then na else if condDn then 85 else 100;

SigUp.AssignValueColor(if condUp or condUp[1] then Color.YELLOW else CreateColor(98, 98, 0));
SigDn.AssignValueColor(if condDn or condDn[1] then Color.MAGENTA else CreateColor(98, 0, 98));

AddChart(high = if UpCandle then bullbearline else na , low = fundtrend , open = fundtrend,  close =  bullbearline,
         type = ChartType.CANDLE, growcolor = CreateColor(7, 205, 15));

AddChart(high = if WeakUp then bullbearline else na , low = fundtrend , open = fundtrend,  close = bullbearline,
         type = ChartType.CANDLE, growcolor =  Color.LIGHT_GREEN); #CreateColor(188, 245, 188));

AddChart(high = if DnCandle then bullbearline else na , low = fundtrend , open = bullbearline,  close =   fundtrend,
         type = ChartType.CANDLE, growcolor =  Color.RED);

AddChart(high = if WeakDn then bullbearline else na , low = fundtrend , open = bullbearline,  close =   fundtrend,
         type = ChartType.CANDLE, growcolor =  Color.PINK);

#/overbought and oversold threshold lines
def h1 = if last then na else 80;
def h2 = if last then na else 20;
def h3 = 10;
def h4 = 90;

plot h5 = if last then na else 50;
h5.SetDefaultColor(Color.DARK_GRAY);

AddCloud(h2, h3, CreateColor(117, 117, 0));
AddCloud(h4, h1, Color.PLUM);

#-- bar Color
def col = if isNaN(fundtrend) then col[1] else
         if fundtrend > 100 then 255 else if fundtrend<0 then 0 else fundtrend * 2.55;

AssignPriceColor(if !BarColor then Color.CURRENT else
                 if bankerentry then Color.CYAN else
                 if bankerExit then Color.MAGENTA else CreateColor(255 - col, col, 0));

#----Div-----------
input ShowLastDivLines = yes;
input DivBull = yes;      # "Plot Bullish"
input DivBear = yes;      # "Plot Bearish"
input PivotLookbackRight = 5;  # "Pivot Lookback Right"
input PivotLookbackLeft  = 10; # "Pivot Lookback Left"
input MaxLookback = 60;   # "Max of Lookback Range"
input MinLookback = 5;    # "Min of Lookback Range"

def divSrc = fundtrend;
def maxx = Max(fundtrend, bullbearline);
def minn = Min(fundtrend, bullbearline);

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 + 1 and dat == Highest(dat, lbL + 1) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > lbL + 1 and dat == Lowest(dat, lbL + 1) and _VStop
            then dat else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
#_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, PivotLookbackLeft, PivotLookbackRight);
def ph_ = findpivots(divSrc, 1, PivotLookbackLeft, PivotLookbackRight);
def pl = !isNaN(pl_);
def ph = !isNaN(ph_);
def pll = lowest(divSrc,PivotLookbackLeft +1);
def phh = highest(divSrc,PivotLookbackLeft+1);
def sll = lowest(l, PivotLookbackLeft +1);
def shh = highest(h, PivotLookbackLeft+1);
#-- Pvt Low
def plStart  = if pl then yes else plStart[1];
def plFound  = if (plStart and pl) then 1 else 0;
def vlFound1 = if plFound then divSrc else vlFound1[1];
def vlFound_ = if vlFound1!=vlFound1[1] then vlFound1[1] else vlFound_[1];
def vlFound  = if !vlFound_ then pll else vlFound_;
def plPrice1 = if plFound then l else plPrice1[1];
def plPrice_ = if plPrice1!=plPrice1[1] then plPrice1[1] else plPrice_[1];
def plPrice  = if !plPrice_ then sll else plPrice_;
#-- Pvt High
def phStart = if ph then yes else phStart[1];
def phFound = if (phStart and ph) then 1 else 0;
def vhFound1 = if phFound then divSrc else vhFound1[1];
def vhFound_ = if vhFound1!=vhFound1[1] then vhFound1[1] else vhFound_[1];
def vhFound = if !vhFound_ then phh else vhFound_;
def phPrice1 = if phFound then h else phPrice1[1];
def phPrice_ = if phPrice1!=phPrice1[1] then phPrice1[1] else phPrice_[1];
def phPrice = if !phPrice_ then shh else phPrice_;
#// Regular Bullish
def inRangePl = _inRange(plFound[1],MaxLookback,MinLookback);
def oscHL = divSrc > vlFound and inRangePl;
def priceLL = l < plPrice and divSrc <= 40;
def bullCond = plFound and oscHL and priceLL;

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

#------ Bubbles
def bullBub  = DivBull and bullCond;
def bearBub  = DivBear and bearCond;

addchartbubble(bullBub, minn, "R", Color.CYAN, no);
addchartbubble(bearBub, maxx, "R", CreateColor(176,39,176), yes);

##### Lines
def bar = BarNumber();
#-- Bear Line
def lastPhBar = if ph then bar else lastPhBar[1];
def prePhBar = if lastPhBar!=lastPhBar[1] then lastPhBar[1] else prePhBar[1];
def priorPHBar = if bearCond then prePhBar else priorPHBar[1];
#-- Bull Line
def lastPlBar = if pl then bar else lastPlBar[1];
def prePlBar = if lastPlBar!=lastPlBar[1] then lastPlBar[1] else prePlBar[1];
def priorPLBar = if bullCond then prePlBar else priorPLBar[1];

def lastBullBar = if bullCond then bar else lastBullBar[1];
def lastBearBar = if bearCond then bar else lastBearBar[1];

def hiStart = bar == HighestAll(priorPHBar);
def hiEnd   = bar == HighestAll(lastBearBar);
def loStart = bar == HighestAll(priorPLBar);
def loEnd   = bar == HighestAll(lastBullBar);

def pivotHigh = if hiStart then maxx else if hiEnd then maxx else na;#if HighPivots then bullbearline else na;
def pivotLow  = if loStart then minn else if loEnd then minn else na;

plot PlotHline = if ShowLastDivLines then pivotHigh else na;
PlotHline.EnableApproximation();
PlotHline.SetDefaultColor(Color.WHITE);
PlotHline.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

plot PlotLline = if ShowLastDivLines then pivotLow else na;
PlotLline.EnableApproximation();
PlotLline.SetDefaultColor(Color.CYAN);
PlotLline.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);


#---- END CODE
CODE :

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © blackcat1402
#study("[blackcat] L3 Banker Fund Flow Trend Oscillator", overlay=false)
# Converted and mod by Sam4Cok@Samer800 - 02/2023
declare lower;
#//functions
input BarColor = yes;
input SmoothingLength = 13;
def na = Double.NaN;
def last = isNaN(close[1]);
#xrf(values, length) =>
script xrf {
    input values = close;
    input length = 34;
    def r_val;# = float(na)
    r_val = if length >= 1 then
                fold i = 0 to length +1 with p=values do
             if IsNaN(p) or !IsNaN(values[i]) then values[i] else p else Double.NaN;
    plot out = r_val;
}
#xsa(src,len,wei) =>
script xsa {
    input src = close;
    input len = 5;
    input wei = 1;
    def sumf;# = 0.0
    def ma;# = 0.0
    def out;# = 0.0
    sumf = CompoundValue(1, sumf[1] - src[len] + src , src);
    ma   = if IsNaN(src[len]) then Double.NaN else sumf / len;
    out  = if IsNaN(out[1]) then ma else (src * wei + out[1] * (len - wei)) / len;
    plot return = out;
}
def wmCal = (close - Lowest(low, 27)) / (Highest(high, 27) - Lowest(low, 27)) * 100;

#//set up a simple model of banker fund flow trend
def fundtrend = (3 * xsa(wmCal, 5, 1) - 2 * xsa(xsa(wmCal, 5, 1), 3, 1) - 50) * 1.032 + 50;
#//define typical price for banker fund
def typ = (2 * close + high + low + open) / 5;
#//lowest low with mid term fib # 34
def lol = Lowest(low, 34);
#//highest high with mid term fib # 34
def hoh = Highest(high, 34);
#//define banker fund flow bull bear line
def bullbear = (typ - lol) / (hoh - lol) * 100;
def bullbearline = ExpAverage(bullbear, SmoothingLength);
#//define banker entry signal
def bankerentry = Crosses(fundtrend, bullbearline, CrossingDirection.ABOVE) and bullbearline < 25;

#//banker increase position with green candle
def UpCandle = fundtrend > bullbearline;
def WeakUp   = fundtrend < (xrf(fundtrend * 0.95, 1));
def DnCandle = fundtrend < bullbearline;
def WeakDn   = fundtrend < bullbearline and fundtrend > (xrf(fundtrend * 0.95, 1));

# Plot the new Chart
#//banker fund entry with yellow candle
AddChart(high = if bankerentry then 100 else na, low = 0 , open = 100,  close = 0,
         type = ChartType.CANDLE, growcolor =  CreateColor(26, 70, 85));

AddChart(high = if UpCandle then bullbearline else na , low = fundtrend , open = fundtrend,  close =  bullbearline,
         type = ChartType.CANDLE, growcolor =  CreateColor(7,205,15));

AddChart(high = if WeakUp then bullbearline else na , low = fundtrend , open = fundtrend,  close = bullbearline,
         type = ChartType.CANDLE, growcolor =  CreateColor(188,245,188));

AddChart(high = if DnCandle then bullbearline else na , low = fundtrend , open = bullbearline,  close =   fundtrend,
         type = ChartType.CANDLE, growcolor =  Color.RED);

AddChart(high = if WeakDn then bullbearline else na , low = fundtrend , open = bullbearline,  close =   fundtrend,
         type = ChartType.CANDLE, growcolor =  Color.PINK);

#/overbought and oversold threshold lines
def h1 = if last then na else 80;
def h2 = if last then na else 20;
def h3 = 10;
def h4 = 90;
plot h5 = if last then na else 50;
h5.SetDefaultColor(Color.DARK_GRAY);

AddCloud(h2, h3, CreateColor(157,157,0));#color=color.yellow,transp=70)
AddCloud(h4, h1, CreateColor(157,0 ,157));#=color.fuchsia,transp=70)

AssignPriceColor(if !BarColor then Color.CURRENT else
                 if bankerentry then Color.CYAN else
                 if WeakDn then Color.DARK_RED else
                 if DnCandle then Color.RED else
                 if WeakUp then Color.DARK_GREEN else
                 if UpCandle then Color.GREEN else Color.CURRENT);



#---- END CODE
@samer800, thank you for great work. is the final version of CODE - Upper Study - 08/2024, have an option for SHORT Trades?
 
try this

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © blackcat1402
#study("[blackcat] L3 Banker Fund Flow Trend Oscillator", overlay=false)
# Converted and mod by Sam4Cok@Samer800 - 02/2023
# Scan
#input BarColor = yes;
#input SmoothingLength = 13;
def na = Double.NaN;
def last = isNaN(close[1]);
#xrf(values, length) =>
script xrf {
    input values = close;
    input length = 34;
    def r_val;# = float(na)
    r_val = if length >= 1 then
                fold i = 0 to length +1 with p=values do
             if IsNaN(p) or !IsNaN(values[i]) then values[i] else p else Double.NaN;
    plot out = r_val;
}
#xsa(src,len,wei) =>
script xsa {
    input src = close;
    input len = 5;
    input wei = 1;
    def sumf;# = 0.0
    def ma;# = 0.0
    def out;# = 0.0
    sumf = CompoundValue(1, sumf[1] - src[len] + src , src);
    ma   = if IsNaN(src[len]) then Double.NaN else sumf / len;
    out  = if IsNaN(out[1]) then ma else (src * wei + out[1] * (len - wei)) / len;
    plot return = out;
}
def wmCal = (close - Lowest(low, 27)) / (Highest(high, 27) - Lowest(low, 27)) * 100;

#//set up a simple model of banker fund flow trend  
def fundtrend = (3 * xsa(wmCal, 5, 1) - 2 * xsa(xsa(wmCal, 5, 1), 3, 1) - 50) * 1.032 + 50;
#//define typical price for banker fund
def typ = (2 * close + high + low + open) / 5;
#//lowest low with mid term fib # 34
def lol = Lowest(low, 34);
#//highest high with mid term fib # 34
def hoh = Highest(high, 34);
#//define banker fund flow bull bear line
def bullbear = (typ - lol) / (hoh - lol) * 100;
def bullbearline = ExpAverage(bullbear, 13);
#//define banker entry signal
def bankerentry = Crosses(fundtrend, bullbearline, CrossingDirection.ABOVE) and bullbearline < 25;

# Plot the new Chart
#//banker fund entry with yellow candle

plot scan = bankerentry within 3 bars;


#---- END CODE
1729960738962.png


hi @samer800 , is it possible to scan for stocks that a bull divergence setup as shown in the pic circled in Red?

Thanks
 
try this

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © blackcat1402
#study("[blackcat] L3 Banker Fund Flow Trend Oscillator", overlay=false)
# Converted and mod by Sam4Cok@Samer800 - 02/2023
# Scan
#input BarColor = yes;
#input SmoothingLength = 13;
def na = Double.NaN;
def last = isNaN(close[1]);
#xrf(values, length) =>
script xrf {
    input values = close;
    input length = 34;
    def r_val;# = float(na)
    r_val = if length >= 1 then
                fold i = 0 to length +1 with p=values do
             if IsNaN(p) or !IsNaN(values[i]) then values[i] else p else Double.NaN;
    plot out = r_val;
}
#xsa(src,len,wei) =>
script xsa {
    input src = close;
    input len = 5;
    input wei = 1;
    def sumf;# = 0.0
    def ma;# = 0.0
    def out;# = 0.0
    sumf = CompoundValue(1, sumf[1] - src[len] + src , src);
    ma   = if IsNaN(src[len]) then Double.NaN else sumf / len;
    out  = if IsNaN(out[1]) then ma else (src * wei + out[1] * (len - wei)) / len;
    plot return = out;
}
def wmCal = (close - Lowest(low, 27)) / (Highest(high, 27) - Lowest(low, 27)) * 100;

#//set up a simple model of banker fund flow trend  
def fundtrend = (3 * xsa(wmCal, 5, 1) - 2 * xsa(xsa(wmCal, 5, 1), 3, 1) - 50) * 1.032 + 50;
#//define typical price for banker fund
def typ = (2 * close + high + low + open) / 5;
#//lowest low with mid term fib # 34
def lol = Lowest(low, 34);
#//highest high with mid term fib # 34
def hoh = Highest(high, 34);
#//define banker fund flow bull bear line
def bullbear = (typ - lol) / (hoh - lol) * 100;
def bullbearline = ExpAverage(bullbear, 13);
#//define banker entry signal
def bankerentry = Crosses(fundtrend, bullbearline, CrossingDirection.ABOVE) and bullbearline < 25;

# Plot the new Chart
#//banker fund entry with yellow candle

plot scan = bankerentry within 3 bars;


#---- END CODE
Hi samer800, very nice for this scan script, but I cannot found any stock after scan. Anything wrong with my scan setup ?
 
check the below:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © blackcat1402
#study("[blackcat] L3 Banker Fund Flow Trend Oscillator", overlay=false)
# Converted and mod by Sam4Cok@Samer800 - 02/2023
# Update - added option for MTF - 02/2024
# updated - Added plot option and Divergences - 06/2024

declare lower;
#//functions
input BarColor = no;
input plotStyle = {Default "Candles", "Lines"};
input showSignalLine = yes;
input timeframe = {default "Chart", "Custom"};
input customTimeframe = AggregationPeriod.FIFTEEN_MIN;
input SourceType = {"High/Low",default "Open/Close"};
input smoothingType = AverageType.EXPONENTIAL;
input SmoothingLength = 13;
input upperThreshold = 75;
input lowerThreshold = 25;

def na = Double.NaN;
def last = IsNaN(close);
def can = plotStyle==plotStyle."Candles";
def tf = customTimeframe;
def c;
def h;
def l;
def o;
def typ;
switch (timeframe) {
case "Custom" :
    c = close(Period = tf);
    h = high(Period = tf);
    l = low(Period = tf);
    o = open(Period = tf);
    typ = (2 * close(Period = tf) + high(Period = tf) + low(Period = tf) + open(Period = tf)) / 5;
default :
    c = close;
    h = high;
    l = low;
    o = open;
    typ = (2 * close + high + low + open) / 5;
}
#//define typical price for banker fund
def hilo = SourceType == SourceType."High/Low";
def srcHi = if hilo then h else Max(o, c);
def srcLo = if hilo then l else Min(o, c);
#xrf(values, length) =>
script xrf {
    input values = close;
    input length = 34;
    def r_val = fold i = 0 to length + 1 with p=Double.NaN do
            if (IsNaN(p) or !IsNaN(values[i])) then values[i] else p;
    plot out = if length >= 1 then r_val else Double.NaN;
}
#xsa(src,len,wei) =>
script xsa {
    input src = close;
    input len = 5;
    input wei = 1;
    def sumf = CompoundValue(1, sumf[1] - src[len] + src , src);
    def ma   = if IsNaN(src[len]) then Double.NaN else sumf / len;
    def out  = CompoundValue(1, (src * wei + out[1] * (len - wei)) / len, ma);
    plot return = out;
}

def hh = Highest(h, 27);
def ll = Lowest(l, 27);
def wmCal = (c - ll) / (hh - ll) * 100;
def xsaWM5 = xsa(wmCal, 5, 1);
def xsaWM3 = xsa(xsaWM5, 3, 1);
#//set up a simple model of banker fund flow trend  
def fundtrend = (3 * xsaWM5 - 2 * xsaWM3 - 50) * 1.032 + 50;

#//lowest low with mid term fib # 34
def lol = Lowest(srcLo, 34);
#//highest high with mid term fib # 34
def hoh = Highest(srcHi, 34);
#//define banker fund flow bull bear line
def bullbear = (typ - lol) / (hoh - lol) * 100;
def bullbearline = MovingAverage(smoothingType, bullbear, SmoothingLength);
#//define banker entry signal
def bankerentry = (fundtrend Crosses Above bullbearline) and bullbearline < lowerThreshold;
def bankerExit  = (fundtrend Crosses Below bullbearline) and bullbearline > upperThreshold;

#//banker increase position with green candle
def xrf1 = xrf(fundtrend * 0.95, 1);
def UpCandle = if last or !can then na else fundtrend > bullbearline;
def WeakUp   = if last or !can then na else fundtrend < xrf1;
def DnCandle = if last or !can then na else fundtrend < bullbearline;
def WeakDn   = if last or !can then na else fundtrend < bullbearline and fundtrend > xrf1;

#-- clouds
def weak = !can and fundtrend < xrf1;
AddCloud(if weak or weak[1] then fundtrend else na, bullbearline, Color.DARK_GREEN, Color.RED, yes);
AddCloud(if can then na else fundtrend, bullbearline, Color.GREEN, Color.DARK_RED, yes);

# Plot the new Chart
#//banker fund entry with yellow candle
def condUp = bankerentry and !bankerentry[1];
def condDn = bankerExit and !bankerExit[1];
plot SigUp = if !showSignalLine then na else if condUp then 15 else 0;
plot SigDn = if !showSignalLine then na else if condDn then 85 else 100;

SigUp.AssignValueColor(if condUp or condUp[1] then Color.YELLOW else CreateColor(98, 98, 0));
SigDn.AssignValueColor(if condDn or condDn[1] then Color.MAGENTA else CreateColor(98, 0, 98));

AddChart(high = if UpCandle then bullbearline else na , low = fundtrend , open = fundtrend,  close =  bullbearline,
         type = ChartType.CANDLE, growcolor = CreateColor(7, 205, 15));

AddChart(high = if WeakUp then bullbearline else na , low = fundtrend , open = fundtrend,  close = bullbearline,
         type = ChartType.CANDLE, growcolor =  Color.LIGHT_GREEN); #CreateColor(188, 245, 188));

AddChart(high = if DnCandle then bullbearline else na , low = fundtrend , open = bullbearline,  close =   fundtrend,
         type = ChartType.CANDLE, growcolor =  Color.RED);

AddChart(high = if WeakDn then bullbearline else na , low = fundtrend , open = bullbearline,  close =   fundtrend,
         type = ChartType.CANDLE, growcolor =  Color.PINK);

#/overbought and oversold threshold lines
def h1 = if last then na else 80;
def h2 = if last then na else 20;
def h3 = 10;
def h4 = 90;

plot h5 = if last then na else 50;
h5.SetDefaultColor(Color.DARK_GRAY);

AddCloud(h2, h3, CreateColor(117, 117, 0));
AddCloud(h4, h1, Color.PLUM);

#-- bar Color
def col = if isNaN(fundtrend) then col[1] else
         if fundtrend > 100 then 255 else if fundtrend<0 then 0 else fundtrend * 2.55;

AssignPriceColor(if !BarColor then Color.CURRENT else
                 if bankerentry then Color.CYAN else
                 if bankerExit then Color.MAGENTA else CreateColor(255 - col, col, 0));

#----Div-----------
input ShowLastDivLines = yes;
input DivBull = yes;      # "Plot Bullish"
input DivBear = yes;      # "Plot Bearish"
input PivotLookbackRight = 5;  # "Pivot Lookback Right"
input PivotLookbackLeft  = 10; # "Pivot Lookback Left"
input MaxLookback = 60;   # "Max of Lookback Range"
input MinLookback = 5;    # "Min of Lookback Range"

def divSrc = fundtrend;
def maxx = Max(fundtrend, bullbearline);
def minn = Min(fundtrend, bullbearline);

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 + 1 and dat == Highest(dat, lbL + 1) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > lbL + 1 and dat == Lowest(dat, lbL + 1) and _VStop
            then dat else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
#_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, PivotLookbackLeft, PivotLookbackRight);
def ph_ = findpivots(divSrc, 1, PivotLookbackLeft, PivotLookbackRight);
def pl = !isNaN(pl_);
def ph = !isNaN(ph_);
def pll = lowest(divSrc,PivotLookbackLeft +1);
def phh = highest(divSrc,PivotLookbackLeft+1);
def sll = lowest(l, PivotLookbackLeft +1);
def shh = highest(h, PivotLookbackLeft+1);
#-- Pvt Low
def plStart  = if pl then yes else plStart[1];
def plFound  = if (plStart and pl) then 1 else 0;
def vlFound1 = if plFound then divSrc else vlFound1[1];
def vlFound_ = if vlFound1!=vlFound1[1] then vlFound1[1] else vlFound_[1];
def vlFound  = if !vlFound_ then pll else vlFound_;
def plPrice1 = if plFound then l else plPrice1[1];
def plPrice_ = if plPrice1!=plPrice1[1] then plPrice1[1] else plPrice_[1];
def plPrice  = if !plPrice_ then sll else plPrice_;
#-- Pvt High
def phStart = if ph then yes else phStart[1];
def phFound = if (phStart and ph) then 1 else 0;
def vhFound1 = if phFound then divSrc else vhFound1[1];
def vhFound_ = if vhFound1!=vhFound1[1] then vhFound1[1] else vhFound_[1];
def vhFound = if !vhFound_ then phh else vhFound_;
def phPrice1 = if phFound then h else phPrice1[1];
def phPrice_ = if phPrice1!=phPrice1[1] then phPrice1[1] else phPrice_[1];
def phPrice = if !phPrice_ then shh else phPrice_;
#// Regular Bullish
def inRangePl = _inRange(plFound[1],MaxLookback,MinLookback);
def oscHL = divSrc > vlFound and inRangePl;
def priceLL = l < plPrice and divSrc <= 40;
def bullCond = plFound and oscHL and priceLL;

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

#------ Bubbles
def bullBub  = DivBull and bullCond;
def bearBub  = DivBear and bearCond;

addchartbubble(bullBub, minn, "R", Color.CYAN, no);
addchartbubble(bearBub, maxx, "R", CreateColor(176,39,176), yes);

##### Lines
def bar = BarNumber();
#-- Bear Line
def lastPhBar = if ph then bar else lastPhBar[1];
def prePhBar = if lastPhBar!=lastPhBar[1] then lastPhBar[1] else prePhBar[1];
def priorPHBar = if bearCond then prePhBar else priorPHBar[1];
#-- Bull Line
def lastPlBar = if pl then bar else lastPlBar[1];
def prePlBar = if lastPlBar!=lastPlBar[1] then lastPlBar[1] else prePlBar[1];
def priorPLBar = if bullCond then prePlBar else priorPLBar[1];

def lastBullBar = if bullCond then bar else lastBullBar[1];
def lastBearBar = if bearCond then bar else lastBearBar[1];

def hiStart = bar == HighestAll(priorPHBar);
def hiEnd   = bar == HighestAll(lastBearBar);
def loStart = bar == HighestAll(priorPLBar);
def loEnd   = bar == HighestAll(lastBullBar);

def pivotHigh = if hiStart then maxx else if hiEnd then maxx else na;#if HighPivots then bullbearline else na;
def pivotLow  = if loStart then minn else if loEnd then minn else na;

plot PlotHline = if ShowLastDivLines then pivotHigh else na;
PlotHline.EnableApproximation();
PlotHline.SetDefaultColor(Color.WHITE);
PlotHline.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);

plot PlotLline = if ShowLastDivLines then pivotLow else na;
PlotLline.EnableApproximation();
PlotLline.SetDefaultColor(Color.CYAN);
PlotLline.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);


#---- END CODE
1731142700620.png

@samer800 able to add the vertical violet lines for the Exit signal? tks
 
Hi samer800, very nice for this scan script, but I cannot found any stock after scan. Anything wrong with my scan setup ?
I got it, the scan script is working. very nice. Salute for Samer800.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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