//-------------------------------------------------------------------- // 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.
//-------------------------------------------------------------------- // 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)
// 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)
// 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.