Untitled
unknown
plain_text
a year ago
4.8 kB
30
Indexable
//@version=5
strategy("Mr.Rakun İster By.OzGo Yapar strategy ", overlay=true, initial_capital=10000)
// Kullanıcı Girdileri
var float init_position_size = input.float(1.0, "Başlangıç Pozisyon Büyüklüğü")
var float tp1_percent = input.float(25, "TP1 Yüzde", minval=0, maxval=100)
var float tp2_percent = input.float(25, "TP2 Yüzde", minval=0, maxval=100)
var float tp3_percent = input.float(25, "TP3 Yüzde", minval=0, maxval=100)
var float tp4_percent = input.float(25, "TP4 Yüzde", minval=0, maxval=100)
// Geliştirilmiş split_position fonksiyonu
calculate_position_amount(float totalSize, float percentage) =>
var float PRECISION = 100000000 // 8 decimal hassasiyet için
float amount = math.floor(totalSize * (percentage / 100) * PRECISION) / PRECISION
amount
// Pozisyon takibi için değişkenler
var float remaining_position = 0.0
var int current_tp = 0
var float entry_price = 0.0
var bool tp1_executed = false
var bool tp2_executed = false
var bool tp3_executed = false
var bool tp4_executed = false
// Her TP için pozisyon miktarları
var float tp1_amount = 0.0
var float tp2_amount = 0.0
var float tp3_amount = 0.0
var float tp4_amount = 0.0
// Giriş sinyali (örnek)
fast_ma = ta.sma(close, 10)
slow_ma = ta.sma(close, 20)
entry_signal = ta.crossover(fast_ma, slow_ma)
// TP seviyeleri
tp1_level = strategy.position_avg_price * 1.01
tp2_level = strategy.position_avg_price * 1.02
tp3_level = strategy.position_avg_price * 1.03
tp4_level = strategy.position_avg_price * 1.04
// Pozisyon girişi
if entry_signal and strategy.position_size == 0
// Pozisyon miktarlarını hesapla
tp1_amount := calculate_position_amount(init_position_size, tp1_percent)
tp2_amount := calculate_position_amount(init_position_size, tp2_percent)
tp3_amount := calculate_position_amount(init_position_size, tp3_percent)
// Son miktar için kalan miktarı kullan
tp4_amount := init_position_size - tp1_amount - tp2_amount - tp3_amount
strategy.entry("Long", strategy.long, init_position_size)
remaining_position := init_position_size
current_tp := 1
entry_price := close
tp1_executed := false
tp2_executed := false
tp3_executed := false
tp4_executed := false
// TP1 İşlemi
if strategy.position_size > 0 and current_tp == 1 and high >= tp1_level and not tp1_executed
if tp1_amount <= remaining_position
strategy.order("TP1", strategy.short, tp1_amount, limit=tp1_level)
remaining_position := remaining_position - tp1_amount
current_tp := 2
tp1_executed := true
// TP2 İşlemi
if strategy.position_size > 0 and current_tp == 2 and high >= tp2_level and not tp2_executed
if tp2_amount <= remaining_position
strategy.order("TP2", strategy.short, tp2_amount, limit=tp2_level)
remaining_position := remaining_position - tp2_amount
current_tp := 3
tp2_executed := true
// TP3 İşlemi
if strategy.position_size > 0 and current_tp == 3 and high >= tp3_level and not tp3_executed
if tp3_amount <= remaining_position
strategy.order("TP3", strategy.short, tp3_amount, limit=tp3_level)
remaining_position := remaining_position - tp3_amount
current_tp := 4
tp3_executed := true
// TP4 İşlemi
if strategy.position_size > 0 and current_tp == 4 and high >= tp4_level and not tp4_executed
if tp4_amount <= remaining_position
strategy.order("TP4", strategy.short, remaining_position, limit=tp4_level)
remaining_position := 0
current_tp := 0
tp4_executed := true
// Pozisyon bilgilerini gösterme
var label pos_info = na
label.delete(pos_info[1])
info_text = "Kalan Poz: " + str.tostring(remaining_position, "#.########") + "\nTP Seviyesi: " + str.tostring(current_tp) + "\nOrtalama Giriş: " + str.tostring(entry_price) + "\nTP1 Miktar: " + str.tostring(tp1_amount, "#.########") + "\nTP2 Miktar: " + str.tostring(tp2_amount, "#.########") + "\nTP3 Miktar: " + str.tostring(tp3_amount, "#.########") + "\nTP4 Miktar: " + str.tostring(tp4_amount, "#.########")
pos_info := label.new(bar_index, high, text=info_text, style=label.style_label_down, color=color.new(color.blue, 70))
// Plot TP seviyeleri
plot(strategy.position_size > 0 ? tp1_level : na, "TP1", color.new(color.green, 0), style=plot.style_circles)
plot(strategy.position_size > 0 ? tp2_level : na, "TP2", color.new(color.green, 20), style=plot.style_circles)
plot(strategy.position_size > 0 ? tp3_level : na, "TP3", color.new(color.green, 40), style=plot.style_circles)
plot(strategy.position_size > 0 ? tp4_level : na, "TP4", color.new(color.green, 60), style=plot.style_circles)Editor is loading...
Leave a Comment