zig zag temelli....
pivot mantığıyla...olası destek ve dirençleri çizen kod.....
PHP Code:
 // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HeWhoMustNotBeNamed
//                                       ░▒             
//                                  ▒▒▒   ▒▒      
//                              ▒▒▒▒▒     ▒▒      
//                      ▒▒▒▒▒▒▒░     ▒     ▒▒          
//                  ▒▒▒▒▒▒           ▒     ▒▒          
//             ▓▒▒▒       ▒        ▒▒▒▒▒▒▒▒▒▒▒  
//   ▒▒▒▒▒▒▒▒▒▒▒ ▒        ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒         
//   ▒  ▒       ░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░        
//   ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒▒▒▒▒▒▒▒         
//   ▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒                       
//    ▒▒▒▒▒         ▒▒▒▒▒▒▒                            
//                 ▒▒▒▒▒▒▒▒▒                           
//                ▒▒▒▒▒ ▒▒▒▒▒                          
//               ░▒▒▒▒   ▒▒▒▒▓      ████████╗██████╗ ███████╗███╗   ██╗██████╗  ██████╗ ███████╗ ██████╗ ██████╗ ██████╗ ███████╗
//              ▓▒▒▒▒     ▒▒▒▒      ╚══██╔══╝██╔══██╗██╔════╝████╗  ██║██╔══██╗██╔═══██╗██╔════╝██╔════╝██╔═══██╗██╔══██╗██╔════╝
//              ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒        ██║   ██████╔╝█████╗  ██╔██╗ ██║██║  ██║██║   ██║███████╗██║     ██║   ██║██████╔╝█████╗ 
//             ▒▒▒▒▒       ▒▒▒▒▒       ██║   ██╔══██╗██╔══╝  ██║╚██╗██║██║  ██║██║   ██║╚════██║██║     ██║   ██║██╔═══╝ ██╔══╝  
//            ▒▒▒▒▒         ▒▒▒▒▒      ██║   ██║  ██║███████╗██║ ╚████║██████╔╝╚██████╔╝███████║╚██████╗╚██████╔╝██║     ███████╗
//             ▒▒             ▒                        
//@version=5
indicator("Next Pivot Projection [Trendoscope]""NPP[Trendoscope]"overlay=truemax_lines_count 500max_labels_count 500)
import HeWhoMustNotBeNamed/mZigzag/12 as zg
import HeWhoMustNotBeNamed
/enhanced_ta/14 as eta
import HeWhoMustNotBeNamed
/arrays/as pa
length 
input.int(8'Length'group='Zigzag'display display.none)
oscillatorType input.string("rsi"title="Oscillator"inline="osc"options=["cci""cmo""cog""mfi""roc""rsi"],
                     
group='Oscillator'display display.none)
oscLength input.int(14title=""inline="osc"group='Oscillator'display display.none)
supertrendLength input.int(5'History'inline='st'group='Supertrend'display display.none)
drawSupertrend input.bool(false"Draw Zigzag Supertrend"inline='st2'group='Supertrend'display display.none)

showTable input.bool(false'Detailed Stats'inline='txt'group 'Stats and Display'display display.none)
txtSize input.string(size.tiny'', [size.tinysize.smallsize.normalsize.largesize.huge],
                         
inline='txt'group 'Stats and Display'display display.none)
txtColor input.color(color.white''inline='txt'group 'Stats and Display'display display.none)

showPivotLines input.bool(true'Pivot Lines'inline='pli'group 'Stats and Display'display display.none)
showPivotLabel input.bool(false'Pivot Label'inline='pla'group 'Stats and Display'display display.none)
fillAreas input.bool(true'Fill Bullish/Bearish Sentiments'inline='fil'group 'Stats and Display'display display.none)
increment(mtxrowcolval=1)=>matrix.set(mtxrowcolmatrix.get(mtxrowcol)+val)
gettrendindex(int priceint oscint trend)=>
    
trendFactor trend 1
    priceFactor 
math.abs(price) > 10
    oscFactor 
math.abs(osc) > 10
    trendFactor
*priceFactor*oscFactor


getSentimentDetails
(pDiroDirsDir) =>
    
