PHP Code:
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © east-west_trading
//@version=5
indicator("Pivots and Swings",overlay=true, max_labels_count = 500, max_lines_count = 500, max_bars_back = 500)
//User inputs
pivotbars = input.int(title = 'number of bars for pivot', defval = 2, inline='1')
swingD = input.string(title = 'Show swing details?', options=['None','On plot','In table','Both'],defval ='None', inline='1')
labelcolor = input.color(title = 'Label background color', defval =color.white, inline='2')
PHtextcolor = input.color(title = 'Pivot High text', defval=color.green, inline ='2')
PLtextcolor = input.color(title = 'Pivot low text', defval=color.red, inline='2')
colorbars = input.bool(title='color bars basis trend?', defval = false, inline='3')
uptrendup = input.color(defval = color.rgb(65, 235, 71),title = 'uptrend / up day',inline='3')
uptrenddown = input.color(defval = color.rgb(3, 113, 6),title = 'Up trend / down day', inline='3')
downtrendup = input.color(defval = color.rgb(237, 162, 188),title='Down trend / up day', inline ='5')
downtrenddown = input.color(defval = color.rgb(159, 48, 48),title='Down trend / down day',inline='5')
showfirstpivots = input.bool(title = 'Show first order pivots', defval = true, group = '---- First Order Pivots ----', inline='1')
show1sttrends = input.bool(title='Show first order swing trends', defval = false,group = '---- First Order Pivots ----', inline='1' )
FOPH_color = input.color(defval = color.lime, title = 'Pivot high', group = '---- First Order Pivots ----', inline='1')
FOPL_color = input.color(defval = color.rgb(237, 162, 188), title = 'Pivot low', group = '---- First Order Pivots ----', inline='1')
FOPH_connect_color = input.color(defval = color.rgb(188, 218, 244), title = 'Up swing', group = '---- First Order Pivots ----', inline='2')
FOPL_connect_color = input.color(defval = color.rgb(188, 218, 244), title = 'Down swing', group = '---- First Order Pivots ----',inline='2' )
FOPH_style = input.string(defval = 'Circle', title = 'High style', group = '---- First Order Pivots ----', options = ['Circle','X Cross','Cross', 'Triangle Up', 'Triangle Down', 'Flag','Arrow Up','Arrow Down','Square',
'Diamond','None'], inline = '3')
FOPL_style = input.string(defval = 'Circle', title = 'Low style', group = '---- First Order Pivots ----', options = ['Circle','X Cross','Cross', 'Triangle Up', 'Triangle Down', 'Flag','Arrow Up','Arrow Down','Square',
'Diamond','None'], inline = '3')
FOP_size = input.string(size.auto, 'Size', options=[size.auto, size.tiny,size.small,size.normal,size.large,size.huge],group = '---- First Order Pivots ----', inline='3' )
showsecondpivots = input.bool(title='Show second order pivots', defval = true, group = '---- Second Order Pivots ----', inline='1')
show2ndtrends = input.bool(title='Show second order swing trends',defval=false, group = '---- Second Order Pivots ----', inline='1' )
SOPH_color = input.color(defval = color.teal, title = 'Pivot high', group = '---- Second Order Pivots ----', inline='2')
SOPL_color = input.color(defval = color.red, title = 'Pivot low', group = '---- Second Order Pivots ----',inline='2')
SOPH_connect_color = input.color(defval = color.silver, title = 'Up swing', group = '---- Second Order Pivots ----', inline='2')
SOPL_connect_color = input.color(defval = color.silver, title = 'Down swing', group = '---- Second Order Pivots ----',inline='2' )
SOPH_style = input.string(defval = 'Triangle Down', title = ' High style', group = '---- Second Order Pivots ----', options = ['Circle','X Cross','Cross', 'Triangle Up', 'Triangle Down', 'Flag','Arrow Up',
'Arrow Down','Square', 'Diamond','None'], inline='3')
SOPL_style = input.string(defval = 'Triangle Up', title = 'Low style', group = '---- Second Order Pivots ----', options = ['Circle','X Cross','Cross', 'Triangle Up', 'Triangle Down', 'Flag','Arrow Up',
'Arrow Down','Square', 'Diamond','None'], inline='3')
SOP_size = input.string(size.auto, 'Size', options=[size.auto, size.tiny,size.small,size.normal,size.large,size.huge],group = '---- Second Order Pivots ----', inline='3' )
showthirdpivots = input.bool(title='Show third order pivots', defval = true, group = '---- Third Order Pivots ----', inline ='1')
show3rdtrends = input.bool(title='show third order swings', defval = false, group = '---- Third Order Pivots ----', inline= '1')
TOPH_color = input.color(defval = color.black, title = 'Pivot high', group = '---- Third Order Pivots ----', inline='2')
TOPL_color = input.color(defval = color.black, title = 'Pivot low', group = '---- Third Order Pivots ----',inline='2')
TOPH_connect_color = input.color(defval = color.rgb(255, 153, 0, 66), title = 'Up swing', group = '---- Third Order Pivots ----', inline='2')
TOPL_connect_color = input.color(defval = color.rgb(255, 153, 0, 66), title = 'Down swing', group = '---- Third Order Pivots ----',inline='2' )
TOPH_style = input.string(defval = 'Triangle Down', title = 'High style', group = '---- Third Order Pivots ----', options = ['Circle','X Cross','Cross', 'Triangle Up', 'Triangle Down', 'Flag','Arrow Up',
'Arrow Down','Square', 'Diamond','None'], inline='3')
TOPL_style = input.string(defval = 'Triangle Up', title = 'Low style', group = '---- Third Order Pivots ----', options = ['Circle','X Cross','Cross', 'Triangle Up', 'Triangle Down', 'Flag','Arrow Up',
'Arrow Down','Square', 'Diamond','None'], inline='3')
TOP_size = input.string(size.auto, 'Size', options=[size.auto, size.tiny,size.small,size.normal,size.large,size.huge],group = '---- Third Order Pivots ----', inline='3' )
FOPH_style_option = switch FOPH_style
'Circle' => label.style_circle
'X Cross' => label.style_xcross
'Cross' => label.style_cross
'Triangle Up' => label.style_triangleup
'Triangle Down' => label.style_triangledown
'Flag' => label.style_flag
'Arrow Up'=>label.style_arrowup
'Arrow Down'=>label.style_arrowdown
'Square'=>label.style_square
'Diamond'=>label.style_diamond
'None'=>label.style_none
FOPL_style_option = switch FOPL_style
'Circle' => label.style_circle
'X Cross' => label.style_xcross
'Cross' => label.style_cross
'Triangle Up' => label.style_triangleup
'Triangle Down' => label.style_triangledown
'Flag' => label.style_flag
'Arrow Up'=>label.style_arrowup
'Arrow Down'=>label.style_arrowdown
'Square'=>label.style_square
'Diamond'=>label.style_diamond
'None'=>label.style_none
SOPH_style_option = switch SOPH_style
'Circle' => label.style_circle
'X Cross' => label.style_xcross
'Cross' => label.style_cross
'Triangle Up' => label.style_triangleup
'Triangle Down' => label.style_triangledown
'Flag' => label.style_flag
'Arrow Up'=>label.style_arrowup
'Arrow Down'=>label.style_arrowdown
'Square'=>label.style_square
'Diamond'=>label.style_diamond
'None'=>label.style_none
SOPL_style_option = switch SOPL_style
'Circle' => label.style_circle
'X Cross' => label.style_xcross
'Cross' => label.style_cross
'Triangle Up' => label.style_triangleup
'Triangle Down' => label.style_triangledown
'Flag' => label.style_flag
'Arrow Up'=>label.style_arrowup
'Arrow Down'=>label.style_arrowdown
'Square'=>label.style_square
'Diamond'=>label.style_diamond
'None'=>label.style_none
TOPH_style_option = switch TOPH_style
'Circle' => label.style_circle
'X Cross' => label.style_xcross
'Cross' => label.style_cross
'Triangle Up' => label.style_triangleup
'Triangle Down' => label.style_triangledown
'Flag' => label.style_flag
'Arrow Up'=>label.style_arrowup
'Arrow Down'=>label.style_arrowdown
'Square'=>label.style_square
'Diamond'=>label.style_diamond
'None'=>label.style_none
TOPL_style_option = switch TOPL_style
'Circle' => label.style_circle
'X Cross' => label.style_xcross
'Cross' => label.style_cross
'Triangle Up' => label.style_triangleup
'Triangle Down' => label.style_triangledown
'Flag' => label.style_flag
'Arrow Up'=>label.style_arrowup
'Arrow Down'=>label.style_arrowdown
'Square'=>label.style_square
'Diamond'=>label.style_diamond
'None'=>label.style_none
// Calculate pivot bars
ph = ta.pivothigh(pivotbars, pivotbars)
pl = ta.pivotlow(pivotbars, pivotbars)
// label positioning
labpos = ta.atr(10)
// ---- Variables for line drawings ---- //
//first order pivot connections
var string lastcheck1 = na,var int ph1index = 0,var int pl1index = 0,var int lookback1 = 0,var float ph1val = 0,var float pl1val = 0,var line connect1 = na
// second order pivot connections
var string lastcheck2 = na,var int ph2index = 0,var int pl2index = 0,var float ph2val = 0,var float pl2val = 0,var line connect2 = na,var array<line> lines = array.new<line>(),var float[] p2low_val = array.new_float(),
var int[] p2low_index = array.new_int(),var float[] p2high_val = array.new_float(),var int[] p2high_index = array.new_int()
// third order pivot connections
var string lastcheck3 = na,var int ph3index = 0,var int pl3index = 0,var int lookback3 = 0,var float ph3val = 0,var float pl3val = 0,var line connect3 = na
// --- Variables for pivots --- //
//variables for first order pivot lows
var float[] lows = array.new_float(3,0),var int[] pl_loc = array.new_int(3,0),var float pl1 = 0,var float pl2 = 0,var float pl3 = 0
// variables for second order pivot lows
var float[] seclows = array.new_float(3,0),var int[] secpl_loc = array.new_int(3,0),var float secpl1 = 0,var float secpl2 = 0,var float secpl3 = 0,var label secondpivotlow = na,var int spl_loc = 0
//variables for third order pivots
var label thirdpivotlow = na,var int tpl_loc = 0
//variables for first order pivot highs
var float[] highs = array.new_float(3,0),var int[] ph_loc = array.new_int(3,0),var float ph1 = 0,var float ph2 = 0,var float ph3 = 0
//variables for second order pivot highs
var float[] sechighs = array.new_float(3,0),var int[] secph_loc = array.new_int(3,0),var float secph1 = 0,var float secph2 = 0,var float secph3 = 0,var label secondpivothigh = na,var int sph_loc = 0
//variable for thrid order pivot highs
var label thirdpivothigh = na,var int tph_loc = 0
//sequence arrays
var float[] seqhighs = array.new_float(),var float[] seqlows = array.new_float()
// uncommon situation variables
var float temp_index_h = 0,var float temp_val_h = 0,var float[] temp_h = array.new_float(),var float temp_index_l = 0,var float temp_val_l = 0,var float[] temp_l = array.new_float()
// Variables for color coding
var label swinghigh = na,var label swinglow = na,var float lowprice = na,var float hiprice = na,var string trend = na,upday = close > open,downday = close < open
// Table
var table swings = table.new(position.top_right,20,20,border_color=color.black), var float[] highstamp = array.new_float(), var float[] lowstamp = array.new_float(),
var int[] highstampindex= array.new_int(), var int[] lowstampindex = array.new_int(),var float distance = 0, var float[] seqswing = array.new_float()
// ----- PIVOT HIGHS ----- //
if not na(ph)
if showfirstpivots == true
label.new(x=bar_index - pivotbars, y = na(labpos) ? high[pivotbars] + syminfo.mintick*250 : high[pivotbars] + labpos,style=FOPH_style_option, size=FOP_size,color=FOPH_color)
hiprice := high[pivotbars]
// set price arrays
array.push(highs, high[pivotbars]),array.set(highs, 0, array.get(highs, 1)), array.set(highs, 1, array.get(highs, 2)),array.set(highs, 2, high[pivotbars])
// set index arrays
array.push(ph_loc,bar_index[pivotbars]), array.set(ph_loc, 0, array.get(ph_loc, 1)),array.set(ph_loc, 1, array.get(ph_loc, 2)),array.set(ph_loc, 2, bar_index[pivotbars])
//set comparison values
ph1 := array.get(highs,0),ph2 := array.get(highs,1), ph3 := array.get(highs,2)
// first order swing connections
if lastcheck1 == 'PL1' or na(lastcheck1)
if pl1index !=0 and high[pivotbars] > pl1val
lookback1 := bar_index - pl1index
connect1 := show1sttrends == true ? line.new(x1 = pl1index, y1 = low[lookback1], x2 = bar_index - pivotbars, y2 = high[pivotbars], color=FOPH_connect_color) : na
lastcheck1 := 'PH1'
ph1val := high[pivotbars]
ph1index := bar_index - pivotbars
if lastcheck1 == 'PH1' and high[pivotbars] > ph1val
line.delete(connect1)
lookback1 := bar_index - pl1index
connect1 := show1sttrends == true ? line.new(x1 = pl1index, y1 = low[lookback1], x2 = bar_index - pivotbars, y2 = high[pivotbars], color=FOPH_connect_color) : na
ph1val := high[pivotbars]
ph1index := bar_index - pivotbars
//second order pivot highs
if (ph1 < ph2 and ph2 > ph3) or (ph1 == ph2 and ph2 > ph3)
sph_loc := array.get(ph_loc,1)
if ph1 < ph2 and ph2 == ph3
sph_loc := array.get(ph_loc,2)
if ((ph1 < ph2 and ph2 > ph3) or (ph1 == ph2 and ph2 > ph3) or (ph1 < ph2 and ph2 == ph3 ))
//set price arrays
array.push(sechighs, high[bar_index - sph_loc]),array.set(sechighs,0,array.get(sechighs,1)),array.set(sechighs,1,array.get(sechighs,2)),array.set(sechighs, 2, high[bar_index - sph_loc])
//set index arrays
array.push(secph_loc, bar_index[bar_index - sph_loc]),array.set(secph_loc,0,array.get(secph_loc,1)),array.set(secph_loc,1,array.get(secph_loc,2)), array.set(secph_loc, 2, bar_index[bar_index - sph_loc])
// set comparison values
secph1 := array.get(sechighs,0),secph2 := array.get(sechighs,1), secph3 := array.get(sechighs,2)
// label
secondpivothigh := showsecondpivots == true ? label.new(x = bar_index - (bar_index - sph_loc), y= high[bar_index - sph_loc] + labpos[bar_index - sph_loc]*2 , style=SOPH_style_option, size=SOP_size, color=SOPH_color ) : na
// second order pivot high swing connections
if lastcheck2 == 'PL2'
if sph_loc > pl2index
if high[bar_index - sph_loc] > pl2val
connect2 := show2ndtrends == true ? line.new(x1 = pl2index, y1 = low[bar_index - pl2index], x2 = sph_loc, y2 = high[bar_index - sph_loc], color=SOPH_connect_color) : na, lines.push(connect2)
swinghigh := swingD == 'On plot' or swingD == 'Both' ? label.new(x=sph_loc,y=high[bar_index - sph_loc] + labpos*4, color=labelcolor, textcolor=PHtextcolor,
text = 'Time : ' + str.tostring(sph_loc - pl2index) + '\n' + 'Distance : ' +
str.tostring(((high[bar_index - sph_loc]-low[bar_index - pl2index])/low[bar_index - pl2index]),'#.##'+'%'), size=size.small):na
distance := ((high[bar_index - sph_loc]-low[bar_index - pl2index])/low[bar_index - pl2index])
array.push(highstamp,distance), array.push(highstampindex,sph_loc - pl2index),array.push(seqswing,1), array.push(seqswing,distance), array.push(seqswing,sph_loc - pl2index)
array.clear(seqhighs),array.push(seqhighs,sph_loc),array.push(seqhighs, high[bar_index - sph_loc])
ph2index := sph_loc,ph2val := high[bar_index - sph_loc]
array.push(p2high_index, ph2index),array.push(p2high_val, ph2val)
lastcheck2 := 'PH2'
if high[bar_index - sph_loc] < pl2val
array.push(seqhighs, sph_loc),array.push(seqhighs,high[bar_index - sph_loc])
if sph_loc < spl_loc
line.delete(array.get(lines, array.size(lines) -1)), array.remove(lines, array.size(lines) -1)
connect2 := show2ndtrends == true ? line.new(x1 = pl2index, y1 = low[bar_index - pl2index], x2 = sph_loc, y2 = high[bar_index - sph_loc], color=SOPH_connect_color) : na,lines.push(connect2)
connect2 := show2ndtrends == true ? line.new(x1 = sph_loc, y1 = high[bar_index - sph_loc], x2 = spl_loc, y2 = low[bar_index - spl_loc], color=SOPL_connect_color) : na,lines.push(connect2)
swinglow := swingD == 'On plot'or swingD == 'Both' ? label.new(x=spl_loc,y=low[bar_index - spl_loc] - labpos*4, color=labelcolor, textcolor=PLtextcolor,
text = 'Time : ' + str.tostring(spl_loc - ph2index) + '\n' + 'Distance : ' + str.tostring(((low[bar_index - spl_loc]-high[bar_index - ph2index])/high[bar_index - ph2index]),'#.##'+'%'), size=size.small):na
distance := low[bar_index - spl_loc]-high[bar_index - ph2index]/high[bar_index - ph2index]
array.push(lowstamp,distance), array.push(lowstampindex,spl_loc - ph2index),array.push(seqswing,0), array.push(seqswing,distance), array.push(seqswing,spl_loc - pl2index)
lastcheck2 := 'PL2'
pl2index := spl_loc, pl2val := low[bar_index - spl_loc]
array.clear(seqlows),array.push(seqlows,spl_loc),array.push(seqlows, low[bar_index - spl_loc])
if sph_loc < pl2index
if array.size(seqlows) > 2 and array.size(lines)!=0
if array.get(seqlows, array.size(seqlows) - 2) > sph_loc
array.pop(seqlows), array.pop(seqlows)
if array.size(seqlows) > 2
for i = 1 to array.size(seqlows) by 2
array.push(temp_l, array.get(seqlows,i))
temp_val_l := array.min(temp_l),temp_index_l := array.get(seqlows, (array.indexof(seqlows, temp_val_l)-1))
if array.size(seqlows) == 2
temp_val_l := array.get(seqlows,1),temp_index_l := array.get(seqlows,0)
if temp_val_l < high[bar_index - sph_loc]
line.delete(array.get(lines, array.size(lines) - 1)), array.remove(lines, array.size(lines) - 1), label.delete(swinglow),array.pop(lowstamp), array.pop(lowstampindex),
array.pop(seqswing),array.pop(seqswing),array.pop(seqswing)
connect2 := show2ndtrends == true ? line.new(x1 = ph2index, y1 = high[bar_index - ph2index], x2 = int(temp_index_l), y2 = low[bar_index - temp_index_l], color=SOPL_connect_color ) : na,lines.push(connect2)
swinglow := swingD == 'On plot'or swingD == 'Both' ? label.new(x=int(temp_index_l),y=low[bar_index - temp_index_l] - labpos*4, color=labelcolor, textcolor=PLtextcolor,
text = 'Time : ' + str.tostring(temp_index_l - ph2index) + '\n' + 'Distance : ' + str.tostring(((low[bar_index - temp_index_l]-high[bar_index - ph2index])/high[bar_index - ph2index]),'#.##'+'%'), size=size.small):na
distance := (low[bar_index - spl_loc]-high[bar_index - ph2index])/high[bar_index - ph2index]
array.push(lowstamp,distance), array.push(lowstampindex,bar_index - int(temp_index_l)),array.push(seqswing,0), array.push(seqswing,distance), array.push(seqswing,bar_index - int(temp_index_l))
connect2 := show2ndtrends == true ? line.new(x1 = int(temp_index_l), y1 = low[bar_index - temp_index_l], x2 = sph_loc, y2 = high[bar_index - sph_loc], color=SOPH_connect_color) : na,lines.push(connect2)
swinghigh := swingD == 'On plot'or swingD == 'Both' ? label.new(x=sph_loc,y=high[bar_index - sph_loc] + labpos*4, color=labelcolor, textcolor=PHtextcolor,
text = 'Time : ' + str.tostring(sph_loc - temp_index_l) + '\n' + 'Distance : ' + str.tostring(((high[bar_index - sph_loc]-low[bar_index - temp_index_l])/low[bar_index - temp_index_l]),'#.##'+'%'), size=size.small):na
distance := ((high[bar_index - sph_loc]-low[bar_index - pl2index])/low[bar_index - pl2index])
array.push(highstamp,distance), array.push(highstampindex,sph_loc - int(temp_index_l)),array.push(seqswing,1), array.push(seqswing,distance), array.push(seqswing,sph_loc - int(temp_index_l))
connect2 := show2ndtrends == true ? line.new(x1 = sph_loc, y1 = high[bar_index -sph_loc], x2 = spl_loc, y2 = low[bar_index - spl_loc], color=SOPL_connect_color) : na,lines.push(connect2)
swinglow := swingD == 'On plot'or swingD == 'Both' ? label.new(x=spl_loc,y=low[bar_index - spl_loc] - labpos*4, color=labelcolor, textcolor=PLtextcolor, text = 'Time : ' + str.tostring(spl_loc - sph_loc) + '\n' + 'Distance : ' +
str.tostring(((low[bar_index - spl_loc]-high[bar_index - sph_loc])/high[bar_index - ph2index]),'#.##'+'%'), size=size.small):na
distance := (low[bar_index - spl_loc]-high[bar_index - ph2index])/high[bar_index - ph2index]
array.push(lowstamp,distance), array.push(lowstampindex,spl_loc - sph_loc),array.push(seqswing,0), array.push(seqswing,distance), array.push(seqswing,spl_loc - sph_loc)
array.clear(seqlows), array.push(seqlows,spl_loc),array.push(seqlows, low[bar_index - spl_loc])
ph2index := sph_loc,ph2val := high[ bar_index - sph_loc]
array.push(p2high_index, ph2index),array.push(p2high_val, ph2val),array.clear(seqhighs),array.push(seqhighs, sph_loc),array.push(seqhighs, high[bar_index - sph_loc]),array.clear(temp_l)
lastcheck2 := 'PL2',temp_val_l := na,temp_index_l := na
if array.size(seqlows) == 2 // Could be problems here
if high[bar_index - sph_loc] > ph2val
line.delete(array.get(lines, array.size(lines) -1)), array.remove(lines, array.size(lines) - 1)
line.delete(array.get(lines, array.size(lines) -1)), array.remove(lines, array.size(lines) - 1),label.delete(swinghigh),array.pop(highstamp), array.pop(highstampindex),
array.pop(seqswing),array.pop(seqswing),array.pop(seqswing),array.pop(seqswing),array.pop(seqswing),array.pop(seqswing)
connect2 := show2ndtrends == true ? line.new(x1 = array.get(p2low_index,array.size(p2low_index)-2),
y1 = low[bar_index - array.get(p2low_index,array.size(p2low_index)-2)], x2 = sph_loc, y2 = high[bar_index - sph_loc], color=SOPH_connect_color) : na,lines.push(connect2)
swinghigh := swingD == 'On plot'or swingD == 'Both' ? label.new(x=sph_loc,y=high[bar_index - sph_loc] + labpos*4, color=labelcolor, textcolor=PHtextcolor,
text = 'Time : ' + str.tostring(sph_loc - array.get(p2low_index,array.size(p2low_index)-2)) + '\n' + 'Distance : ' +
str.tostring(((high[bar_index - sph_loc]-low[bar_index - array.get(p2low_index,array.size(p2low_index)-2)])/low[bar_index - array.get(p2low_index,array.size(p2low_index)-2)]),'#.##'+'%'), size=size.small):na
distance := (high[bar_index - sph_loc]-low[bar_index - array.get(p2low_index,array.size(p2low_index)-2)])/low[bar_index - array.get(p2low_index,array.size(p2low_index)-2)]
// distance := (high[bar_index - sph_loc]-low[bar_index - pl2index])/low[bar_index - pl2index]
array.push(highstamp,distance), array.push(highstampindex,sph_loc - array.get(p2low_index,array.size(p2low_index)-2)),array.push(seqswing,1), array.push(seqswing,distance),
array.push(seqswing,sph_loc - array.get(p2low_index,array.size(p2low_index)-2))
connect2 := show2ndtrends == true ? line.new(x1 = sph_loc, y1 = high[bar_index - sph_loc], x2 = spl_loc, y2 = low[bar_index - spl_loc], color=SOPL_connect_color ) : na,lines.push(connect2)
swinglow := swingD == 'On plot'or swingD == 'Both' ? label.new(x=spl_loc,y=low[bar_index - spl_loc] - labpos*4, color=labelcolor, textcolor=PLtextcolor,
text = 'Time : ' + str.tostring(spl_loc - sph_loc) + '\n' + 'Distance : ' + str.tostring(((low[bar_index - spl_loc]-high[bar_index - sph_loc])/high[bar_index - ph2index]),'#.##'+'%'), size=size.small):na
distance := (low[bar_index - spl_loc]-high[bar_index - ph2index])/high[bar_index - ph2index]
array.push(lowstamp,distance), array.push(lowstampindex,spl_loc - sph_loc),array.push(seqswing,0), array.push(seqswing,distance), array.push(seqswing,spl_loc - sph_loc)
ph2index := sph_loc,ph2val := high[bar_index - sph_loc]
array.remove(p2high_index,array.size(p2high_index)-1),array.remove(p2high_val,array.size(p2high_val)-1),array.push(p2high_index, ph2index),array.push(p2high_val, ph2val)
if lastcheck2 == 'PH2'
if sph_loc > ph2index
if high[bar_index - sph_loc] < ph2val
array.push(seqhighs, sph_loc),array.push(seqhighs,high[bar_index - sph_loc])
if high[bar_index - sph_loc] >= ph2val
if array.size(lines)!=0
line.delete(array.get(lines, array.size(lines) -1)), array.remove(lines, array.size(lines) - 1),label.delete(swinghigh),array.pop(highstamp), array.pop(highstampindex),
array.pop(seqswing),array.pop(seqswing),array.pop(seqswing)
connect2 := show2ndtrends == true ? line.new(x1 = pl2index, y1 = low[bar_index - pl2index], x2 = sph_loc, y2 = high[bar_index - sph_loc], color=SOPH_connect_color) : na,lines.push(connect2)
swinghigh := swingD == 'On plot'or swingD == 'Both' ? label.new(x=sph_loc,y=high[bar_index - sph_loc] + labpos*4, color=labelcolor, textcolor=PHtextcolor,
text = 'Time : ' + str.tostring(sph_loc - pl2index) + '\n' + 'Distance : ' + str.tostring(((high[bar_index - sph_loc]-low[bar_index - pl2index])/low[bar_index - pl2index]),'#.##'+'%'), size=size.small):na
distance := ((high[bar_index - sph_loc]-low[bar_index - pl2index])/low[bar_index - pl2index])
array.push(highstamp,distance),array.push(highstampindex,sph_loc - pl2index),array.push(seqswing,1), array.push(seqswing,distance), array.push(seqswing,sph_loc - pl2index)
array.push(seqhighs,sph_loc), array.push(seqhighs, high[bar_index - sph_loc])
ph2index := sph_loc,ph2val := high[bar_index - sph_loc]
array.remove(p2high_index,array.size(p2high_index)-1),array.remove(p2high_val,array.size(p2high_val)-1), array.push(p2high_index, ph2index), array.push(p2high_val, ph2val)
if na(lastcheck2)
ph2index := sph_loc, ph2val := high[bar_index - sph_loc]
array.push(seqhighs, sph_loc),array.push(seqhighs,high[bar_index - sph_loc]), array.push(p2high_index, ph2index), array.push(p2high_val, ph2val)
lastcheck2 := 'PH2'
// third order pivot highs
if secph1 < secph2 and secph2 > secph3 or secph1 == secph2 and secph2 > secph3
tph_loc := array.get(secph_loc,1)
if secph1 < secph2 and secph2 == secph3
tph_loc :=array.get(secph_loc,2)
if (secph1 < secph2 and secph2 > secph3 or secph1 == secph2 and secph2 > secph3) or (secph1 < secph2 and secph2 == secph3)
thirdpivothigh := showthirdpivots == true ? label.new(x = bar_index - (bar_index - tph_loc), y= high[bar_index - tph_loc] + labpos[bar_index - tph_loc]*3 , style=TOPH_style_option,size=TOP_size,
color=TOPH_color) : na
//code for connecting third order swings
if lastcheck3 == 'PL3'
if tph_loc > pl3index and high[bar_index - tph_loc] > pl3val
connect3 := show3rdtrends == true ? line.new(x1 = pl3index, y1 = low[bar_index - pl3index], x2 = tph_loc, y2 = high[bar_index - tph_loc], color=TOPH_connect_color) : na
ph3index := tph_loc, ph3val := high[bar_index - tph_loc]
lastcheck3 := "PH3"
if lastcheck3 == 'PH3' and high[bar_index - tph_loc] > ph3val
line.delete(connect3),connect3 := show3rdtrends == true ? line.new(x1 = pl3index, y1 = low[bar_index - pl3index], x2 = tph_loc, y2 =high[bar_index - tph_loc], color=TOPH_connect_color) : na
ph3index := tph_loc, ph3val := high[bar_index - tph_loc]
if na(lastcheck3)
ph3index := tph_loc, ph3val := high[bar_index - tph_loc]
lastcheck3 := 'PH3'
// ----- PIVOT LOWS ----- //
if not na(pl)
if showfirstpivots == true
label.new(x=bar_index - pivotbars,y= na(labpos) ? low[pivotbars] - syminfo.mintick*250 : low[pivotbars] - labpos, style=FOPH_style_option, size=FOP_size,color=FOPL_color)
lowprice := low[pivotbars]
//set price arrays
array.push(lows, low[pivotbars]),array.set(lows, 0, array.get(lows, 1)),array.set(lows, 1, array.get(lows, 2)),array.set(lows, 2, low[pivotbars])
// set index arrays
array.push(pl_loc,bar_index[pivotbars]),array.set(pl_loc, 0, array.get(pl_loc, 1)),array.set(pl_loc, 1, array.get(pl_loc, 2)), array.set(pl_loc, 2, bar_index[pivotbars])
// set comparison values
pl1 := array.get(lows,0),pl2 := array.get(lows,1),pl3 := array.get(lows,2)
//first order swing connections
if lastcheck1 == 'PH1' or na(lastcheck1)
if ph1index !=0 and low[pivotbars] < ph1val
lookback1 := bar_index - ph1index
connect1 := show1sttrends == true ? line.new(x1 = ph1index, y1 = high[lookback1],x2= bar_index-pivotbars, y2=low[pivotbars], color=FOPL_connect_color ) : na
lastcheck1 := 'PL1'
pl1val := low[pivotbars]
pl1index := bar_index - pivotbars
if lastcheck1 == 'PL1' and low[pivotbars] < pl1val
line.delete(connect1)
lookback1 := bar_index - ph1index
connect1 := show1sttrends == true ? line.new(x1 = ph1index, y1 = high[lookback1],x2= bar_index-pivotbars, y2=low[pivotbars], color=FOPL_connect_color ) : na
pl1val := low[pivotbars]
pl1index := bar_index - pivotbars
//second order pivot lows
if (pl1 > pl2 and pl2 < pl3) or (pl1 == pl2 and pl2 < pl3)
spl_loc := array.get(pl_loc,1)
if pl1 > pl2 and pl2 == pl3
spl_loc := array.get(pl_loc,2)
if ((pl1 > pl2 and pl2 < pl3) or (pl1 == pl2 and pl2 < pl3) ) or (pl1 > pl2 and pl2 == pl3)
//set price arrays
array.push(seclows, low[bar_index - spl_loc]),array.set(seclows,0,array.get(seclows,1)),array.set(seclows,1,array.get(seclows,2)),array.set(seclows, 2, low[bar_index - spl_loc])
//set index arrays
array.push(secpl_loc, bar_index[bar_index - spl_loc]),array.set(secpl_loc,0,array.get(secpl_loc,1)),array.set(secpl_loc,1,array.get(secpl_loc,2)),array.set(secpl_loc, 2, bar_index[bar_index - spl_loc])
//set comparison values
secpl1 := array.get(seclows,0),secpl2 := array.get(seclows,1),secpl3 := array.get(seclows,2)
// label
secondpivotlow := showsecondpivots == true ? label.new(x = bar_index - (bar_index - spl_loc), y= low[bar_index - spl_loc] - labpos[(bar_index - spl_loc)]*2 , style=SOPL_style_option, size=SOP_size, color=SOPL_color) : na
// second order pivot low swing connections
if lastcheck2 == 'PH2'
if spl_loc > ph2index
if low[bar_index - spl_loc] < ph2val
connect2 := show2ndtrends == true ? line.new(x1 = ph2index, y1 = high[bar_index - ph2index], x2 = spl_loc, y2 = low[bar_index - spl_loc], color=SOPL_connect_color) : na,lines.push(connect2)
swinglow := swingD == 'On plot'or swingD == 'Both' ? label.new(x=spl_loc,y=low[bar_index - spl_loc] - labpos*4, color=labelcolor, textcolor=PLtextcolor,
text = 'Time : ' + str.tostring(spl_loc - ph2index) + '\n' + 'Distance : ' + str.tostring(((low[bar_index - spl_loc]-high[bar_index - ph2index])/high[bar_index - ph2index]),'#.##'+'%'), size=size.small):na
distance := (low[bar_index - spl_loc]-high[bar_index - ph2index])/high[bar_index - ph2index]
array.push(lowstamp,distance),array.push(lowstampindex,spl_loc - ph2index), array.push(seqswing,0), array.push(seqswing,distance), array.push(seqswing,spl_loc - ph2index)
array.clear(seqlows),array.push(seqlows,spl_loc),array.push(seqlows, low[bar_index - spl_loc])
pl2index := spl_loc,pl2val := low[bar_index - spl_loc]
array.push(p2low_index, pl2index),array.push(p2low_val, pl2val)
lastcheck2 := 'PL2'
if low[bar_index - spl_loc] > ph2val
array.push(seqlows, spl_loc),array.push(seqlows,low[bar_index - spl_loc])
if spl_loc < sph_loc
connect2 := show2ndtrends == true ? line.new(x1 = spl_loc, y1 = low[bar_index - spl_loc], x2 = sph_loc, y2 = high[bar_index - sph_loc], color=SOPH_connect_color) : na,lines.push(connect2)
swinghigh := swingD == 'On plot'or swingD == 'Both' ? label.new(x=sph_loc,y=high[bar_index - sph_loc] + labpos*4, color=labelcolor, textcolor=PHtextcolor,
text = 'Time : ' + str.tostring(sph_loc - pl2index) + '\n' + 'Distance : ' + str.tostring(((high[bar_index - sph_loc]-low[bar_index - pl2index])/low[bar_index - pl2index]),'#.##'+'%'), size=size.small):na
distance := ((high[bar_index - sph_loc]-low[bar_index - pl2index])/low[bar_index - pl2index])
array.push(highstamp,distance),array.push(highstampindex,sph_loc - pl2index),array.push(seqswing,1), array.push(seqswing,distance), array.push(seqswing,sph_loc - pl2index)
ph2index := sph_loc,ph2val := high[bar_index - sph_loc]
lastcheck2 := 'PH2'
array.clear(seqhighs),array.push(seqhighs,sph_loc),array.push(seqhighs, high[bar_index - sph_loc])
if spl_loc < ph2index
if array.size(seqhighs) > 2 and array.size(lines)!=0
if array.get(seqhighs, array.size(seqhighs) - 2) > spl_loc
array.pop(seqhighs), array.pop(seqhighs)
if array.size(seqhighs) > 2
for i = 1 to array.size(seqhighs) by 2
array.push(temp_h, array.get(seqhighs,i))
temp_val_h := array.max(temp_h),temp_index_h := array.get(seqhighs, (array.indexof(seqhighs, temp_val_h)-1))
if array.size(seqhighs) == 2
temp_val_h := array.get(seqhighs,1),temp_index_h := array.get(seqhighs,0)
if temp_val_h > low[bar_index - spl_loc]
line.delete(array.get(lines, array.size(lines) -1)), array.remove(lines, array.size(lines) - 1), array.pop(highstamp), array.pop(highstampindex), label.delete(swinghigh),
array.pop(seqswing),array.pop(seqswing),array.pop(seqswing)
connect2 := show2ndtrends == true ? line.new(x1 = pl2index, y1 = low[bar_index - pl2index], x2 = int(temp_index_h), y2 = high[bar_index - temp_index_h], color=SOPH_connect_color ) : na,lines.push(connect2)
swinghigh := swingD == 'On plot'or swingD == 'Both' ? label.new(x=int(temp_index_h),y=high[bar_index - temp_index_h] + labpos*4, color=labelcolor, textcolor=PHtextcolor,
text = 'Time : ' + str.tostring(temp_index_h - pl2index) + '\n' + 'Distance : ' + str.tostring(((high[bar_index - temp_index_h]-low[bar_index - pl2index])/low[bar_index - pl2index]),'#.##'+'%'), size=size.small):na
distance := ((high[bar_index - temp_index_h]-low[bar_index - pl2index])/low[bar_index - pl2index])
array.push(highstamp,distance),array.push(highstampindex,int(temp_index_h) - pl2index),array.push(seqswing,1), array.push(seqswing,distance), array.push(seqswing,int(temp_index_h) - pl2index)
connect2 := show2ndtrends == true ? line.new(x1 = int(temp_index_h), y1 = high[bar_index - temp_index_h], x2 = spl_loc, y2 = low[bar_index - spl_loc], color=SOPL_connect_color) : na,lines.push(connect2)
swinglow := swingD == 'On plot'or swingD == 'Both' ? label.new(x=spl_loc,y=low[bar_index - spl_loc] - labpos*4, color=labelcolor, textcolor=PHtextcolor,
text = 'Time : ' + str.tostring(spl_loc - temp_index_h) + '\n' + 'Distance : ' + str.tostring(((low[bar_index - spl_loc]-high[bar_index - temp_index_h])/high[bar_index - temp_index_h]),'#.##'+'%'), size=size.small):na
distance := (low[bar_index - spl_loc]-high[bar_index - ph2index])/high[bar_index - ph2index]
array.push(lowstamp,distance),array.push(lowstampindex,spl_loc - int(temp_index_h)),array.push(seqswing,0), array.push(seqswing,distance), array.push(seqswing,spl_loc - int(temp_index_h))
connect2 := show2ndtrends == true ? line.new(x1 = spl_loc, y1 = low[bar_index -spl_loc], x2 = sph_loc, y2 = high[bar_index - sph_loc], color=SOPH_connect_color) : na,lines.push(connect2)
swinghigh := swingD == 'On plot'or swingD == 'Both' ? label.new(x=sph_loc,y=high[bar_index - sph_loc] + labpos*4, color=labelcolor, textcolor=PHtextcolor,
text = 'Time : ' + str.tostring(sph_loc - spl_loc) + '\n' + 'Distance : ' + str.tostring(((high[bar_index - sph_loc]-low[bar_index - spl_loc])/low[bar_index - pl2index]),'#.##'+'%'), size=size.small):na
distance := ((high[bar_index - sph_loc]-low[bar_index - spl_loc])/low[bar_index - spl_loc])
array.push(highstamp,distance), array.push(highstampindex,sph_loc - spl_loc),array.push(seqswing,1), array.push(seqswing,distance), array.push(seqswing,sph_loc - spl_loc)
array.clear(seqhighs),array.push(seqhighs, sph_loc),array.push(seqhighs, high[bar_index - sph_loc])
pl2index := spl_loc,pl2val := low[bar_index - spl_loc]
array.push(p2low_index, pl2index),array.push(p2low_val, pl2val),array.clear(seqlows),array.push(seqlows, spl_loc),array.push(seqlows, low[bar_index - spl_loc]),array.clear(temp_h)
lastcheck2 := 'PH2'
temp_val_h := na,temp_index_h := na
if array.size(seqhighs) == 2
if low[bar_index - spl_loc] < pl2val
line.delete(array.get(lines, array.size(lines) -1)), array.remove(lines, array.size(lines) - 1)
line.delete(array.get(lines, array.size(lines) -1)), array.remove(lines, array.size(lines) - 1),label.delete(swinglow),array.pop(lowstamp), array.pop(lowstampindex),label.delete(swinghigh),array.pop(highstamp),
array.pop(highstampindex),array.pop(seqswing),array.pop(seqswing),array.pop(seqswing),array.pop(seqswing),array.pop(seqswing),array.pop(seqswing)
connect2 := show2ndtrends == true ? line.new(x1 = array.get(p2high_index,array.size(p2high_index)-2),
y1 = high[bar_index - array.get(p2high_index,array.size(p2high_index)-2)], x2 = spl_loc, y2 = low[bar_index - spl_loc], color=SOPL_connect_color) : na,lines.push(connect2)
swinglow := swingD == 'On plot'or swingD == 'Both' ? label.new(x=spl_loc,y=low[bar_index - spl_loc] - labpos*4, color=labelcolor, textcolor=PLtextcolor,
text = 'Time : ' + str.tostring(spl_loc - array.get(p2high_index,array.size(p2high_index)-2)) + '\n' + 'Distance : ' +
str.tostring(((low[bar_index - spl_loc]-high[bar_index - array.get(p2high_index,array.size(p2high_index)-2)])/high[bar_index - array.get(p2high_index,array.size(p2high_index)-2)]),'#.##'+'%'), size=size.small):na
distance := (low[bar_index - spl_loc]-high[bar_index - array.get(p2high_index,array.size(p2high_index)-2)])/high[bar_index - array.get(p2high_index,array.size(p2high_index)-2)]
array.push(lowstamp,distance), array.push(lowstampindex,spl_loc - array.get(p2high_index,array.size(p2high_index)-2)),
array.push(seqswing,0), array.push(seqswing,distance), array.push(seqswing,spl_loc - array.get(p2high_index,array.size(p2high_index)-2))
connect2 := show2ndtrends == true ? line.new(x1 = spl_loc, y1 = low[bar_index - spl_loc], x2 = sph_loc, y2 = high[bar_index - sph_loc], color=SOPH_connect_color ) : na,lines.push(connect2)
swinghigh := swingD == 'On plot'or swingD == 'Both' ? label.new(x=sph_loc,y=high[bar_index - sph_loc] + labpos*4, color=labelcolor, textcolor=PHtextcolor,
text = 'Time : ' + str.tostring(sph_loc - spl_loc) + '\n' + 'Distance : ' + str.tostring(((high[bar_index - sph_loc]-low[bar_index - spl_loc])/low[bar_index - spl_loc]),'#.##'+'%'), size=size.small):na
distance := ((high[bar_index - sph_loc]-low[bar_index - spl_loc])/low[bar_index - spl_loc])
array.push(highstamp,distance), array.push(highstampindex,sph_loc - spl_loc),array.push(seqswing,1), array.push(seqswing,distance), array.push(seqswing,sph_loc - spl_loc)
pl2index := spl_loc,pl2val := low[bar_index - spl_loc]
array.remove(p2low_index,array.size(p2low_index)-1),array.remove(p2low_val,array.size(p2low_val)-1),array.push(p2low_index, pl2index),array.push(p2low_val, pl2val)
if lastcheck2 == 'PL2'
if spl_loc > pl2index
if low[bar_index - spl_loc] > pl2val
array.push(seqlows, spl_loc),array.push(seqlows,low[bar_index - spl_loc])
if low[bar_index - spl_loc] <= pl2val
if array.size(lines)!=0
line.delete(array.get(lines, array.size(lines) -1)), array.remove(lines, array.size(lines) - 1),label.delete(swinglow),array.pop(lowstamp),array.pop(lowstampindex),
array.pop(seqswing),array.pop(seqswing),array.pop(seqswing)
connect2 := show2ndtrends == true ? line.new(x1 = ph2index, y1 = high[bar_index - ph2index], x2 = spl_loc, y2 = low[bar_index - spl_loc], color=SOPL_connect_color) : na,lines.push(connect2)
swinglow := swingD == 'On plot'or swingD == 'Both' ? label.new(x=spl_loc,y=low[bar_index - spl_loc] - labpos*4, color=labelcolor, textcolor=PLtextcolor,
text = 'Time : ' + str.tostring(spl_loc - ph2index) + '\n' + 'Distance : ' + str.tostring(((low[bar_index - spl_loc]-high[bar_index - ph2index])/high[bar_index - ph2index]),'#.##'+'%'), size=size.small):na
distance := (low[bar_index - spl_loc]-high[bar_index - ph2index])/high[bar_index - ph2index]
array.push(lowstamp,distance),array.push(lowstampindex,spl_loc - ph2index),array.push(seqswing,0), array.push(seqswing,distance), array.push(seqswing,spl_loc - ph2index)
array.push(seqlows,spl_loc),array.push(seqlows, low[bar_index - spl_loc])
pl2index := spl_loc,pl2val := low[bar_index - spl_loc]
array.remove(p2low_index,array.size(p2low_index)-1),array.remove(p2low_val,array.size(p2low_val)-1),array.push(p2low_index, pl2index),array.push(p2low_val, pl2val)
if sph_loc > pl2index // Problem here
connect2 := show2ndtrends == true ? line.new(x1 = spl_loc, y1 = low[bar_index - spl_loc], x2 = sph_loc, y2 = high[bar_index - sph_loc], color=color.blue) : na,lines.push(connect2)
array.clear(seqhighs),array.push(seqhighs,sph_loc),array.push(seqhighs, high[bar_index - sph_loc])
ph2index := sph_loc,ph2val := high[bar_index - sph_loc]
array.push(p2high_index, ph2index),array.push(p2high_val, ph2val)
lastcheck2 := 'PH2'
if na(lastcheck2)
pl2index := spl_loc,pl2val := low[bar_index - spl_loc]
array.push(seqlows, spl_loc),array.push(seqlows,low[bar_index - spl_loc]),array.push(p2low_index, pl2index),array.push(p2low_val, pl2val)
lastcheck2 := 'PL2'
// third order pivot low
if secpl1 > secpl2 and secpl2 < secpl3 or secpl1 == secpl2 and secpl2 < secpl3
tpl_loc := array.get(secpl_loc,1)
if secpl1 > secpl2 and secpl2 == secpl3
tpl_loc :=array.get(secpl_loc,2)
if (secpl1 > secpl2 and secpl2 < secpl3 or secpl1 == secpl2 and secpl2 < secpl3) or (secpl1 > secpl2 and secpl2 == secpl3)
thirdpivotlow := showthirdpivots == true ?
label.new(x = bar_index - (bar_index - tpl_loc), y= low[(bar_index - tpl_loc)] - labpos[(bar_index - tpl_loc)]*3, style=TOPL_style_option,size=TOP_size,color=TOPL_color) : na
//code for connecting third order swings
if lastcheck3 == 'PH3'
if tpl_loc > ph3index and low[bar_index - tpl_loc] < ph3val
connect3 := show3rdtrends == true ? line.new(x1 = ph3index, y1 = high[bar_index - ph3index], x2 = tpl_loc, y2 = low[bar_index - tpl_loc], color=TOPL_connect_color) : na
pl3index := tpl_loc, pl3val := low[bar_index - tpl_loc]
lastcheck3 := 'PL3'
if lastcheck3 == 'PL3' and low[bar_index - tpl_loc] < pl3val
line.delete(connect3), connect3 := show3rdtrends == true ? line.new(x1 = ph3index, y1 = high[bar_index - ph3index], x2 = tpl_loc, y2 = low[bar_index - tpl_loc], color=TOPL_connect_color) : na
pl3index := tpl_loc, pl3val := low[bar_index - tpl_loc]
if na(lastcheck3)
pl3index := tpl_loc, pl3val := low[bar_index - tpl_loc]
lastcheck3 := 'PL3'
// color coding
if high > hiprice
trend := 'up'
if low < lowprice
trend :='down'
barcolor(colorbars == true ?trend=='up'? upday ? uptrendup:uptrenddown : trend == 'down'? upday ? downtrendup:downtrenddown: color.gray : na)
if barstate.islast
if array.size(highstamp) >= 3 and array.size(lowstamp) >=3 and swingD == 'In table' or swingD == 'Both'
table.cell(swings,1,0,bgcolor=labelcolor, text_color=color.rgb(7, 77, 7), text=' Pivot Highs', text_size=size.small)
table.cell(swings,1,1,bgcolor = labelcolor, text_color = PHtextcolor, text='Duration',text_valign = text.align_center, text_size = size.small)
table.cell(swings,2,1,bgcolor = labelcolor, text_color = PHtextcolor, text='Distance',text_valign = text.align_center, text_size = size.small)
// table.cell(swings,3,1,bgcolor = color.white, text_color = color.green, text='Sequence',text_valign = text.align_center, text_size = size.small)
table.cell(swings,1,2, bgcolor=labelcolor, text_color=PHtextcolor, text=str.tostring(array.get(highstampindex,array.size(highstampindex)-3)))
table.cell(swings,2,2, bgcolor=labelcolor, text_color=PHtextcolor, text=str.tostring(array.get(highstamp,array.size(highstamp)-3),'#.##'+ '%'))
// table.cell(swings,3,2, bgcolor=color.white, text_color=color.green, text = )
table.cell(swings,1,3, bgcolor=labelcolor, text_color=PHtextcolor, text=str.tostring(array.get(highstampindex,array.size(highstampindex)-2)))
table.cell(swings,2,3, bgcolor=labelcolor, text_color=PHtextcolor, text=str.tostring(array.get(highstamp,array.size(highstamp)-2),'#.##'+ '%'))
table.cell(swings,1,4, bgcolor=labelcolor, text_color=PHtextcolor, text=str.tostring(array.get(highstampindex,array.size(highstampindex)-1)))
table.cell(swings,2,4, bgcolor=labelcolor, text_color=PHtextcolor, text=str.tostring(array.get(highstamp,array.size(highstamp)-1),'#.##'+ '%'))
table.cell(swings,1,5,bgcolor=labelcolor, text_color=color.rgb(134, 38, 52), text=' Pivot Lows', text_size=size.small)
table.cell(swings,1,6,bgcolor = labelcolor, text_color = PLtextcolor, text='Duration',text_valign = text.align_center, text_size = size.small)
table.cell(swings,2,6,bgcolor = labelcolor, text_color = PLtextcolor, text='Distance',text_valign = text.align_center, text_size = size.small)
table.cell(swings,1,7, bgcolor=labelcolor, text_color=PLtextcolor, text=str.tostring(array.get(lowstampindex,array.size(lowstampindex)-3)))
table.cell(swings,2,7, bgcolor=labelcolor, text_color=PLtextcolor, text=str.tostring(array.get(lowstamp,array.size(lowstamp)-3),'#.##'+ '%'))
table.cell(swings,1,8, bgcolor=labelcolor, text_color=PLtextcolor, text=str.tostring(array.get(lowstampindex,array.size(lowstampindex)-2)))
table.cell(swings,2,8, bgcolor=labelcolor, text_color=PLtextcolor, text=str.tostring(array.get(lowstamp,array.size(lowstamp)-2),'#.##'+ '%'))
table.cell(swings,1,9, bgcolor=labelcolor, text_color=PLtextcolor, text=str.tostring(array.get(lowstampindex,array.size(lowstampindex)-1)))
table.cell(swings,2,9, bgcolor=labelcolor, text_color=PLtextcolor, text=str.tostring(array.get(lowstamp,array.size(lowstamp)-1),'#.##'+ '%'))
table.cell(swings,1,10, bgcolor=labelcolor, text_color = color.rgb(33, 184, 243), text = 'Sequence Swings', text_size = size.small, text_halign = text.align_right )
table.cell(swings,1,11, bgcolor=labelcolor, text_color=color.rgb(33, 184, 243), text = 'Duration', text_size = size.small)
table.cell(swings,2,11, bgcolor=labelcolor, text_color=color.rgb(33, 184, 243), text = 'Distance', text_size = size.small)
table.cell(swings,1,13, bgcolor=labelcolor,text_color= array.get(seqswing,array.size(seqswing)-15) == 1 ? PHtextcolor:PLtextcolor, text=str.tostring(array.get(seqswing,array.size(seqswing)-13)))
table.cell(swings,2,13, bgcolor=labelcolor,text_color= array.get(seqswing,array.size(seqswing)-15) == 1 ? PHtextcolor:PLtextcolor, text=str.tostring(array.get(seqswing,array.size(seqswing)-14),'#.##'+'%'))
table.cell(swings,1,14, bgcolor=labelcolor,text_color= array.get(seqswing,array.size(seqswing)-12) == 1 ? PHtextcolor:PLtextcolor, text=str.tostring(array.get(seqswing,array.size(seqswing)-10)))
table.cell(swings,2,14, bgcolor=labelcolor,text_color= array.get(seqswing,array.size(seqswing)-12) == 1 ? PHtextcolor:PLtextcolor, text=str.tostring(array.get(seqswing,array.size(seqswing)-11),'#.##'+'%'))
table.cell(swings,1,15, bgcolor=labelcolor,text_color= array.get(seqswing,array.size(seqswing)-9) == 1 ? PHtextcolor:PLtextcolor, text=str.tostring(array.get(seqswing,array.size(seqswing)-7)))
table.cell(swings,2,15, bgcolor=labelcolor,text_color= array.get(seqswing,array.size(seqswing)-9) == 1 ? PHtextcolor:PLtextcolor, text=str.tostring(array.get(seqswing,array.size(seqswing)-8),'#.##'+'%'))
table.cell(swings,1,16, bgcolor=labelcolor,text_color= array.get(seqswing,array.size(seqswing)-6) == 1 ? PHtextcolor:PLtextcolor, text=str.tostring(array.get(seqswing,array.size(seqswing)-4)))
table.cell(swings,2,16, bgcolor=labelcolor,text_color= array.get(seqswing,array.size(seqswing)-6) == 1 ? PHtextcolor:PLtextcolor, text=str.tostring(array.get(seqswing,array.size(seqswing)-5),'#.##'+'%'))
table.cell(swings,1,17, bgcolor=labelcolor,text_color= array.get(seqswing,array.size(seqswing)-3) == 1 ? PHtextcolor:PLtextcolor, text=str.tostring(array.get(seqswing,array.size(seqswing)-1)))
table.cell(swings,2,17, bgcolor=labelcolor,text_color= array.get(seqswing,array.size(seqswing)-3) == 1 ? PHtextcolor:PLtextcolor, text=str.tostring(array.get(seqswing,array.size(seqswing)-2),'#.##'+'%'))
//////////
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dg_factor
//@version=5
string tt = "The script does not contain any security calls.
If there are not enough bars on the chart, the result may not be displayed. You can try higher timeframes."
sh_monday = input.bool(false, "Monday ")
sh_daily = input.bool(false, "Daily ")
sh_weekly = input.bool(true, "Weekly ", tooltip=tt)
sh_monthly = input.bool(false, "Monthly ", tooltip=tt)
sh_ln = input.bool(true, "Line ", group="DISPLAY")
sh_tx = input.bool(true, "Text ", group="DISPLAY")
sh_pr = input.bool(true, "Price ", group="DISPLAY")
col_1 = input.color(#2962ff, "Color", inline="c", group="DISPLAY")
col_2 = input.color(#00bb00, "", inline="c", group="DISPLAY")
col_3 = input.color(#fb0000, "", inline="c", group="DISPLAY")
col_4 = input.color(#9C27B0, "", inline="c", group="DISPLAY")
p(x, y, c, t) =>
var line ln = na, line.delete(ln)
var label lb = na, label.delete(lb)
ln := sh_ln ? line.new(x, y, time, y, xloc.bar_time, color=c) : na
t1 = sh_tx ? t : na, t2 = sh_pr ? " [" + str.tostring(y, format.mintick) + "]" : na
lb := label.new(time, y, t1 + t2, xloc.bar_time, yloc.price,
#00000000, label.style_label_left, c, size.normal, text.align_right)
//
f(x, t) =>
s = x and not x[1]
f = not x and x[1]
o = ta.valuewhen(s, open, 0)
var h1 = 0.0, h1 := fixnan(not x ? na : s or f ? high : math.max(high, h1))
var l1 = 0.0, l1 := fixnan(not x ? na : s or f ? low : math.min(low, l1))
var h2 = 0.0, h2 := s ? high : math.max(high, h2)
var l2 = 0.0, l2 := s ? low : math.min(low, l2)
h = t == "Monday" ? h1 : h2
l = t == "Monday" ? l1 : l2
m = math.avg(h, l)
ot = ta.valuewhen(s, time, 0)
ht = ta.valuewhen(h==high, time, 0)
lt = ta.valuewhen(l==low, time, 0)
mt = math.max(ht, lt)
p(ot, o, col_1, sh_tx ? t + " Açılış" : na)
p(ht, h, col_2, sh_tx ? t + " Yüksek" : na)
p(lt, l, col_3, sh_tx ? t + " Düşük" : na)
p(mt, m, col_4, sh_tx ? t + " Ortalama" : na)
//
if sh_monday
f(dayofweek == dayofweek.monday, "HaftaBaşı")
if sh_daily
f(time_tradingday != time_tradingday[1], "Günlük")
if sh_weekly
f(dayofweek < dayofweek[1], "Haftalık")
if sh_monthly
f(dayofmonth < dayofmonth[1], "Aylık")
/////////
Yer İmleri