Liquidity Hunter [ChartPrime] for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
Liquidity Hunter S_CHARTS.png

Author Message:
The Liquidity Hunter helps traders identify areas in the market where reversals may occur by analyzing candle formations and structures.
For more Details: https://www.tradingview.com/v/E9z8Isgd/

CODE:

CSS:
#//https://www.tradingview.com/v/E9z8Isgd/
#// This source code is subject to the terms of the Mozilla Public License 2.0
#// © ChartPrime
#indicator("Liquidity Hunter [ChartPrime]",shorttitle = "Liquidity Hunter [ChartPrime]"
# Converted and mod by Sam4Cok@Samer800    - 12/2023

input showInfoLabel = yes;
input colorLiquidityBars = yes;
input useFilter = no;
input filterLength = 14;
input showMarketCharacter = {Default "Lines & Labels", "Lines Only", "Labels Only", "Don't Show"};
input bodyPercentage = 30;    # "Body %" tooltip = "Body Value will be lower than this "
input WickPercentage = 60;    # "Wick %" tooltip = "Wick Value will be higher than this "
input ShowTargets = yes;      # "Show Targets"
input lostSize = 100;
input targetMulti   = 1.5;    # "Profit Target "
input stopLossMulti = 1.5;    # "SL Target "


def na = Double.NaN;
def bar = CompoundValue(1, AbsValue(BarNumber()), 1);
def last = !IsNaN(close);
def bar_index = if last then bar else bar_index[1];
def SMCLine;
def SMCLabel;
Switch (showMarketCharacter) {
Case "Lines Only" :
    SMCLine  = yes;
    SMCLabel = no;
Case "Labels Only" :
    SMCLine  = no;
    SMCLabel = yes;
Case "Don't Show" :
    SMCLine  = no;
    SMCLabel = no;
Default :
    SMCLine  = yes;
    SMCLabel = yes;
}
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
    def _pivotRange;
    ##############
    _BN  = BarNumber();
    _nan = Double.NaN;
    _pivotRange = lbL + lbL;
    _VStop = if !isNaN(dat[_pivotRange]) 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;
}
Script get_counts {
input condition = no;
input top = high;
input btm = low;
    def count;# = 0
    if condition {
        count = 0;
    } else {
        count = count[1] + (if low < top and high > btm then 1 else 0);
    }
    plot cnt = count;
}
Script _Band {
    input len = 5;
    def nATR = ATR(LENGTH = len);
    def Band = Min(nATR * 0.3, close * (0.3 / 100));
    plot _Band = Band[20] / 2;
}
def _Band = _Band(5);
def Zband = _Band(30);
def range = AbsValue(high[1] - low[1]);
def LowerWickRange = Min(open[1], close[1]) - low[1];
def BodyPer = AbsValue(open[1] - close[1]) / range * 100;
def WickPer = (LowerWickRange / range) * 100;

def t = bar_index;
def TIME = if t[5] > 0 then t[5] else 1;
def LTIME = if TIME[1] then TIME[1] else 1;
def Slope = (close[1] - close[2]) / (TIME - LTIME);
def CON = BodyPer <= bodyPercentage and WickPer >= WickPercentage and (Slope * t > 0) and _Band >= _Band[1];

def ph_top;
def ph_btm;
def phtop = if ph_top[1] then ph_top[1] else high + _Band;
def phbtm = if ph_btm[1] then ph_btm[1] else low  - _Band;
def pvtH =  findpivots(high, 1, filterLength, RoundUp(filterLength/2, 0));
def ph_count = get_counts(!isNaN(pvtH), phtop, phbtm);
    ph_top = if !isNaN(pvtH) then high + _Band else phtop;
    ph_btm = if !isNaN(pvtH) then low  - _Band else phbtm;

def filter = if useFilter then ph_count > 1 else yes;
def long = filter and CON;
def nATR = ATR(Length = 14);
def x2 = low - nATR * stopLossMulti;
def longDiffSL = AbsValue(close - x2);