sentiment pDir == oDir sDir == pDir or sDir == -pDir ? -sDir sDir sDir == pDir or sDir == -oDir : (math.abs(oDir) > math.abs(pDir) ? sDir : -sDir) * (sDir == oDir 3)
    
sentimentSymbol sentiment == '⬆' sentiment == -'⬇' sentiment == '↗' sentiment == -'↘' sentiment == '⤴' sentiment == -'⤵' sentiment == '⤒' sentiment == -'⤓' '▣'
    
sentimentColor sentiment == color.green sentiment == -color.red sentiment == color.lime sentiment == -color.orange sentiment == color.rgb(202224130) : sentiment == -color.rgb(2501281140) : color.silver
    sentimentLabel 
math.abs(sentiment) == 'C' math.abs(sentiment) == 'H' math.abs(sentiment) == 'D' 'I'
    
[sentimentSymbolsentimentLabelsentimentColor]


getStatus(int trendIndexint pivotDir)=>
    
trendFactor int(trendIndex/4)
    
remainder trendIndex 4
    priceFactor 
int(remainder/2)+1
    oscFactor 
= (remainder 2)+1
    trendChar 
= (trendFactor == 0)? 'U' 'D'
    
priceChar pivotDir 0? (priceFactor == 2'HH' 'LH') : (priceFactor == 2'LL' 'HL')
    
oscChar pivotDir 0? (oscFactor == 2'HH' 'LH') : (oscFactor == 2'LL' 'HL')
    
trendChar ' - ' priceChar '/'+oscChar

draw_zg_line
(idx1idx2zigzaglineszigzaglabelsvalueMatrixdirectionMatrixratioMatrix,  divergenceMatrixdoubleDivergenceMatrix,
                                         
barArraytrendArraylineColorlineWidthlineStyle) =>
    if 
matrix.rows(valueMatrix) > 2
        idxLen1 
matrix.rows(valueMatrix)-idx1
        idxLen2 
matrix.rows(valueMatrix)-idx2
        lastValues 
matrix.row(valueMatrixidxLen1)
        
llastValues matrix.row(valueMatrixidxLen2)
        
        
lastDirections matrix.row(directionMatrixidxLen1)
        
lastRatios matrix.row(ratioMatrixidxLen1)
        
lastDivergence matrix.row(divergenceMatrixidxLen1)
        
lastDoubleDivergence matrix.row(doubleDivergenceMatrixidxLen1)

        
y1 = array.get(lastValues0)
        
y2 = array.get(llastValues0)
        
x1 = array.get(barArrayidxLen1)
        
x2 = array.get(barArrayidxLen2)
        
zline line.new(x1=x1y1=y1x2=x2y2=y2color=lineColorwidth=lineWidthstyle=lineStyle)
        
currentDir y1 y2: -1
        
        priceDir 
= array.get(lastDirections0)
        
oscDir = array.get(lastDirections1)
        
trendDir = array.get(trendArrayidxLen1)
        
trendIndex gettrendindex(priceDiroscDirtrendDir)
        
trendLabel getStatus(trendIndexcurrentDir)
        [
sentimentSymbolsentimentLabelsentimentColor] = getSentimentDetails(priceDiroscDirtrendDir)

        
labelStyle currentDir 0label.style_label_down label.style_label_up
        zlabel 
showPivotLabel label.new(x=x1y=y1yloc=yloc.pricecolor=sentimentColorstyle=labelStyletext=sentimentSymbol ' ' trendLabel
                                     
textcolor=color.blacksize size.smalltooltip=sentimentLabel) : na
        
if array.size(zigzaglines) > 0
            lastLine 
= array.get(zigzaglines, array.size(zigzaglines)-1)
            if 
line.get_x2(lastLine) == x2 and line.get_x1(lastLine) <= x1
                pa
.pop(zigzaglines)
                
pa.pop(zigzaglabels)
        
        
pa.push(zigzaglineszline500)
        
pa.push(zigzaglabelszlabel500)

draw(matrix<floatvalueMatrixmatrix<intdirectionMatrixmatrix<floatratioMatrix,  matrix<intdivergenceMatrixmatrix<intdoubleDivergenceMatrix, array<intbarArray, array<inttrendArray,
                 
bool newZGbool doubleZGcolor lineColor color.blueint lineWidth 1string lineStyle line.style_solid)=>
    var 
