You are on page 1of 2

instrument {

name = 'Pivot Price',


icon = 'https://freesoft.ru/storage/images/208/2075/207410/207410_normal.png',
overlay = true
}

periodL = input(4, "Left", input.integer, 1)


periodR = input(5, "Right", input.integer, 1)

input_group {
"Support & Resistance",
colorS = input { default = rgba(3, 175, 34, 1), type = input.color },
colorR = input { default = rgba(236, 23, 6, 1), type = input.color },
width = input { default = 1, type = input.line_width},
visibleSR = input { default = true, type = input.plot_visibility },
}

local function pivotHHprice(l, r)


local tablePivot = {}
for i = 0, r-2, 1 do
if high[r-1] > high[i] then
table.insert(tablePivot, 0)
else
table.insert(tablePivot, 1)
end
end
for j = r, l + r - 1 , 1 do
if high[r-1] > high[j] then
table.insert(tablePivot, 0)
else
table.insert(tablePivot, 1)
end
end
table.sort(tablePivot)
position_r = tablePivot[#tablePivot] == 0 and r or 0
return position_r
end

local function pivotLLprice(l, r)


local tablePivot = {}
for i = 0, r-2, 1 do
if low[r-1] < low[i] then
table.insert(tablePivot, 0)
else
table.insert(tablePivot, 1)
end
end
for j = r, l + r - 1 , 1 do
if low[r-1] < low[j] then
table.insert(tablePivot, 0)
else
table.insert(tablePivot, 1)
end
end
table.sort(tablePivot)
position_r = tablePivot[#tablePivot] == 0 and r or 0
return position_r
end
pivotHHPricePlot = iff( pivotHHprice(periodL, periodR) == periodR, high[periodR],
false)
pivotLLPricePlot = iff( pivotLLprice(periodL, periodR) == periodR, low[periodR],
false)

plot_shape(pivotHHPricePlot, "pivotHHPricePlot", shape_style.triangledown,


shape_size.large, "red", shape_location.abovebar, -periodR+1, "HH", "red")
plot_shape(pivotLLPricePlot, "pivotLLPricePlot", shape_style.triangleup,
shape_size.large, "green", shape_location.belowbar, -periodR+1, "LL", "green")

local function positionOfPrice(array, countTrue)


position = {}
for i = 0, 300, 1 do
if get_value(array[i]) ~= false then
table.insert(position, i)
end
if #position == countTrue then
break
end
end
return position
end

positionsHH = positionOfPrice(pivotHHPricePlot, 2)
positionsLL = positionOfPrice(pivotLLPricePlot, 2)

positionsHH_1 = get_value(positionsHH[1] + (periodR - 1))


positionsHH_2 = get_value(positionsHH[2] + (periodR - 1))

positionsLL_1 = get_value(positionsLL[1] + (periodR - 1))


positionsLL_2 = get_value(positionsLL[2] + (periodR - 1))

if visibleSR then
hline(get_value(high[positionsHH_1]), "HH1", colorR, width)
hline(get_value(high[positionsHH_2]), "HH2", colorR, width)
hline(get_value(low[positionsLL_1]), "LL1", colorS, width)
hline(get_value(low[positionsLL_2]), "LL2", colorS, width)

rect(get_value(high[positionsHH_1]), get_value(high[positionsHH_2]), "fillHH",


rgba(175, 32, 3, 0.5) )
rect(get_value(low[positionsLL_1]), get_value(low[positionsLL_2]), "fillLL",
rgba(2, 171, 12, 0.5) )

end

You might also like