def TradeisON;
def LongIndex;
def TP;
def CHOCH;
def SL;
def BOS;
def Message;
def top;
def bot;
def ChochisON;
def BOSisON;
def ChoIndex;
def ChoIndex1;
def CHOCHLab;
def Bosindex;
def Bosindex1;
def bosLab;
def entry;
if long and !TradeisON[1] {
    entry = ohlc4[-1];
    LongIndex = bar_index;
    TP = entry + (targetMulti * longDiffSL);
    SL = entry - longDiffSL;
    CHOCH = close + (targetMulti / 2 * longDiffSL);
    BOS = low  - (Zband * 15);
    top = high + (Zband * 0.5);
    bot = low - (Zband * 0.5);
    Message = Round(WickPer, 2);
    ChoIndex = 0;#ChoIndex[1];
    ChoIndex1 = 0;
    Bosindex = 0;
    Bosindex1 = 0;
    CHOCHLab = na;
    bosLab = na;
    TradeisON = yes;
    ChochisON = no;
    BOSisON = no;
} else
if TradeisON[1] {
    entry = entry[1];
    LongIndex = LongIndex[1];
    TP = TP[1];
    SL = SL[1];
    CHOCH = CHOCH[1];
    BOS = BOS[1];
    Message = no;
    top = top[1];
    bot = bot[1];
    if close >= CHOCH and !ChochisON[1] {
        ChoIndex = bar_index;
        ChoIndex1 = LongIndex;
        CHOCHLab = Floor((ChoIndex1 + ChoIndex) / 2);
        ChochisON = yes;
    } else {
        ChoIndex = 0;
        ChoIndex1 = 0;
        CHOCHLab = na;
        ChochisON = ChochisON[1];
    }
    if close <= BOS and !BOSisON[1] {
        Bosindex = bar_index;
        Bosindex1 = LongIndex;
        bosLab = Floor((Bosindex1 + Bosindex) / 2);
        BOSisON = yes;
    } else {
        Bosindex = 0;
        Bosindex1 = 0;
        bosLab = na;
        BOSisON = BOSisON[1];
    }
    TradeisON = if high >= TP then no else
                if close <= SL then no else TradeisON[1];
} else {
    entry = entry[1];
    LongIndex = LongIndex[1];
    TP = TP[1];
    SL = SL[1];
    CHOCH = CHOCH[1];
    BOS = BOS[1];
    Message = no;
    top = top[1];
    bot = bot[1];
    ChoIndex  = 0;#ChoIndex[1];
    ChoIndex1 = 0;#ChoIndex1[1];
    Bosindex  = 0;#Bosindex[1];
    Bosindex1 = 0;#Bosindex1[1];
    CHOCHLab  = na;
    bosLab    = na;
    TradeisON = if high >= TP then no else
                if close <= SL then no else TradeisON[1];
    ChochisON = if TradeisON then ChochisON[1] else no;
    BOSisON   = if TradeisON then BOSisON[1] else no;
}
def plotCond = (TradeisON or TradeisON[2]);
def choChCond = TradeisON and bar_index >= HighestAll(ChoIndex1) - 1 and bar_index <= HighestAll(ChoIndex);
def bosCond   = TradeisON and bar_index >= HighestAll(Bosindex1) - 1 and bar_index <= HighestAll(Bosindex);
def choChLabCond = bar_index == HighestAll(CHOCHLab);
def bosLabCond   = bar_index == HighestAll(bosLab);
def topLine =  if TradeisON and top then top else na;
def botLine =  if TradeisON and bot then bot else na;

plot TpLine = if ShowTargets and plotCond and TP then TP else na;
plot SlLine = if ShowTargets and plotCond and SL then SL else na;
plot chLine = if SMCLine and choChCond then CHOCH else na;
plot boLine = if SMCLine and bosCond then BOS else na;

chLine.SetStyle(Curve.SHORT_DASH);
chLine.SetDefaultColor(CreateColor(4,123,136));
boLine.SetStyle(Curve.SHORT_DASH);
boLine.SetDefaultColor(Color.DARK_RED);
TpLine.SetDefaultColor(CreateColor(78, 255, 43));
SlLine.SetDefaultColor(Color.MAGENTA);
TpLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
SlLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot wickPerc = if Message then Message else na;
wickPerc.SetDefaultColor(Color.YELLOW);
wickPerc.SetLineWeight(3);
wickPerc.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

def endTrade = !TradeisON and TradeisON[1];
def win = high >= TP;
def los = close <= SL;

plot TradeEnd = if !ShowTargets then na else
                if endTrade[2] then
                if los[2] then SL[2] else TP[2] else na;