zigzaglines = array.new_line(0)
    var 
zigzaglabels = array.new_label(0)
    if(
newZG)
        if 
doubleZG
            draw_zg_line
(23zigzaglineszigzaglabelsvalueMatrixdirectionMatrixratioMatrixdivergenceMatrixdoubleDivergenceMatrixbarArraytrendArray,
                             
lineColorlineWidthlineStyle)

        if 
matrix.rows(valueMatrix) >= 2
            draw_zg_line
(12zigzaglineszigzaglabelsvalueMatrixdirectionMatrixratioMatrix,  divergenceMatrixdoubleDivergenceMatrixbarArraytrendArray,
                             
lineColorlineWidthlineStyle)
    [
valueMatrixdirectionMatrixratioMatrixdivergenceMatrixdoubleDivergenceMatrixbarArrayzigzaglineszigzaglabels]

    

indicatorHigh = array.new_float()
indicatorLow = array.new_float()
indicatorLabels = array.new_string()

[
oscHigh__] = eta.oscillator(oscillatorTypeoscLengthoscLengthoscLengthhigh)
[
oscLow__] = eta.oscillator(oscillatorTypeoscLengthoscLengthoscLengthlow)
array.
push(indicatorHighmath.round(oscHigh,2))
array.
push(indicatorLowmath.round(oscLow,2))
array.
push(indicatorLabelsoscillatorType+str.tostring(oscLength))


[
valueMatrixdirectionMatrixratioMatrixdivergenceMatrixdoubleDivergenceMatrixbarArraytrendArraysupertrendDirsupertrendnewZGdoubleZG] = 
                                                         
zg.calculate(length, array.from(highlow), indicatorHighindicatorLowsupertrendLength supertrendLength)

nextDirection matrix.rows(directionMatrix) > 0matrix.row(directionMatrixmatrix.rows(directionMatrix)-1) : array.new_int()
lastDirection matrix.rows(directionMatrix) > 1matrix.row(directionMatrixmatrix.rows(directionMatrix)-2) : array.new_int()
llastDirection matrix.rows(directionMatrix) > 2matrix.row(directionMatrixmatrix.rows(directionMatrix)-3) : array.new_int()
lllastDirection matrix.rows(directionMatrix) > 3matrix.row(directionMatrixmatrix.rows(directionMatrix)-4) : array.new_int()

var 
pivotHighStats matrix.new<int>(6430)
var 
pivotLowStats matrix.new<int>(6430)

var 
pivotHighRatios matrix.new<float>(6430)
var 
pivotLowRatios matrix.new<float>(6430)

var 
pivotHighBars matrix.new<float>(6430)
var 
pivotLowBars matrix.new<float>(6430)

currentTotalTrendIndex 0
nextTotalTrendIndex 
0
currentDir 
matrix.rows(directionMatrix) > 0matrix.get(directionMatrixmatrix.rows(directionMatrix)-10) : 0

currentPDir 
lastDirection.size() > lastDirection.first() : na
changePriceDirection 
ta.change(math.sign(currentPDir))
if(array.
size(lllastDirection) > 0)
    
priceDirection = array.get(lastDirection0)
    
priceRatio matrix.get(ratioMatrixmatrix.rows(ratioMatrix)-20)

    
numberOfBars = array.get(barArray, array.size(barArray)-2) - array.get(barArray, array.size(barArray)-3)
    
currentPriceDirection = array.get(lastDirection0)
    
currentOscDirection = array.get(lastDirection1)
    
currentTrend = array.get(trendArray, array.size(trendArray)-2)

    
nextPriceDirection = array.get(nextDirection0)
    
nextOscDirection = array.get(nextDirection1)
    
nextTrend = array.get(trendArray, array.size(trendArray)-1)

    
lastPriceDirection = array.get(llastDirection0)
    
lastOscDirection = array.get(llastDirection1)
    
lastTrend = array.get(trendArray, array.size(trendArray)-3)

    
llastPriceDirection = array.get(lllastDirection0)
    
llastOscDirection = array.get(lllastDirection1)
    
llastTrend = array.get(trendArray, array.size(trendArray)-4)

    
colLast math.abs(priceDirection) %2

    nextTrendIndex 
