PROTECTED SOURCE SCRIPT

Destek, Direnc ve Trend (Pivot Bazli, min 3 bar)

//version=6
indicator('Destek, Direnc ve Trend (Pivot Bazli, min 3 bar)', overlay = true)

//--------------------------------------------------------------------
// 1) KULLANICI AYARLARI (INPUT)
//--------------------------------------------------------------------
pivotLen = input.int(3, 'Pivot Uzunlugu (min 3)', minval = 1)
showTrend = input.bool(true, 'Trend Cizgisi Goster?')
showSR = input.bool(true, 'Destek-Direnc Cizgisi Goster?')

//--------------------------------------------------------------------
// 2) PIVOT HESAPLARI
//--------------------------------------------------------------------
// Bir barin pivot high (zirve) olabilmesi icin:
// - Son pivotLen barin ve gelecek pivotLen barin en yuksek degerinden yuksek olmali
// pivotH = bar_index - pivotLen'deki high, en yuksekse true
//
// pivotLow icin ise en dusuk olmali
// Bu kodda Pine'in built-in fonksiyonlarindaki mantigi taklit ediyoruz.

pivotH = high[pivotLen] == ta.highest(high, pivotLen * 2 + 1)
pivotL = low[pivotLen] == ta.lowest(low, pivotLen * 2 + 1)

//--------------------------------------------------------------------
// 3) DIZILER: PIVOT BILGILERINI SAKLA
//--------------------------------------------------------------------
var pivotHighBars = array.new_int()
var pivotHighVals = array.new_float()
var pivotLowBars = array.new_int()
var pivotLowVals = array.new_float()

//--------------------------------------------------------------------
// 4) PIVOTLARI TESPIT VE DIZILERE EKLE
//--------------------------------------------------------------------
if barstate.isconfirmed
if pivotH
array.push(pivotHighBars, bar_index - pivotLen)
array.push(pivotHighVals, high[pivotLen])
if pivotL
array.push(pivotLowBars, bar_index - pivotLen)
array.push(pivotLowVals, low[pivotLen])

// Dizi boyutu cok buyumesin diye 20'den fazlasi varsa en eskileri sil
if array.size(pivotHighBars) > 20
array.shift(pivotHighBars)
array.shift(pivotHighVals)
if array.size(pivotLowBars) > 20
array.shift(pivotLowBars)
array.shift(pivotLowVals)

//--------------------------------------------------------------------
// 5) LINE REFERANSLARI TANIMLA (var line ... = na)
//--------------------------------------------------------------------
var line srLineHigh = na
var line srLineLow = na
var line trendLineHi = na
var line trendLineLo = na

//--------------------------------------------------------------------
// 6) DESTEK - DIRENC CIZGILERI
//--------------------------------------------------------------------
// Son 2 pivot high'i birlestir -> Direnc
// Son 2 pivot low'u birlestir -> Destek

if showSR
// a) Direnc
if array.size(pivotHighBars) >= 2
// Son 2 pivot high verilerini cek
bh1 = array.get(pivotHighBars, array.size(pivotHighBars) - 1)
ph1 = array.get(pivotHighVals, array.size(pivotHighVals) - 1)
bh2 = array.get(pivotHighBars, array.size(pivotHighBars) - 2)
ph2 = array.get(pivotHighVals, array.size(pivotHighVals) - 2)

// Eger eski line varsa sil
if not na(srLineHigh)
line.delete(srLineHigh)


// Yeni direnc line'i olustur
srLineHigh := line.new(x1 = bh2, y1 = ph2, x2 = bh1, y2 = ph1, extend = extend.right, color = color.red, width = 2)
srLineHigh

// b) Destek
if array.size(pivotLowBars) >= 2
bl1 = array.get(pivotLowBars, array.size(pivotLowBars) - 1)
pl1 = array.get(pivotLowVals, array.size(pivotLowVals) - 1)
bl2 = array.get(pivotLowBars, array.size(pivotLowBars) - 2)
pl2 = array.get(pivotLowVals, array.size(pivotLowVals) - 2)

if not na(srLineLow)
line.delete(srLineLow)


srLineLow := line.new(x1 = bl2, y1 = pl2, x2 = bl1, y2 = pl1, extend = extend.right, color = color.lime, width = 2)
srLineLow

//--------------------------------------------------------------------
// 7) TREND CIZGILERI
//--------------------------------------------------------------------
// Basit mantik:
// - 3 pivot high ardisik olarak asagidaki gibi siralandiysa dusen trend
// - 3 pivot low ardisik olarak asagidaki gibi siralandiysa yukselen trend

if showTrend
// a) Dusen trend icin pivot high kontrolu
if array.size(pivotHighVals) >= 3
ph1 = array.get(pivotHighVals, array.size(pivotHighVals) - 1)
ph2 = array.get(pivotHighVals, array.size(pivotHighVals) - 2)
ph3 = array.get(pivotHighVals, array.size(pivotHighVals) - 3)

bh1 = array.get(pivotHighBars, array.size(pivotHighBars) - 1)
bh2 = array.get(pivotHighBars, array.size(pivotHighBars) - 2)
bh3 = array.get(pivotHighBars, array.size(pivotHighBars) - 3)

// Eger ph1 < ph2 < ph3 ise dusen siralama
if ph1 < ph2 and ph2 < ph3
// Eski trend line varsa sil
if not na(trendLineHi)
line.delete(trendLineHi)
// Yeni line
trendLineHi := line.new(x1 = bh3, y1 = ph3, x2 = bh1, y2 = ph1, extend = extend.right, color = color.new(color.red, 0), width = 2)
trendLineHi

// b) Yukselen trend icin pivot low kontrolu
if array.size(pivotLowVals) >= 3
pl1 = array.get(pivotLowVals, array.size(pivotLowVals) - 1)
pl2 = array.get(pivotLowVals, array.size(pivotLowVals) - 2)
pl3 = array.get(pivotLowVals, array.size(pivotLowVals) - 3)

bl1 = array.get(pivotLowBars, array.size(pivotLowBars) - 1)
bl2 = array.get(pivotLowBars, array.size(pivotLowBars) - 2)
bl3 = array.get(pivotLowBars, array.size(pivotLowBars) - 3)

// pl1 > pl2 > pl3 ise yukselen siralama
if pl1 > pl2 and pl2 > pl3
if not na(trendLineLo)
line.delete(trendLineLo)
trendLineLo := line.new(x1 = bl3, y1 = pl3, x2 = bl1, y2 = pl1, extend = extend.right, color = color.new(color.lime, 0), width = 2)
trendLineLo

//--------------------------------------------------------------------
// ACIKLAMA
//--------------------------------------------------------------------
// - pivotLen = 3, en az 3 bar (mum) dokunarak pivot olusumunu bekler.
// - Kod, bar kapanisi (barstate.isconfirmed) ile pivot tespit eder,
// pivotlari dizilerde saklar, son 2 pivot ile destek/direnc,
// son 3 pivot ile trend cizgileri olusturur.
// - "Line" referanslarini var line ... = na seklinde tanimladik,
// her if blogunda != na kontrolu yaparak silip yeniden olusturuyoruz.
// - Girinti (indentation) kurallari Pine Script’e uyumludur.
Bill Williams IndicatorsBreadth Indicators

Script protégé

Ce script est publié en code source fermé et vous pouvez l'utiliser librement. Vous pouvez le préférer pour l'utiliser sur un graphique. Vous ne pouvez pas visualiser ou modifier son code source.

Vous voulez utiliser ce script sur un graphique ?

Clause de non-responsabilité