TradeEnd.SetLineWeight(2);
TradeEnd.AssignValueColor(if win[2] then Color.CYAN else Color.MAGENTA);
TradeEnd.SetPaintingStrategy(PaintingStrategy.SQUARES);

#-- Clouds / Bars/ Label
AddCloud(topLine, botLine, Color.DARK_GRAY, Color.DARK_GRAY, yes);

AddChartBubble(SMCLabel and choChLabCond, CHOCH + Zband, "CHoCH", Color.WHITE);
AddChartBubble(SMCLabel and bosLabCond,  BOS - Zband, "BOS", Color.WHITE, no);

AssignPriceColor( if colorLiquidityBars and TradeisON then Color.CYAN else Color.CURRENT);

# -- Info Label

def winCnt = if endTrade then if win then winCnt[1] + 1 else winCnt[1] else winCnt[1];
def losCnt = if endTrade then if los then losCnt[1] + 1 else losCnt[1] else losCnt[1];
def PlAmt = if endTrade then if win then PlAmt[1] + (TP - Entry) * lostSize else
                             if los then PlAmt[1] - (Entry - SL) * lostSize else PlAmt[1] else PlAmt[1];
def totTrade = winCnt + losCnt;
def winRate = winCnt / totTrade;#Round(winCnt / totTrade * 100, 2);
def PL = Round(PlAmt, 2);

AddLabel(showInfoLabel, "Trades("+ totTrade+ ")"  , Color.WHITE);
AddLabel(showInfoLabel, "P/L ($" + PL + ")", if PL > 0 then Color.GREEN else
                                            if PL < 0 then Color.RED else Color.GRAY);
AddLabel(showInfoLabel, "WinRate("+ AsPercent(winRate) + ")", if winRate > 0.50 then Color.GREEN else
                                                   if winRate < 50 then Color.RED else Color.GRAY);

#-- END of CODE
 

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

Hey Sam, I'm going to try this code next week for trading /ES. Can you clarify what chLine and boLine mean?
 
Hey Sam, I'm going to try this code next week for trading /ES. Can you clarify what chLine and boLine mean?
chLine = change of character (ChoCH), change in the nature of the movement of the market from bullish to bearish or vice versa.
boLine = Break if Structure (BOS), It typically occurs when a support or resistance level is breached.
 
View attachment 20444
Author Message:
The Liquidity Hunter helps traders identify areas in the market where reversals may occur by analyzing candle formations and structures.
For more Details: https://www.tradingview.com/v/E9z8Isgd/

CODE:

CSS:
#//https://www.tradingview.com/v/E9z8Isgd/
#// This source code is subject to the terms of the Mozilla Public License 2.0
#// © ChartPrime
#indicator("Liquidity Hunter [ChartPrime]",shorttitle = "Liquidity Hunter [ChartPrime]"
# Converted and mod by Sam4Cok@Samer800    - 12/2023

input showInfoLabel = yes;
input colorLiquidityBars = yes;
input useFilter = no;
input filterLength = 14;
input showMarketCharacter = {Default "Lines & Labels", "Lines Only", "Labels Only", "Don't Show"};
input bodyPercentage = 30;    # "Body %" tooltip = "Body Value will be lower than this "
input WickPercentage = 60;    # "Wick %" tooltip = "Wick Value will be higher than this "
input ShowTargets = yes;      # "Show Targets"
input lostSize = 100;
input targetMulti   = 1.5;    # "Profit Target "
input stopLossMulti = 1.5;    # "SL Target "