gettrendindex(nextPriceDirectionnextOscDirectionnextTrend)
    
currentTrendIndex gettrendindex(currentPriceDirectioncurrentOscDirectioncurrentTrend)
    
lastTrendIndex gettrendindex(lastPriceDirectionlastOscDirectionlastTrend)
    
llastTrendIndex gettrendindex(llastPriceDirectionllastOscDirectionllastTrend)

    
totalIndex lastTrendIndex*llastTrendIndex
    currentTotalTrendIndex 
:= currentTrendIndex*lastTrendIndex
    nextTotalTrendIndex 
:= nextTrendIndex*currentTrendIndex

    matrixToSet 
math.sign(priceDirection) > 0pivotHighStats pivotLowStats
    ratioMatrixToSet 
math.sign(priceDirection) > 0pivotHighRatios pivotLowRatios
    barMatrixToSet 
math.sign(priceDirection) > 0pivotHighBars pivotLowBars

    
if(not na(currentPDir) and changePriceDirection != 0)
        
increment(matrixToSettotalIndexcolLast)
        
increment(ratioMatrixToSettotalIndexcolLastpriceRatio)
        
increment(barMatrixToSettotalIndexcolLastnumberOfBars)

        
increment(matrixToSettotalIndex2)
        
increment(ratioMatrixToSettotalIndex2priceRatio)
        
increment(barMatrixToSettotalIndex2numberOfBars)


var 
float hhValue na
var float lhValue na

var float llValue na
var float hlValue na

var float hhProbability na
var float llProbability na

var float htRatio na
var float ltRatio na
if(array.size(barArray) > 10)
    
currentBar = array.get(barArray, array.size(barArray)-1)
    
lastBar = array.get(barArray, array.size(barArray)-2)
    
currentPrice matrix.get(valueMatrixmatrix.rows(valueMatrix)-10)
    
lastPrice matrix.get(valueMatrixmatrix.rows(valueMatrix)-20)
    
llastPrice matrix.get(valueMatrixmatrix.rows(valueMatrix)-30)
    
startRow 2
    
var statsTable showTable table.new(position=position.top_rightcolumns=10rows=64+startRowborder_color color.blackborder_width 2) : na
    
    phSortIndices 
= array.sort_indices(matrix.col(pivotHighStats2), order.descending)
    
    
phColStart currentDir 5
    
    
if(showTable)
        
table.clear(statsTable00964+startRow-1)
        
table.cell(statsTablephColStart0'Pivot High Projection'text_color txtColortext_size txtSizebgcolor color.maroon)
        
table.cell(statsTablephColStart1'Last Two Pivots'text_color txtColortext_size txtSizebgcolor color.maroon)
        
table.cell(statsTablephColStart+21'HH'text_color txtColortext_size txtSizebgcolor color.maroon)
        
table.cell(statsTablephColStart+31'LH'text_color txtColortext_size txtSizebgcolor color.maroon)
        
table.cell(statsTablephColStart+41'T'text_color txtColortext_size txtSizebgcolor color.maroon)
        
table.merge_cells(statsTablephColStart0phColStart+40)
        
table.merge_cells(statsTablephColStart1phColStart+11)

    
hlr startRow
    
for i=0 to 63
        si 
= array.get(phSortIndicesi)
        
lastTrendIndex int(si/8)
        
llastTrendIndex si%8

        lastPivotStatus 
getStatus(lastTrendIndex, -1)
        
llastPivotStatus getStatus(llastTrendIndex1)
        
hhStats matrix.get(pivotHighStatssi0)
        
lhStats matrix.get(pivotHighStatssi1)
        
tStats matrix.get(pivotHighStatssi2)

        
hhRatio math.round(matrix.get(pivotHighRatiossi0)/hhStats3)
        
lhRatio math.round(matrix.get(pivotHighRatiossi1)/lhStats3)
        
tRatio math.round(matrix.get(pivotHighRatiossi2)/tStats3)

        
hhBars math.round(matrix.get(pivotHighBarssi0)/hhStats)
        
lhBars math.round(matrix.get(pivotHighBarssi1)/lhStats)
        
tBars math.round(matrix.get(pivotHighBarssi2)/tStats)
        
