本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator('Parabolic CCI Pro — Long & Short + ATR Risk — [AlphaFinansData]', overlay = false, max_labels_count = 500)
groupBT = 'Backtest'
showBacktest = input.bool(true, '═══ Backtest Aralığı ═══', group = groupBT)
startDate = input.time(timestamp('2024-01-01'), 'Başlangıç Tarihi', group = groupBT)
endDate = input.time(timestamp('2025-12-31'), 'Bitiş Tarihi', group = groupBT)
inDateRange = time >= startDate and time <= endDate
canTrade = showBacktest ? inDateRange : true
groupCCI = 'CCI Ayarları'
cciLength = input.int(14, 'CCI Periyodu', minval = 1, group = groupCCI)
cciSource = input.source(hlc3, 'CCI Kaynağı', group = groupCCI)
groupSAR = 'Parabolic SAR Ayarları'
start = input.float(0.02, 'SAR Başlangıç', step = 0.001, minval = 0.001, group = groupSAR)
increment = input.float(0.02, 'SAR Artış', step = 0.001, minval = 0.001, group = groupSAR)
maximum = input.float(0.2, 'SAR Maksimum', step = 0.01, minval = 0.01, group = groupSAR)
groupViz = 'Görünüm'
showCCI = input.bool(true, 'CCI\'yi Göster', group = groupViz)
showSAR = input.bool(true, 'Parabolic SAR\'ı Göster', group = groupViz)
cciColor = input.color(color.rgb(130, 170, 255), 'CCI Rengi', group = groupViz)
sarBullColor = input.color(color.rgb(38, 208, 124), 'SAR Yükseliş Rengi', group = groupViz)
sarBearColor = input.color(color.rgb(255, 92, 96), 'SAR Düşüş Rengi', group = groupViz)
groupVol = 'Hacim Ayarları'
useVolumeFilter = input.bool(true, '═══ Hacim Filtresi ═══', group = groupVol)
volumeMultiplier = input.float(1.5, 'Hacim Çarpanı', minval = 1.0, maxval = 5.0, step = 0.1, group = groupVol)
volumePeriod = input.int(20, 'Ortalama Hacim Periyodu', minval = 5, maxval = 50, group = groupVol)
showVolumeInfo = input.bool(true, 'Hacim Bilgisini Göster', group = groupVol)
avgVolume = ta.sma(volume, volumePeriod)
highVolume = volume > avgVolume * volumeMultiplier
volumeRatio = avgVolume > 0 ? volume / avgVolume : na
barcolor(useVolumeFilter and showVolumeInfo and highVolume ? color.rgb(147, 112, 219, 60) : na, title = 'Yüksek Hacimli Mumlar')
cci = ta.cci(cciSource, cciLength)
var float sar = na
var bool uptrend = true
var float ep = na
var float af = start
var float nextSar = na
if na(sar[1])
sar := cci
ep := cci
uptrend := true
af := start
af
else
sar := nextSar[1]
if uptrend[1]
if cci > ep[1]
ep := cci
af := math.min(af[1] + increment, maximum)
af
else
ep := ep[1]
af := af[1]
af
sar := sar[1] + af * (ep - sar[1])
sar := math.min(sar, cci[1])
sar := math.min(sar, cci[2])
if cci <= sar
uptrend := false
sar := ep
ep := cci
af := start
af
else
uptrend := true
uptrend
else
if cci < ep[1]
ep := cci
af := math.min(af[1] + increment, maximum)
af
else
ep := ep[1]
af := af[1]
af
sar := sar[1] + af * (ep - sar[1])
sar := math.max(sar, cci[1])
sar := math.max(sar, cci[2])
if cci >= sar
uptrend := true
sar := ep
ep := cci
af := start
af
else
uptrend := false
uptrend
if uptrend
nextSar := sar + af * (ep - sar)
nextSar := math.min(nextSar, cci)
nextSar := math.min(nextSar, cci[1])
nextSar
else
nextSar := sar + af * (ep - sar)
nextSar := math.max(nextSar, cci)
nextSar := math.max(nextSar, cci[1])
nextSar
// ÇİZİMLER
plot(showCCI ? cci : na, 'CCI', cciColor, 2)
plot(showSAR ? sar : na, 'Parabolic SAR', uptrend ? sarBullColor : sarBearColor, 1, plot.style_cross)
hline(100, 'Aşırı Alım', color.rgb(255, 92, 96, 80), hline.style_dashed)
hline(0, 'Orta Çizgi', color.rgb(130, 130, 130, 60), hline.style_dotted)
hline(-100, 'Aşırı Satım', color.rgb(38, 208, 124, 80), hline.style_dashed)
// ══════════════════════════════════════════════════════════════════
trendChange = uptrend != uptrend[1]
longSignalRaw = trendChange and uptrend
shortSignalRaw = trendChange and not uptrend
longValid = longSignalRaw and (useVolumeFilter ? highVolume : true)
shortValid = shortSignalRaw and (useVolumeFilter ? highVolume : true)
plotshape(longValid, 'LONG Giriş (Hacimli)', shape.triangleup, location.belowbar, color.rgb(38, 208, 124), size = size.normal, text = 'L', force_overlay = true)
plotshape(shortValid, 'SHORT Giriş (Hacimli)', shape.triangledown, location.abovebar, color.rgb(255, 92, 96), size = size.normal, text = 'S', force_overlay = true)
plotshape(longSignalRaw and useVolumeFilter and not highVolume, 'Düşük Hacimli Yükseliş', shape.triangleup, location.belowbar, color = color.rgb(130, 130, 130, 50), size = size.tiny, force_overlay = true)
plotshape(shortSignalRaw and useVolumeFilter and not highVolume, 'Düşük Hacimli Düşüş', shape.triangledown, location.abovebar, color = color.rgb(130, 130, 130, 50), size = size.tiny, force_overlay = true)
groupRisk = 'Pozisyon Yönetimi'
showTradeTable = input.bool(true, '═══ Pozisyon Tablosu ═══', group = groupRisk)
riskMode = input.string('Percent', 'SL/TP Modu', options = ['Percent', 'ATR'], group = groupRisk)
takeProfitPerc = input.float(2.0, 'Kar Al (%)', minval = 0.1, step = 0.1, group = groupRisk)
stopLossPerc = input.float(10.0, 'Zarar Durdur (%)', minval = 0.1, step = 0.1, group = groupRisk)
useTrailingStop = input.bool(false, 'Trailing Stop Kullan', group = groupRisk)
trailingStopPerc = input.float(0.5, 'Trailing Stop (%)', minval = 0.1, step = 0.1, group = groupRisk)
groupATR = 'ATR Ayarları'
atrLen = input.int(14, 'ATR Periyodu', group = groupATR)
atrMultSL = input.float(3.0, 'ATR SL Katsayısı', group = groupATR)
atrMultTP = input.float(1.0, 'ATR TP Katsayısı', group = groupATR)
atr = ta.atr(atrLen)
var bool inPosition = false
var int side = 0
var float entryPrice = na
var float stopLoss = na
var float takeProfit = na
var float trailingStop = na
var int entryBar = na
var int totalTrades = 0
var int winTrades = 0
var int lossTrades = 0
var float totalProfitPct = 0.0
var float maxProfitPct = 0.0
var float maxLossPct = 0.0
var float sumWin = 0.0
var float sumLoss = 0.0
var int cntWin = 0
var int cntLoss = 0
var float eq = 100.0
var float eqPeak = 100.0
var float maxDrawdown = 0.0
var int winStreak = 0
var int loseStreak = 0
var int maxWinStreak = 0
var int maxLoseStreak = 0
buySignal = longValid and canTrade and not inPosition
sellSignal = shortValid and canTrade and not inPosition
if buySignal
inPosition := true
side := 1
entryPrice := close
entryBar := bar_index
if riskMode == 'Percent'
stopLoss := entryPrice * (1 - stopLossPerc / 100)
takeProfit := entryPrice * (1 + takeProfitPerc / 100)
takeProfit
else
stopLoss := entryPrice - atrMultSL * atr
takeProfit := entryPrice + atrMultTP * atr
takeProfit
trailingStop := stopLoss
trailingStop
if sellSignal
inPosition := true
side := -1
entryPrice := close
entryBar := bar_index
if riskMode == 'Percent'
stopLoss := entryPrice * (1 + stopLossPerc / 100)
takeProfit := entryPrice * (1 - takeProfitPerc / 100)
takeProfit
else
stopLoss := entryPrice + atrMultSL * atr
takeProfit := entryPrice - atrMultTP * atr
takeProfit
trailingStop := stopLoss
trailingStop
if inPosition and useTrailingStop
if side == 1
newTrail = close * (1 - trailingStopPerc / 100)
trailingStop := math.max(trailingStop, newTrail)
trailingStop
if side == -1
newTrail = close * (1 + trailingStopPerc / 100)
trailingStop := math.min(trailingStop, newTrail)
trailingStop
var float lastClosedProfit = na
if inPosition
longExitHit = side == 1 and (close <= (useTrailingStop ? trailingStop : stopLoss) or close >= takeProfit)
shortExitHit = side == -1 and (close >= (useTrailingStop ? trailingStop : stopLoss) or close <= takeProfit)
if longExitHit or shortExitHit
profitPct = side == 1 ? (close - entryPrice) / entryPrice * 100 : (entryPrice - close) / entryPrice * 100
lastClosedProfit := profitPct
totalProfitPct := totalProfitPct + profitPct
totalTrades := totalTrades + 1
// Win/Loss
isWin = profitPct > 0
if isWin
winTrades := winTrades + 1
sumWin := sumWin + profitPct
cntWin := cntWin + 1
maxProfitPct := math.max(maxProfitPct, profitPct)
winStreak := winStreak + 1
loseStreak := 0
maxWinStreak := math.max(maxWinStreak, winStreak)
maxWinStreak
else
lossTrades := lossTrades + 1
sumLoss := sumLoss + profitPct
cntLoss := cntLoss + 1
maxLossPct := math.min(maxLossPct, profitPct)
loseStreak := loseStreak + 1
winStreak := 0
maxLoseStreak := math.max(maxLoseStreak, loseStreak)
maxLoseStreak
eq := eq * (1 + profitPct / 100.0)
eqPeak := math.max(eqPeak, eq)
dd = eqPeak > 0 ? (eq - eqPeak) / eqPeak * 100.0 : 0.0
maxDrawdown := math.min(maxDrawdown, dd) // negatif değer (örn. -12.3%)
inPosition := false
side := 0
entryPrice := na
stopLoss := na
takeProfit := na
trailingStop := na
entryBar := na
entryBar
currentPnL = if inPosition
side == 1 ? (close - entryPrice) / entryPrice * 100 : (entryPrice - close) / entryPrice * 100
else
0.0
// Çizgiler
plot(inPosition and side == 1 ? entryPrice : na, 'Long Giriş', color.rgb(38, 208, 124, 70), 2, plot.style_linebr, true, force_overlay = true)
plot(inPosition and side == -1 ? entryPrice : na, 'Short Giriş', color.rgb(255, 92, 96, 70), 2, plot.style_linebr, true, force_overlay = true)
plot(inPosition ? useTrailingStop ? trailingStop : stopLoss : na, 'Stop', color.rgb(255, 92, 96, 70), 1, plot.style_linebr, true, force_overlay = true)
plot(inPosition ? takeProfit : na, 'Take Profit', color.rgb(251, 191, 36, 70), 1, plot.style_linebr, true, force_overlay = true)
var table statsTable = table.new(position.top_right, 2, 18, force_overlay = true)
if barstate.islast and showTradeTable
table.cell(statsTable, 0, 0, 'POZİSYON / PERFORMANS', bgcolor = color.rgb(17, 24, 39), text_color = color.rgb(240, 240, 240))
table.merge_cells(statsTable, 0, 0, 1, 0)
table.cell(statsTable, 0, 1, 'CCI:', bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(180, 180, 180), text_size = size.small)
table.cell(statsTable, 1, 1, str.tostring(cci, '#.##'), bgcolor = color.rgb(31, 41, 55), text_color = cciColor, text_size = size.small)
table.cell(statsTable, 0, 2, 'SAR:', bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(180, 180, 180), text_size = size.small)
table.cell(statsTable, 1, 2, str.tostring(sar, '#.##'), bgcolor = color.rgb(31, 41, 55), text_color = uptrend ? sarBullColor : sarBearColor, text_size = size.small)
table.cell(statsTable, 0, 3, 'Trend:', bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(180, 180, 180), text_size = size.small)
table.cell(statsTable, 1, 3, uptrend ? 'YÜKSELİŞ ↑' : 'DÜŞÜŞ ↓', bgcolor = color.rgb(31, 41, 55), text_color = uptrend ? color.rgb(38, 208, 124) : color.rgb(255, 92, 96), text_size = size.small)
table.cell(statsTable, 0, 4, 'Hacim:', bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(180, 180, 180), text_size = size.small)
volText = highVolume ? 'YÜKSEK (' + str.tostring(volumeRatio, '#.0') + 'x)' : 'NORMAL'
volColor = highVolume ? color.rgb(251, 191, 36) : color.rgb(150, 150, 150)
table.cell(statsTable, 1, 4, volText, bgcolor = color.rgb(31, 41, 55), text_color = volColor, text_size = size.small)
table.cell(statsTable, 0, 5, '═══════════', bgcolor = color.rgb(15, 23, 42), text_color = color.rgb(100, 100, 100), text_size = size.tiny)
table.merge_cells(statsTable, 0, 5, 1, 5)
posText = inPosition ? side == 1 ? 'LONG AÇIK' : 'SHORT AÇIK' : 'POZİSYON YOK'
posColor = inPosition ? side == 1 ? color.rgb(38, 208, 124) : color.rgb(255, 92, 96) : color.rgb(130, 130, 130)
table.cell(statsTable, 0, 6, 'Pozisyon:', bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(180, 180, 180), text_size = size.small)
table.cell(statsTable, 1, 6, posText, bgcolor = color.rgb(31, 41, 55), text_color = posColor, text_size = size.small)
table.cell(statsTable, 0, 7, 'Giriş:', bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(180, 180, 180), text_size = size.small)
table.cell(statsTable, 1, 7, inPosition ? str.tostring(entryPrice, '#.####') : '-', bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(240, 240, 240), text_size = size.small)
table.cell(statsTable, 0, 8, 'Anlık K/Z:', bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(180, 180, 180), text_size = size.small)
pnlColor = currentPnL > 0 ? color.rgb(38, 208, 124) : currentPnL < 0 ? color.rgb(255, 92, 96) : color.rgb(150, 150, 150)
table.cell(statsTable, 1, 8, inPosition ? str.tostring(currentPnL, '+#.##;-#.##') + '%' : '-', bgcolor = color.rgb(31, 41, 55), text_color = pnlColor, text_size = size.small)
table.cell(statsTable, 0, 9, '═══════════', bgcolor = color.rgb(15, 23, 42), text_color = color.rgb(100, 100, 100), text_size = size.tiny)
table.merge_cells(statsTable, 0, 9, 1, 9)
table.cell(statsTable, 0, 10, 'Toplam İşlem:', bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(180, 180, 180), text_size = size.small)
table.cell(statsTable, 1, 10, str.tostring(totalTrades), bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(240, 240, 240), text_size = size.small)
winRate = totalTrades > 0 ? winTrades / totalTrades * 100 : 0.0
table.cell(statsTable, 0, 11, 'Başarı Oranı:', bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(180, 180, 180), text_size = size.small)
table.cell(statsTable, 1, 11, str.tostring(winRate, '#.0') + '%', bgcolor = color.rgb(31, 41, 55), text_color = winRate >= 50 ? color.rgb(38, 208, 124) : color.rgb(255, 92, 96), text_size = size.small)
avgWin = cntWin > 0 ? sumWin / cntWin : na
avgLoss = cntLoss > 0 ? sumLoss / cntLoss : na
table.cell(statsTable, 0, 12, 'Ort. Kazanç:', bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(180, 180, 180), text_size = size.small)
table.cell(statsTable, 1, 12, na(avgWin) ? '-' : str.tostring(avgWin, '+.##') + '%', bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(38, 208, 124), text_size = size.small)
table.cell(statsTable, 0, 13, 'Ort. Kayıp:', bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(180, 180, 180), text_size = size.small)
table.cell(statsTable, 1, 13, na(avgLoss) ? '-' : str.tostring(avgLoss, '+.##') + '%', bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(255, 92, 96), text_size = size.small)
table.cell(statsTable, 0, 14, 'Max Kâr / Zarar:', bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(180, 180, 180), text_size = size.small)
mxText = str.tostring(maxProfitPct, '+.##') + '% / ' + str.tostring(maxLossPct, '+.##') + '%'
table.cell(statsTable, 1, 14, mxText, bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(251, 191, 36), text_size = size.small)
table.cell(statsTable, 0, 15, 'Win/Win Streak:', bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(180, 180, 180), text_size = size.small)
table.cell(statsTable, 1, 15, str.tostring(winStreak) + ' / ' + str.tostring(maxWinStreak), bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(38, 208, 124), text_size = size.small)
table.cell(statsTable, 0, 16, 'Lose/Lose Streak:', bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(180, 180, 180), text_size = size.small)
table.cell(statsTable, 1, 16, str.tostring(loseStreak) + ' / ' + str.tostring(maxLoseStreak), bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(255, 92, 96), text_size = size.small)
table.cell(statsTable, 0, 17, 'Max Drawdown:', bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(180, 180, 180), text_size = size.small)
table.cell(statsTable, 1, 17, str.tostring(maxDrawdown, '+.##') + '%', bgcolor = color.rgb(31, 41, 55), text_color = color.rgb(255, 92, 96), text_size = size.small)
longMsg = 'LONG Entry | Price: {{close}} | TP: ' + (inPosition and side == 1 ? str.tostring(takeProfit, '#.####') : '—') + ' | SL: ' + (inPosition and side == 1 ? str.tostring(useTrailingStop ? trailingStop : stopLoss, '#.####') : '—') + ' | Vol(x): ' + (na(volumeRatio) ? '-' : str.tostring(volumeRatio, '#.0'))
shortMsg = 'SHORT Entry | Price: {{close}} | TP: ' + (inPosition and side == -1 ? str.tostring(takeProfit, '#.####') : '—') + ' | SL: ' + (inPosition and side == -1 ? str.tostring(useTrailingStop ? trailingStop : stopLoss, '#.####') : '—') + ' | Vol(x): ' + (na(volumeRatio) ? '-' : str.tostring(volumeRatio, '#.0'))
alertcondition(longValid, title = 'LONG Giriş Sinyali')
alertcondition(shortValid, title = 'SHORT Giriş Sinyali')
alertcondition(inPosition and currentPnL <= -stopLossPerc, title = 'Stop Loss Yakın (Percent Mod)', message = 'SL yaklaşıyor! Mevcut K/Z: {{plot_2}}%')
alertcondition(inPosition and currentPnL >= takeProfitPerc * 0.8, title = 'Take Profit Yakın (Percent Mod)', message = 'TP yaklaşıyor! Mevcut K/Z: {{plot_2}}%')