def na = Double.NaN;
def bar = CompoundValue(1, AbsValue(BarNumber()), 1);
def last = !IsNaN(close);
def bar_index = if last then bar else bar_index[1];
def SMCLine;
def SMCLabel;
Switch (showMarketCharacter) {
Case "Lines Only" :
    SMCLine  = yes;
    SMCLabel = no;
Case "Labels Only" :
    SMCLine  = no;
    SMCLabel = yes;
Case "Don't Show" :
    SMCLine  = no;
    SMCLabel = no;
Default :
    SMCLine  = yes;
    SMCLabel = yes;
}
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
    def _pivotRange;
    ##############
    _BN  = BarNumber();
    _nan = Double.NaN;
    _pivotRange = lbL + lbL;
    _VStop = if !isNaN(dat[_pivotRange]) 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;
}
Script get_counts {
input condition = no;
input top = high;
input btm = low;
    def count;# = 0
    if condition {
        count = 0;
    } else {
        count = count[1] + (if low < top and high > btm then 1 else 0);
    }
    plot cnt = count;
}
Script _Band {
    input len = 5;
    def nATR = ATR(LENGTH = len);
    def Band = Min(nATR * 0.3, close * (0.3 / 100));
    plot _Band = Band[20] / 2;
}
def _Band = _Band(5);
def Zband = _Band(30);
def range = AbsValue(high[1] - low[1]);
def LowerWickRange = Min(open[1], close[1]) - low[1];
def BodyPer = AbsValue(open[1] - close[1]) / range * 100;
def WickPer = (LowerWickRange / range) * 100;

def t = bar_index;
def TIME = if t[5] > 0 then t[5] else 1;
def LTIME = if TIME[1] then TIME[1] else 1;
def Slope = (close[1] - close[2]) / (TIME - LTIME);
def CON = BodyPer <= bodyPercentage and WickPer >= WickPercentage and (Slope * t > 0) and _Band >= _Band[1];

def ph_top;
def ph_btm;
def phtop = if ph_top[1] then ph_top[1] else high + _Band;
def phbtm = if ph_btm[1] then ph_btm[1] else low  - _Band;
def pvtH =  findpivots(high, 1, filterLength, RoundUp(filterLength/2, 0));
def ph_count = get_counts(!isNaN(pvtH), phtop, phbtm);
    ph_top = if !isNaN(pvtH) then high + _Band else phtop;
    ph_btm = if !isNaN(pvtH) then low  - _Band else phbtm;

def filter = if useFilter then ph_count > 1 else yes;
def long = filter and CON;
def nATR = ATR(Length = 14);
def x2 = low - nATR * stopLossMulti;
def longDiffSL = AbsValue(close - x2);

def TradeisON;
def LongIndex;
def TP;
def CHOCH;
def SL;
def BOS;
def Message;
def top;
def bot;
def ChochisON;
def BOSisON;
def ChoIndex;
def ChoIndex1;
def CHOCHLab;
def Bosindex;
def Bosindex1;
def bosLab;
def entry;
if long and !TradeisON[1] {
    entry = ohlc4[-1];
    LongIndex = bar_index;
    TP = entry + (targetMulti * longDiffSL);
    SL = entry - longDiffSL;
    CHOCH = close + (targetMulti / 2 * longDiffSL);
    BOS = low  - (Zband * 15);
    top = high + (Zband * 0.5);
    bot = low - (Zband * 0.5);
    Message = Round(WickPer, 2);
    ChoIndex = 0;#ChoIndex[1];
    ChoIndex1 = 0;
    Bosindex = 0;
    Bosindex1 = 0;
    CHOCHLab = na;
    bosLab = na;
    TradeisON = yes;
    ChochisON = no;
    BOSisON = no;
} else
if TradeisON[1] {
    entry = entry[1];
    LongIndex = LongIndex[1];
    TP = TP[1];
    SL = SL[1];
    CHOCH = CHOCH[1];
    BOS = BOS[1];
    Message = no;
    top = top[1];
    bot = bot[1];
    if close >= CHOCH and !ChochisON[1] {
        ChoIndex = bar_index;
        ChoIndex1 = LongIndex;
        CHOCHLab = Floor((ChoIndex1 + ChoIndex) / 2);
        ChochisON = yes;
    } else {
        ChoIndex = 0;
        ChoIndex1 = 0;
        CHOCHLab = na;
        ChochisON = ChochisON[1];
    }
    if close <= BOS and !BOSisON[1] {
        Bosindex = bar_index;
        Bosindex1 = LongIndex;
        bosLab = Floor((Bosindex1 + Bosindex) / 2);
        BOSisON = yes;
    } else {
        Bosindex = 0;
        Bosindex1 = 0;
        bosLab = na;
        BOSisON = BOSisON[1];
    }
    TradeisON = if high >= TP then no else
                if close <= SL then no else TradeisON[1];
} else {
    entry = entry[1];
    LongIndex = LongIndex[1];
    TP = TP[1];
    SL = SL[1];
    CHOCH = CHOCH[1];
    BOS = BOS[1];
    Message = no;
    top = top[1];
    bot = bot[1];
    ChoIndex  = 0;#ChoIndex[1];
    ChoIndex1 = 0;#ChoIndex1[1];
    Bosindex  = 0;#Bosindex[1];
    Bosindex1 = 0;#Bosindex1[1];
    CHOCHLab  = na;
    bosLab    = na;
    TradeisON = if high >= TP then no else
                if close <= SL then no else TradeisON[1];
    ChochisON = if TradeisON then ChochisON[1] else no;
    BOSisON   = if TradeisON then BOSisON[1] else no;
}
def plotCond = (TradeisON or TradeisON[2]);
def choChCond = TradeisON and bar_index >= HighestAll(ChoIndex1) - 1 and bar_index <= HighestAll(ChoIndex);
def bosCond   = TradeisON and bar_index >= HighestAll(Bosindex1) - 1 and bar_index <= HighestAll(Bosindex);
def choChLabCond = bar_index == HighestAll(CHOCHLab);
def bosLabCond   = bar_index == HighestAll(bosLab);
def topLine =  if TradeisON and top then top else na;
def botLine =  if TradeisON and bot then bot else na;