highlight math.sign(currentDir) < nextTotalTrendIndex == si  currentTotalTrendIndex == si

        hhTooltip 
'Average Ratio - '+str.tostring(hhRatio)+'\n'+'Average Bars - '+str.tostring(hhBars)
        
lhTooltip 'Average Ratio - '+str.tostring(lhRatio)+'\n'+'Average Bars - '+str.tostring(lhBars)
        
tTooltip 'Average Ratio - '+str.tostring(tRatio)+'\n'+'Average Bars - '+str.tostring(tBars)

        if(
highlight)
            var 
line hhLine na
            
var line lhLine na
            
var line tLine na
            
var label hhLabel na
            
var label lhLabel na
            
var label tLabel na

            line
.delete(hhLine)
            
line.delete(lhLine)
            
line.delete(tLine)
            
label.delete(hhLabel)
            
label.delete(lhLabel)
            
label.delete(tLabel)
            
            
x1 math.sign(currentDir) < currentBar lastBar
            hhX2 
x1 hhBars
            lhX2 
x1 lhBars
            tX2 
x1 tBars

            y1 
math.sign(currentDir) < currentPrice lastPrice
            prev 
math.sign(currentDir) < lastPrice llastPrice
            hhY2 
math.round_to_mintick(y1 math.abs(y1-prev)*hhRatio)
            
lhY2 math.round_to_mintick(y1 math.abs(y1-prev)*lhRatio)
            
tY2 math.round_to_mintick(y1 math.abs(y1-prev)*tRatio)
            
hhLine := line.new(x1y1hhX2hhY2xloc=xloc.bar_indexcolor=color.greenstyle=line.style_arrow_right)
            
lhLine := line.new(x1y1lhX2lhY2xloc=xloc.bar_indexcolor=color.limestyle=line.style_arrow_right)
            
tLine := line.new(x1y1tX2tY2xloc=xloc.bar_indexcolor=color.yellowstyle=line.style_arrow_right)

            
hhPercent str.tostring(hhStats*100/tStatsformat.percent)
            
lhPercent str.tostring(lhStats*100/tStatsformat.percent)
            
hhText 'Number of Historical References :'+str.tostring(hhStats)+'/'+str.tostring(tStats)+
                         
'\nProbability of Higher High :'+hhPercent+
                         
'\nAverage Higher High Ratio :'+str.tostring(hhRatio) +
                         
'\nAverage Higher High Bars :'+str.tostring(hhBars)
            
lhText 'Number of Historical References :'+str.tostring(lhStats)+'/'+str.tostring(tStats)+
                         
'\nProbability of Lower High :'+lhPercent+
                         
'\nAverage Lower High Ratio :'+str.tostring(lhRatio) +
                         
'\nAverage Lower High Bars :'+str.tostring(lhBars)
            
tText 'Number of Historical References :'+str.tostring(tStats)+
                         
'\nAverage Fib Ratio :'+str.tostring(tRatio)+
                         
'\nAverage Bars :'+str.tostring(tBars)
            
hhLabel := label.new(hhX2hhY2str.tostring(hhY2)+ ' - ' +hhPercentstyle=label.style_label_lower_leftcolor=color.new(color.green70), textcolor color.whitesize=size.smalltooltip=hhText)
            
lhLabel := label.new(lhX2lhY2str.tostring(lhY2)+ ' - ' +lhPercentstyle=label.style_label_upper_leftcolor=color.new(color.lime70), textcolor color.whitesize=size.smalltooltip=lhText)
            
tLabel := label.new(tX2tY2str.tostring(tY2)+ '@'+str.tostring(tRatio), style=label.style_label_leftcolor=color.new(color.yellow70), textcolor color.whitesize=size.smalltooltip=tText)
            
hhValue := hhY2
            lhValue 
:= lhY2
            hhProbability 
:= hhStats*100/tStats
            htRatio 
:= tRatio

        
if(hhStats != and lhStats != 0) and showTable
            table
.cell(statsTablephColStarthlrllastPivotStatustext_color txtColortext_size txtSizebgcolor color.new(color.lime60))
            
table.cell(statsTablephColStart+1hlrlastPivotStatustext_color txtColortext_size txtSizebgcolor color.new(color.orange60))
            
