//@version=5
strategy("PMAX + ATR AL/Sat Stratejisi ", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=0)
// Kullanıcı Seçimleri
cikis_turu = input.string("SAT ile Çıkış", "Çıkış Yöntemi", options=["SAT ile Çıkış", "% Kar Al ile Çıkış", "Her İkisi ile Çıkış"])
profit_percent = input.float(5.0, "% Kar Al Seviyesi", minval=0.1, maxval=50.0, step=0.5)
stop_loss_percent = input.float(3.0, "Stop Loss %", minval=0.1, maxval=20.0, step=0.5, tooltip="İşlem girişten sonra maksimum % kayıp")
// Emir Boyutu Seçenekleri
emir_boyutu_turu = input.string("Portföy %", "Emir Boyutu", options=["Portföy %", "Sabit Lot", "Sabit TL"])
emir_boyutu_deger = input.float(100.0, "Emir Boyutu Değeri", minval=0.1, step=0.1, tooltip="Portföy % için: 0-100, Sabit Lot için: adet, Sabit TL için: TL miktarı")
// Parametreler
hhv_period = 20
hhv_shift = 5
atr_period = 45
atr_shift = 5
atr_multiplier = 3
pmax_length1 = 7
pmax_length2 = 10
pmax_length3 = 20
// AL koşulu hesaplamaları
hhv_20 = ta.highest(high, hhv_period)
shifted_hhv = hhv_20[hhv_shift]
shifted_atr = ta.atr(atr_period)[atr_shift]
al_seviyesi = shifted_hhv + (shifted_atr * atr_multiplier)
al_condition = ta.cross(close, al_seviyesi)
// SAT koşulu hesaplamaları
typical_price = (high + low) / 2
pmax_value = (ta.highest(high, pmax_length1) + ta.highest(high, pmax_length2) + ta.highest(high, pmax_length3)) / 3
sat_condition = close < math.min(pmax_value, typical_price)
// Pozisyon ve Fiyat Takibi - TİP TANIMLARI EKLENDİ
var float entry_price = na
var bool position_open = false
var float position_size = na
// Kullanıcı Seçimine Göre Çıkış Koşulları - TİP TANIMLARI EKLENDİ
var bool use_sat_exit = cikis_turu == "SAT ile Çıkış" or cikis_turu == "Her İkisi ile Çıkış"
var bool use_profit_exit = cikis_turu == "% Kar Al ile Çıkış" or cikis_turu == "Her İkisi ile Çıkış"
// Emir Boyutu Hesaplama Fonksiyonu
get_position_size() =>
calc_size = 0.0
if emir_boyutu_turu == "Portföy %"
calc_size := strategy.equity * (emir_boyutu_deger / 100.0) / close
else if emir_boyutu_turu == "Sabit Lot"
calc_size := emir_boyutu_deger
else if emir_boyutu_turu == "Sabit TL"
calc_size := emir_boyutu_deger / close
else
calc_size := na
calc_size
// Giriş fiyatını ve boyutunu kaydet
if al_condition and not position_open
entry_price := close
position_open := true
position_size := get_position_size()
// Emir boyutuna göre işlem aç
if emir_boyutu_turu == "Portföy %"
strategy.entry("AL", strategy.long, qty=position_size, comment="% " + str.tostring(emir_boyutu_deger))
else if emir_boyutu_turu == "Sabit Lot"
strategy.entry("AL", strategy.long, qty=position_size, comment="Lot:" + str.tostring(emir_boyutu_deger))
else if emir_boyutu_turu == "Sabit TL"
strategy.entry("AL", strategy.long, qty=position_size, comment="TL:" + str.tostring(emir_boyutu_deger))
// Kar Alma Hesaplamaları
take_profit_level = entry_price * (1 + profit_percent / 100)
take_profit_condition = position_open and close >= take_profit_level
// Stop Loss Hesaplamaları
stop_loss_level = entry_price * (1 - stop_loss_percent / 100)
stop_loss_condition = position_open and close <= stop_loss_level
// Tüm Çıkış Koşulları
cikis_kosulu = false
cikis_sebebi = ""
// ÖNCELİK SIRASI: 1. Stop Loss → 2. Kar Alma → 3. SAT
if stop_loss_condition
cikis_kosulu := true
cikis_sebebi := "Stop Loss " + str.tostring(stop_loss_percent, "#.#") + "%"
else if use_profit_exit and take_profit_condition
cikis_kosulu := true
cikis_sebebi := "Kar Al " + str.tostring(profit_percent, "#.#") + "%"
else if use_sat_exit and sat_condition and position_open
cikis_kosulu := true
cikis_sebebi := "SAT Sinyali"
// Strateji kuralları - Çıkış
if cikis_kosulu and position_open
strategy.close("AL", comment=cikis_sebebi)
entry_price := na
position_open := false
position_size := na
// Görselleştirme
plot(al_seviyesi, "AL Seviyesi", color=color.green, linewidth=2)
plot(pmax_value, "PMAX", color=color.orange, linewidth=1)
plot(typical_price, "Typical Price", color=color.blue, linewidth=1)
// Kar alma ve stop loss seviyelerini göster
plot(use_profit_exit and position_open ? take_profit_level : na, "Kar Al Seviyesi",
color=color.purple, linewidth=2, style=plot.style_circles)
plot(position_open ? stop_loss_level : na, "Stop Loss Seviyesi",
color=color.red, linewidth=2, style=plot.style_circles)
// Bilgi tablosu
var table info_table = table.new(position.top_right, 2, 10, bgcolor=color.white, border_width=1)
if barstate.islast
table.cell(info_table, 0, 0, "Emir Boyutu", bgcolor=color.gray)
table.cell(info_table, 1, 0, emir_boyutu_turu, bgcolor=color.gray)
table.cell(info_table, 0, 1, "Boyut Değeri", bgcolor=color.blue)
table.cell(info_table, 1, 1, str.tostring(emir_boyutu_deger, "#.##"), bgcolor=color.blue)
table.cell(info_table, 0, 2, "Çıkış Yöntemi", bgcolor=color.gray)
table.cell(info_table, 1, 2, cikis_turu, bgcolor=color.gray)
table.cell(info_table, 0, 3, "Stop Loss %", bgcolor=color.red)
table.cell(info_table, 1, 3, str.tostring(stop_loss_percent, "#.#") + "%", bgcolor=color.red)
table.cell(info_table, 0, 4, "Kar Al %", bgcolor=color.yellow)
table.cell(info_table, 1, 4, str.tostring(profit_percent, "#.#") + "%", bgcolor=color.yellow)
table.cell(info_table, 0, 5, "AL Seviyesi", bgcolor=color.lime)
table.cell(info_table, 1, 5, str.tostring(al_seviyesi, "#.##"), bgcolor=color.lime)
if position_open
table.cell(info_table, 0, 6, "Giriş Fiyatı", bgcolor=color.blue)
table.cell(info_table, 1, 6, str.tostring(entry_price, "#.##"), bgcolor=color.blue)
table.cell(info_table, 0, 7, "Pozisyon Boyutu", bgcolor=color.orange)
table.cell(info_table, 1, 7, str.tostring(position_size, "#.##") + " lot", bgcolor=color.orange)
table.cell(info_table, 0, 8, "Kar Al", bgcolor=color.purple)
table.cell(info_table, 1, 8, str.tostring(take_profit_level, "#.##"), bgcolor=color.purple)
table.cell(info_table, 0, 9, "Stop Loss", bgcolor=color.red)
table.cell(info_table, 1, 9, str.tostring(stop_loss_level, "#.##"), bgcolor=color.red)
else
table.cell(info_table, 0, 6, "Durum", bgcolor=color.gray)
table.cell(info_table, 1, 6, "Pozisyon Yok", bgcolor=color.gray)
table.cell(info_table, 0, 7, "", bgcolor=color.white)
table.cell(info_table, 1, 7, "", bgcolor=color.white)
table.cell(info_table, 0, 8, "", bgcolor=color.white)
table.cell(info_table, 1, 8, "", bgcolor=color.white)
table.cell(info_table, 0, 9, "", bgcolor=color.white)
table.cell(info_table, 1, 9, "", bgcolor=color.white)
// Seviye çizgileri için alternatif çözüm - plot kullanarak
plot(position_open ? take_profit_level : na, "Take Profit Line", color=color.purple, linewidth=1, style=plot.style_linebr)
plot(position_open ? stop_loss_level : na, "Stop Loss Line", color=color.red, linewidth=1, style=plot.style_linebr)
// Label ile bilgilendirme
if barstate.islast and position_open
label.new(bar_index, high * 1.01,
"Emir: " + emir_boyutu_turu + " (" + str.tostring(emir_boyutu_deger, "#.##") + ")" +
"\nGiriş: " + str.tostring(entry_price, "#.##") +
"\nStop: " + str.tostring(stop_loss_level, "#.##") + " (" + str.tostring(stop_loss_percent, "#.#") + "%)" +
"\nTake Profit: " + str.tostring(take_profit_level, "#.##") + " (" + str.tostring(profit_percent, "#.#") + "%)",
color=color.blue, style=label.style_label_down,
textcolor=color.white, size=size.small)
Bu kod TradingView platformu için yazılmış bir Pine Script strateji göstergesidir. "PMAX + ATR AL/Sat Stratejisi" adlı bu strateji, teknik analiz göstergeleri kullanarak otomatik alım-satım sinyalleri üretir.
HHV (Highest High Value): 20 periyodun en yükseği hesaplanır
ATR (Average True Range): 45 periyodun ortalama volatilitesi
AL seviyesi = (HHV + 5 bar önce) + (ATR + 5 bar önce × 3 kat)
Fiyat bu seviyeyi yukarı kestiğinde AL sinyali oluşur
PMAX: 7, 10 ve 20 periyodluk en yükseklerin ortalaması
Typical Price: (Yüksek + Düşük) / 2
Fiyat PMAX ve Typical Price'ın altına düştüğünde SAT sinyali
Stop Loss: Kullanıcı tanımlı yüzde (varsayılan %3)
Take Profit: Kullanıcı tanımlı kar alma yüzdesi (varsayılan %5)
Çıkış önceliği: 1) Stop Loss → 2) Take Profit → 3) SAT sinyali
Portföy yüzdesi ile (örneğin %100 tüm sermaye)
Sabit lot miktarı ile
Sabit TL tutarı ile
AL seviyesi (yeşil çizgi)
PMAX değeri (turuncu çizgi)
Typical Price (mavi çizgi)
Kar al ve stop loss seviyeleri (daireler ve çizgiler)
Sağ üstte bilgi tablosu
Pozisyon açıkken fiyat etiketi
Bu strateji, trend takip sistemi olarak tasarlanmıştır:
Trend başlangıcında (AL seviyesi kırıldığında) pozisyon açar
Trend dönüşünde veya zararı sınırlandırmak için çeşitli yöntemlerle çıkış yapar
Otomatik backtest yaparak strateji performansını ölçebilirsiniz
Bu kod, otomatik bir trading sistemi oluşturur ve TradingView'de:
Tarihsel performans testi
Gerçek zamanlı sinyal üretimi
Risk yönetimi kuralları uygulama
Görsel analiz sağlama
işlevlerini yerine getirir. Strateji, trend takip eden bir yaklaşımla volatiliteyi de dikkate alarak işlem açmayı hedefler.