plot TpLine = if ShowTargets and plotCond and TP then TP else na;
plot SlLine = if ShowTargets and plotCond and SL then SL else na;
plot chLine = if SMCLine and choChCond then CHOCH else na;
plot boLine = if SMCLine and bosCond then BOS else na;

chLine.SetStyle(Curve.SHORT_DASH);
chLine.SetDefaultColor(CreateColor(4,123,136));
boLine.SetStyle(Curve.SHORT_DASH);
boLine.SetDefaultColor(Color.DARK_RED);
TpLine.SetDefaultColor(CreateColor(78, 255, 43));
SlLine.SetDefaultColor(Color.MAGENTA);
TpLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
SlLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot wickPerc = if Message then Message else na;
wickPerc.SetDefaultColor(Color.YELLOW);
wickPerc.SetLineWeight(3);
wickPerc.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

def endTrade = !TradeisON and TradeisON[1];
def win = high >= TP;
def los = close <= SL;

plot TradeEnd = if !ShowTargets then na else
                if endTrade[2] then
                if los[2] then SL[2] else TP[2] else na;
TradeEnd.SetLineWeight(2);
TradeEnd.AssignValueColor(if win[2] then Color.CYAN else Color.MAGENTA);
TradeEnd.SetPaintingStrategy(PaintingStrategy.SQUARES);

#-- Clouds / Bars/ Label
AddCloud(topLine, botLine, Color.DARK_GRAY, Color.DARK_GRAY, yes);

AddChartBubble(SMCLabel and choChLabCond, CHOCH + Zband, "CHoCH", Color.WHITE);
AddChartBubble(SMCLabel and bosLabCond,  BOS - Zband, "BOS", Color.WHITE, no);

AssignPriceColor( if colorLiquidityBars and TradeisON then Color.CYAN else Color.CURRENT);

# -- Info Label

def winCnt = if endTrade then if win then winCnt[1] + 1 else winCnt[1] else winCnt[1];
def losCnt = if endTrade then if los then losCnt[1] + 1 else losCnt[1] else losCnt[1];
def PlAmt = if endTrade then if win then PlAmt[1] + (TP - Entry) * lostSize else
                             if los then PlAmt[1] - (Entry - SL) * lostSize else PlAmt[1] else PlAmt[1];
def totTrade = winCnt + losCnt;
def winRate = winCnt / totTrade;#Round(winCnt / totTrade * 100, 2);
def PL = Round(PlAmt, 2);

AddLabel(showInfoLabel, "Trades("+ totTrade+ ")"  , Color.WHITE);
AddLabel(showInfoLabel, "P/L ($" + PL + ")", if PL > 0 then Color.GREEN else
                                            if PL < 0 then Color.RED else Color.GRAY);
AddLabel(showInfoLabel, "WinRate("+ AsPercent(winRate) + ")", if winRate > 0.50 then Color.GREEN else
                                                   if winRate < 50 then Color.RED else Color.GRAY);