table.cell(statsTablephColStart+2hlrstr.tostring(hhStats)+' - '+str.tostring(hhRatio), text_color txtColortext_size txtSizebgcolor color.new(color.greenhighlight 50 90), tooltip hhTooltip)
            
table.cell(statsTablephColStart+3hlrstr.tostring(lhStats)+' - '+str.tostring(lhRatio), text_color txtColortext_size txtSizebgcolor color.new(color.redhighlight50 90), tooltip lhTooltip)
            
table.cell(statsTablephColStart+4hlrstr.tostring(tStats)+' - '+str.tostring(tRatio), text_color txtColortext_size txtSizebgcolor color.from_gradient(hhStats/tStats01color.redcolor.green), tooltip tTooltip)
            
hlr+=1


    plColStart 
currentDir 5
    
if(showTable)
        
table.cell(statsTableplColStart0'Pivot Low Projection'text_color txtColortext_size txtSizebgcolor color.maroon)
        
table.cell(statsTableplColStart1'Last Two Pivots'text_color txtColortext_size txtSizebgcolor color.maroon)
        
table.cell(statsTableplColStart+21'LL'text_color txtColortext_size txtSizebgcolor color.maroon)
        
table.cell(statsTableplColStart+31'HL'text_color txtColortext_size txtSizebgcolor color.maroon)
        
table.cell(statsTableplColStart+41'T'text_color txtColortext_size txtSizebgcolor color.maroon)
        
table.merge_cells(statsTableplColStart0plColStart+40)
        
table.merge_cells(statsTableplColStart1plColStart+11)
    
plSortIndices = array.sort_indices(matrix.col(pivotLowStats2), order.descending)

    
llr startRow
    
for i=0 to 63
        si 
= array.get(plSortIndicesi)
        
lastTrendIndex int(si/8)
        
llastTrendIndex si%8

        lastPivotStatus 
getStatus(lastTrendIndex1)
        
llastPivotStatus getStatus(llastTrendIndex, -1)
        
llStats matrix.get(pivotLowStatssi0)
        
hlStats matrix.get(pivotLowStatssi1)
        
tStats matrix.get(pivotLowStatssi2)

        
llRatio math.round(matrix.get(pivotLowRatiossi0)/llStats3)
        
hlRatio math.round(matrix.get(pivotLowRatiossi1)/hlStats3)
        
tRatio math.round(matrix.get(pivotLowRatiossi2)/tStats3)

        
llBars math.round(matrix.get(pivotLowBarssi0)/llStats)
        
hlBars math.round(matrix.get(pivotLowBarssi1)/hlStats)
        
tBars math.round(matrix.get(pivotLowBarssi2)/tStats)

        
highlight math.sign(currentDir) > nextTotalTrendIndex== si  currentTotalTrendIndex  == si

        llTooltip 
'Average Ratio - '+str.tostring(llRatio)+'\n'+'Average Bars - '+str.tostring(llBars)
        
hlTooltip 'Average Ratio - '+str.tostring(hlRatio)+'\n'+'Average Bars - '+str.tostring(hlBars)
        
tTooltip 'Average Ratio - '+str.tostring(tRatio)+'\n'+'Average Bars - '+str.tostring(tBars)

        if(
highlight)
            var 
line llLine na
            
var line hlLine na
            
var line tLine na

            
var label llLabel na
            
var label hlLabel na
            
var label tLabel na

            line
.delete(llLine)
            
line.delete(hlLine)
            
line.delete(tLine)

            
label.delete(llLabel)
            
label.delete(hlLabel)
            
label.delete(tLabel)

            
x1 math.sign(currentDir) > currentBar lastBar
            llX2 
x1 llBars
            hlX2 
x1 hlBars
            tX2 
x1 tBars

            y1 
math.sign(currentDir) > currentPrice lastPrice
            prev 
math.sign(currentDir) > lastPrice llastPrice
            llY2 
math.round_to_mintick(y1 math.abs(y1-prev)*llRatio)
            
hlY2 math.round_to_mintick(y1 math.abs(y1-prev)*hlRatio)
            
tY2 math.round_to_mintick(y1 math.abs(y1-prev)*tRatio)
            
llLine := line.new(x1y1llX2llY2xloc=xloc.bar_indexcolor=color.redstyle=line.style_arrow_right)
            