#-- END of CODE
I very much like this script from what I can read, a big Thank You! It would be helpful if you define a few of the terms. Like, choChCond, CHOCH, BOS, etc. Thank you in advance for these clarifications.
 
Hey ,Samer. is the entry as soon as the cyan candles appear with the value at the bottom? Couldn't find any information on where the entry is. Thank you in advance. Also does this repaint?
 
Last edited:
I very much like this script from what I can read, a big Thank You! It would be helpful if you define a few of the terms. Like, choChCond, CHOCH, BOS, etc. Thank you in advance for these clarifications.

ICT (Inner Circle Trading) takes basic trading concepts and rebundles them with new terminology.
The terms CHoCH (change in character) and BOS (break in structure), simply notes the difference between pullbacks and reversals.

CHoCH is a reversal of direction
BOS is a temporary pullback, after which the direction is continued.
epThWls.png


Reversion traders attempt to find the reversal; as the move, before a trend is defined; can be the most significant. But it can also the most risky; if the reversal does not materialize and the stock drops ever lower.
Trend traders wait and trade the pullbacks.

Hey ,Samer. is the entry as soon as the cyan candles appear with the value at the bottom? Couldn't find any information on where the entry is. Thank you in advance. Also does this repaint?

ICT Market Structure indicators show the ZONE where your strategy signals are most likely to be optimal.
This assists with reducing the false signals in oscillators and other trend/momentum studies.

The recommended use of Market Structure indicators, is to look for your strategy signal from your RSI, MACD, or any other trend/momentum indicator or whatever else is your strategy to appear within the Market Structure Zone that is identified with cyan candles.

repainting indicators on this forum are identified with a repaints prefix.
 
Last edited:
trades label seems to not agree with number of trades opened, but number of days trade is on. And how does this affect winrate? alos what is the first label before trades (no code for it???) I'm a newbie here but trying to learn, Thanks
 
View attachment 20444
Author Message:
The Liquidity Hunter helps traders identify areas in the market where reversals may occur by analyzing candle formations and structures.
For more Details: https://www.tradingview.com/v/E9z8Isgd/

CODE:

CSS:
#//https://www.tradingview.com/v/E9z8Isgd/
#// This source code is subject to the terms of the Mozilla Public License 2.0
#// © ChartPrime
#indicator("Liquidity Hunter [ChartPrime]",shorttitle = "Liquidity Hunter [ChartPrime]"
# Converted and mod by Sam4Cok@Samer800    - 12/2023

input showInfoLabel = yes;
input colorLiquidityBars = yes;
input useFilter = no;
input filterLength = 14;
input showMarketCharacter = {Default "Lines & Labels", "Lines Only", "Labels Only", "Don't Show"};
input bodyPercentage = 30;    # "Body %" tooltip = "Body Value will be lower than this "
input WickPercentage = 60;    # "Wick %" tooltip = "Wick Value will be higher than this "
input ShowTargets = yes;      # "Show Targets"
input lostSize = 100;
input targetMulti   = 1.5;    # "Profit Target "
input stopLossMulti = 1.5;    # "SL Target "


def na = Double.NaN;
def bar = CompoundValue(1, AbsValue(BarNumber()), 1);
def last = !IsNaN(close);
def bar_index = if last then bar else bar_index[1];
def SMCLine;
def SMCLabel;
Switch (showMarketCharacter) {
Case "Lines Only" :
    SMCLine  = yes;
    SMCLabel = no;
Case "Labels Only" :
    SMCLine  = no;
    SMCLabel = yes;
Case "Don't Show" :
    SMCLine  = no;
    SMCLabel = no;
Default :
    SMCLine  = yes;
    SMCLabel = yes;
}
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
    def _pivotRange;
    ##############
    _BN  = BarNumber();
    _nan = Double.NaN;
    _pivotRange = lbL + lbL;
    _VStop = if !isNaN(dat[_pivotRange]) 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;
}
Script get_counts {
input condition = no;
input top = high;
input btm = low;
    def count;# = 0
    if condition {
        count = 0;
    } else {
        count = count[1] + (if low < top and high > btm then 1 else 0);
    }
    plot cnt = count;
}
Script _Band {
    input len = 5;
    def nATR = ATR(LENGTH = len);
    def Band = Min(nATR * 0.3, close * (0.3 / 100));
    plot _Band = Band[20] / 2;
}
def _Band = _Band(5);
def Zband = _Band(30);
def range = AbsValue(high[1] - low[1]);
def LowerWickRange = Min(open[1], close[1]) - low[1];
def BodyPer = AbsValue(open[1] - close[1]) / range * 100;
def WickPer = (LowerWickRange / range) * 100;

def t = bar_index;
def TIME = if t[5] > 0 then t[5] else 1;
def LTIME = if TIME[1] then TIME[1] else 1;
def Slope = (close[1] - close[2]) / (TIME - LTIME);
def CON = BodyPer <= bodyPercentage and WickPer >= WickPercentage and (Slope * t > 0) and _Band >= _Band[1];

def ph_top;
def ph_btm;
def phtop = if ph_top[1] then ph_top[1] else high + _Band;
def phbtm = if ph_btm[1] then ph_btm[1] else low  - _Band;
def pvtH =  findpivots(high, 1, filterLength, RoundUp(filterLength/2, 0));
def ph_count = get_counts(!isNaN(pvtH), phtop, phbtm);
    ph_top = if !isNaN(pvtH) then high + _Band else phtop;
    ph_btm = if !isNaN(pvtH) then low  - _Band else phbtm;

def filter = if useFilter then ph_count > 1 else yes;
def long = filter and CON;
def nATR = ATR(Length = 14);
def x2 = low - nATR * stopLossMulti;
def longDiffSL = AbsValue(close - x2);

def TradeisON;
def LongIndex;
def TP;
def CHOCH;
def SL;
def BOS;
def Message;
def top;
def bot;
def ChochisON;
def BOSisON;
def ChoIndex;
def ChoIndex1;
def CHOCHLab;
def Bosindex;
def Bosindex1;
def bosLab;
def entry;
if long and !TradeisON[1] {
    entry = ohlc4[-1];
    LongIndex = bar_index;
    TP = entry + (targetMulti * longDiffSL);
    SL = entry - longDiffSL;
    CHOCH = close + (targetMulti / 2 * longDiffSL);
    BOS = low  - (Zband * 15);
    top = high + (Zband * 0.5);
    bot = low - (Zband * 0.5);
    Message = Round(WickPer, 2);
    ChoIndex = 0;#ChoIndex[1];
    ChoIndex1 = 0;
    Bosindex = 0;
    Bosindex1 = 0;
    CHOCHLab = na;
    bosLab = na;
    TradeisON = yes;
    ChochisON = no;
    BOSisON = no;
} else
if TradeisON[1] {
    entry = entry[1];
    LongIndex = LongIndex[1];
    TP = TP[1];
    SL = SL[1];
    CHOCH = CHOCH[1];
    BOS = BOS[1];
    Message = no;
    top = top[1];
    bot = bot[1];
    if close >= CHOCH and !ChochisON[1] {
        ChoIndex = bar_index;
        ChoIndex1 = LongIndex;
        CHOCHLab = Floor((ChoIndex1 + ChoIndex) / 2);
        ChochisON = yes;
    } else {
        ChoIndex = 0;
        ChoIndex1 = 0;
        CHOCHLab = na;
        ChochisON = ChochisON[1];
    }
    if close <= BOS and !BOSisON[1] {
        Bosindex = bar_index;
        Bosindex1 = LongIndex;
        bosLab = Floor((Bosindex1 + Bosindex) / 2);
        BOSisON = yes;
    } else {
        Bosindex = 0;
        Bosindex1 = 0;
        bosLab = na;
        BOSisON = BOSisON[1];
    }
    TradeisON = if high >= TP then no else
                if close <= SL then no else TradeisON[1];
} else {
    entry = entry[1];
    LongIndex = LongIndex[1];
    TP = TP[1];
    SL = SL[1];
    CHOCH = CHOCH[1];
    BOS = BOS[1];
    Message = no;
    top = top[1];
    bot = bot[1];
    ChoIndex  = 0;#ChoIndex[1];
    ChoIndex1 = 0;#ChoIndex1[1];
    Bosindex  = 0;#Bosindex[1];
    Bosindex1 = 0;#Bosindex1[1];
    CHOCHLab  = na;
    bosLab    = na;
    TradeisON = if high >= TP then no else
                if close <= SL then no else TradeisON[1];
    ChochisON = if TradeisON then ChochisON[1] else no;
    BOSisON   = if TradeisON then BOSisON[1] else no;
}
def plotCond = (TradeisON or TradeisON[2]);
def choChCond = TradeisON and bar_index >= HighestAll(ChoIndex1) - 1 and bar_index <= HighestAll(ChoIndex);
def bosCond   = TradeisON and bar_index >= HighestAll(Bosindex1) - 1 and bar_index <= HighestAll(Bosindex);
def choChLabCond = bar_index == HighestAll(CHOCHLab);
def bosLabCond   = bar_index == HighestAll(bosLab);
def topLine =  if TradeisON and top then top else na;
def botLine =  if TradeisON and bot then bot else na;