hlLine := line.new(x1y1hlX2hlY2xloc=xloc.bar_indexcolor=color.orangestyle=line.style_arrow_right)
            
tLine := line.new(x1y1tX2tY2xloc=xloc.bar_indexcolor=color.yellowstyle=line.style_arrow_right)

            
llPercent str.tostring(llStats*100/tStatsformat.percent)
            
hlPercent str.tostring(hlStats*100/tStatsformat.percent)
            
llText 'Number of Historical References :'+str.tostring(llStats)+'/'+str.tostring(tStats)+
                         
'\nProbability of Lower Low :'+llPercent+
                         
'\nAverage Lower Low Ratio :'+str.tostring(llRatio) +
                         
'\nAverage Lower Low Bars :'+str.tostring(llBars)
            
hlText 'Number of Historical References :'+str.tostring(hlStats)+'/'+str.tostring(tStats)+
                         
'\nProbability of Higher Low :'+hlPercent+
                         
'\nAverage Higher Low Ratio :'+str.tostring(hlRatio) +
                         
'\nAverage Higher Low Bars :'+str.tostring(hlBars)
            
tText 'Number of Historical References :'+str.tostring(tStats)+
                         
'\nAverage Fib Ratio :'+str.tostring(tRatio)+
                         
'\nAverage Bars :'+str.tostring(tBars)
            
llLabel := label.new(llX2llY2str.tostring(llY2)+ ' - ' +llPercentstyle=label.style_label_upper_leftcolor=color.new(color.red70), textcolor color.whitesize=size.smalltooltip=llText)
            
hlLabel := label.new(hlX2hlY2str.tostring(hlY2)+ ' - ' +hlPercentstyle=label.style_label_lower_leftcolor=color.new(color.orange70), textcolor color.whitesize=size.smalltooltip=hlText)
            
tLabel := label.new(tX2tY2str.tostring(tY2)+ '@'+str.tostring(tRatio), style=label.style_label_leftcolor=color.new(color.yellow70), textcolor color.whitesize=size.smalltooltip=tText)
            
llValue := llY2
            hlValue 
:= hlY2
            llProbability 
:= llStats*100/tStats
            ltRatio 
:= tRatio

        
if(llStats != and hlStats != 0) and showTable
            table
.cell(statsTableplColStartllrllastPivotStatustext_color txtColortext_size txtSizebgcolor color.new(color.orange60))
            
table.cell(statsTableplColStart+1llrlastPivotStatustext_color txtColortext_size txtSizebgcolor color.new(color.lime60))
            
table.cell(statsTableplColStart+2llrstr.tostring(llStats)+' - '+str.tostring(llRatio), text_color txtColortext_size txtSizebgcolor color.new(color.redhighlight50 90), tooltip=llTooltip)
            
table.cell(statsTableplColStart+3llrstr.tostring(hlStats)+' - '+str.tostring(hlRatio), text_color txtColortext_size txtSizebgcolor color.new(color.greenhighlight50 90), tooltip hlTooltip)
            
table.cell(statsTableplColStart+4llrstr.tostring(tStats)+' - '+str.tostring(tRatio), text_color txtColortext_size txtSizebgcolor color.from_gradient(llStats/tStats01color.greencolor.red), tooltip tTooltip)
            
llr+=1


if showPivotLines
    draw
(valueMatrixdirectionMatrixratioMatrix,  divergenceMatrixdoubleDivergenceMatrixbarArraytrendArraynewZGdoubleZG)

plot(drawSupertrendsupertrend:nacolor=supertrendDir>0color.green:color.redstyle=plot.style_linebr)


hhp plot(fillAreas?hhValue:na'Higher High Range'color.new(color.green100), 1)
lhp plot(fillAreas?lhValue:na'Lower High Range'color.new(color.lime100), 1)
llp plot(fillAreas?llValue:na'Lower Low Range'color.new(color.red100), 1)
hlp plot(fillAreas?hlValue:na'Higher Low Range'color.new(color.orange100), 1)

fill(hhplhpcolor=color.new(hhProbability 50 color.green hhProbability 50color.red color.silver90))
fill(llphlpcolor=color.new(llProbability 50 color.red llProbability 50color.green color.silver90))