plot TpLine = if ShowTargets and plotCond and TP then TP else na;
plot SlLine = if ShowTargets and plotCond and SL then SL else na;
plot chLine = if SMCLine and choChCond then CHOCH else na;
plot boLine = if SMCLine and bosCond then BOS else na;

chLine.SetStyle(Curve.SHORT_DASH);
chLine.SetDefaultColor(CreateColor(4,123,136));
boLine.SetStyle(Curve.SHORT_DASH);
boLine.SetDefaultColor(Color.DARK_RED);
TpLine.SetDefaultColor(CreateColor(78, 255, 43));
SlLine.SetDefaultColor(Color.MAGENTA);
TpLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
SlLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot wickPerc = if Message then Message else na;
wickPerc.SetDefaultColor(Color.YELLOW);
wickPerc.SetLineWeight(3);
wickPerc.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

def endTrade = !TradeisON and TradeisON[1];
def win = high >= TP;
def los = close <= SL;

plot TradeEnd = if !ShowTargets then na else
                if endTrade[2] then
                if los[2] then SL[2] else TP[2] else na;
TradeEnd.SetLineWeight(2);
TradeEnd.AssignValueColor(if win[2] then Color.CYAN else Color.MAGENTA);
TradeEnd.SetPaintingStrategy(PaintingStrategy.SQUARES);

#-- Clouds / Bars/ Label
AddCloud(topLine, botLine, Color.DARK_GRAY, Color.DARK_GRAY, yes);

AddChartBubble(SMCLabel and choChLabCond, CHOCH + Zband, "CHoCH", Color.WHITE);
AddChartBubble(SMCLabel and bosLabCond,  BOS - Zband, "BOS", Color.WHITE, no);

AssignPriceColor( if colorLiquidityBars and TradeisON then Color.CYAN else Color.CURRENT);

# -- Info Label

def winCnt = if endTrade then if win then winCnt[1] + 1 else winCnt[1] else winCnt[1];
def losCnt = if endTrade then if los then losCnt[1] + 1 else losCnt[1] else losCnt[1];
def PlAmt = if endTrade then if win then PlAmt[1] + (TP - Entry) * lostSize else
                             if los then PlAmt[1] - (Entry - SL) * lostSize else PlAmt[1] else PlAmt[1];
def totTrade = winCnt + losCnt;
def winRate = winCnt / totTrade;#Round(winCnt / totTrade * 100, 2);
def PL = Round(PlAmt, 2);

AddLabel(showInfoLabel, "Trades("+ totTrade+ ")"  , Color.WHITE);
AddLabel(showInfoLabel, "P/L ($" + PL + ")", if PL > 0 then Color.GREEN else
                                            if PL < 0 then Color.RED else Color.GRAY);
AddLabel(showInfoLabel, "WinRate("+ AsPercent(winRate) + ")", if winRate > 0.50 then Color.GREEN else
                                                   if winRate < 50 then Color.RED else Color.GRAY);

#-- END of CODE

What do I need to do to use this in a scanner to alert when price < daily swing low ie BoS? I tried using your scrip in custom scanner with close is less than or equal to liquidty hunter study bo line within 15 bars on SP500 and nothing came up.
 
What do I need to do to use this in a scanner to alert when price < daily swing low ie BoS? I tried using your scrip in custom scanner with close is less than or equal to liquidty hunter study bo line within 15 bars on SP500 and nothing came up.

S&P500 has been running hot, not too many corrections to below the break in structure line.
If you have a chart of an S&P500 stock that has traded below the break in structure line on the daily chart, I will be glad to investigate how to scan for it.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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