Untitled
user_2314666
plain_text
2 months ago
10 kB
5
Indexable
//@version=6 strategy('RSI BOTU', overlay = true, pyramiding = 5, commission_value = 0.03, initial_capital = 5000, default_qty_type = strategy.percent_of_equity, default_qty_value = 20) // Girdi parametreleri yatirimTutari = input.float(5000, title = "Yatırım Tutarı") mevcut_fiyat = close rsi_period = input.int(title = 'RSI Periyodu', defval = 14, minval = 1) kar_al_yuzde = input.float(title = 'Kar Al Yüzdesi (%)', defval = 10.0, minval = 0.0, step = 0.5) alim_yuzde = input.float(title = 'Alım Yüzdesi (%)', defval = 10.0, minval = 0.0, step = 0.5) api_key = input.string(title = "API Anahtarı", defval = "", tooltip = "Osmanlı Yatırım API anahtarınızı girin") token=input.string(title = "Token", defval = "", tooltip = "Osmanlı Yatırım Token girin") // Tarih aralığı seçimi baslangic_tarihi = input.time(title = "Başlangıç Tarihi", defval = timestamp("2025-01-01 10:00")) bitis_tarihi = input.time(title = "Bitiş Tarihi", defval = timestamp("2025-12-31 17:59")) // Çalışma aralığı kontrolü calisma_araligi = (time >= baslangic_tarihi) and (time <= bitis_tarihi) // RSI Hesaplama rsi = ta.rsi(close, rsi_period) // Pozisyon Fiyatlarını Saklamak İçin Dizi var float[] pozisyon_fiyatlari = array.new_float(5, na) // JSON mesajını oluşturma fonksiyonu f_alertMesajiOlustur(orderSide, quantity) => json_string = '{"name": "Emir gönder",' + '"symbol": "' + syminfo.ticker + '",' + '"orderSide": "' + orderSide + '",' + '"orderType": "mkt",' + '"price": "0",' + '"quantity": "' + str.tostring(quantity) + '",' + '"timeInForce": "ioc",' + '"apiKey": "' + api_key + '",' + '"timenow": "{{timenow}}",' + '"token": "' + token + '"}' json_string // Mevcut sermayeyi dinamik olarak hesapla var float mevcut_sermaye = yatirimTutari if (ta.change(strategy.position_size) != 0) mevcut_sermaye := yatirimTutari + strategy.netprofit if (strategy.position_size == 0) mevcut_sermaye := yatirimTutari + strategy.netprofit // Toplam lot hesaplama toplamLot = math.floor(mevcut_sermaye / mevcut_fiyat) // Emir miktarı (lot veya adet) ADET = math.floor(toplamLot * 1 / 5) // Alım Koşulları ve İşlemleri if calisma_araligi and rsi <= 30 and rsi > rsi[1] if na(array.get(pozisyon_fiyatlari, 0)) array.set(pozisyon_fiyatlari, 0, close) strategy.entry('Long1', strategy.long) alert(message = f_alertMesajiOlustur("buy", ADET), freq = alert.freq_once_per_bar_close) else if na(array.get(pozisyon_fiyatlari, 1)) and close < array.get(pozisyon_fiyatlari, 0) * (1 - alim_yuzde / 100) array.set(pozisyon_fiyatlari, 1, close) strategy.entry('Long2', strategy.long) alert(message = f_alertMesajiOlustur("buy", ADET), freq = alert.freq_once_per_bar_close) else if na(array.get(pozisyon_fiyatlari, 2)) and close < array.get(pozisyon_fiyatlari, 1) * (1 - alim_yuzde / 100) array.set(pozisyon_fiyatlari, 2, close) strategy.entry('Long3', strategy.long) alert(message = f_alertMesajiOlustur("buy", ADET), freq = alert.freq_once_per_bar_close) else if na(array.get(pozisyon_fiyatlari, 3)) and close < array.get(pozisyon_fiyatlari, 2) * (1 - alim_yuzde / 100) array.set(pozisyon_fiyatlari, 3, close) strategy.entry('Long4', strategy.long) alert(message = f_alertMesajiOlustur("buy", ADET), freq = alert.freq_once_per_bar_close) else if na(array.get(pozisyon_fiyatlari, 4)) and close < array.get(pozisyon_fiyatlari, 3) * (1 - alim_yuzde / 100) array.set(pozisyon_fiyatlari, 4, close) strategy.entry('Long5', strategy.long) alert(message = f_alertMesajiOlustur("buy", ADET), freq = alert.freq_once_per_bar_close) // Satış Koşulları ve İşlemleri for i = 0 to 4 pozisyon_fiyati = array.get(pozisyon_fiyatlari, i) if not na(pozisyon_fiyati) if calisma_araligi and (rsi > 70 or close > pozisyon_fiyati * (1 + kar_al_yuzde / 100)) and close > pozisyon_fiyati strategy.close('Long' + str.tostring(i + 1)) array.set(pozisyon_fiyatlari, i, na) alert(message = f_alertMesajiOlustur("sell", ADET), freq = alert.freq_once_per_bar_close) // Tablo yönü ve büyüklük değişkenleri tableYonu = input.string(defval = 'Sağ Üst', title = 'Tablo Yönü', options = ['Sağ Üst', 'Sağ Alt', 'Sağ Orta', 'Orta Alt', 'Orta Sol', 'Sol Üst', 'Sol Alt']) tableBuyukluk = input.string(defval = 'Küçük', title = 'Tablo Büyüklüğü', options = ['Küçük', 'Orta', 'Büyük', 'Minnak']) // Tablo yönü için switch-case yapısı yon = switch tableYonu 'Sağ Üst' => position.top_right 'Sağ Alt' => position.bottom_right 'Sağ Orta' => position.middle_right 'Orta Alt' => position.bottom_center 'Orta Sol' => position.bottom_left 'Sol Üst' => position.top_left 'Sol Alt' => position.bottom_left // Tablo büyüklüğü için switch-case yapısı buyuk = switch tableBuyukluk 'Küçük' => size.small 'Büyük' => size.large 'Orta' => size.normal 'Minnak' => size.tiny // Tabloyu tanımlama (satır ve sütun sayısı sabit) var table tablo = table.new(position = yon, columns = 3, rows = 6, border_width = 2, border_color = color.black, frame_color = color.black, frame_width = 2) // Açık pozisyon sayısı acik_pozisyon_sayisi = strategy.opentrades // Karlı pozisyon sayısı ve ortalama kar yüzdesi karli_pozisyon_sayisi = 0 toplam_kar_yuzdesi = 0.0 for i = 0 to strategy.opentrades - 1 if strategy.opentrades.profit(i) > 0 karli_pozisyon_sayisi := karli_pozisyon_sayisi + 1 kar_yuzdesi = (strategy.opentrades.profit(i) / (strategy.opentrades.entry_price(i) * strategy.opentrades.size(i))) * 100 toplam_kar_yuzdesi := toplam_kar_yuzdesi + kar_yuzdesi ortalama_kar_yuzdesi = karli_pozisyon_sayisi > 0 ? nz(toplam_kar_yuzdesi / karli_pozisyon_sayisi, 0) : 0 // Zararda bekleyen pozisyon sayısı ve ortalama zarar yüzdesi zararda_pozisyon_sayisi = acik_pozisyon_sayisi - karli_pozisyon_sayisi toplam_zarar_yuzdesi = 0.0 for i = 0 to strategy.opentrades - 1 if strategy.opentrades.profit(i) < 0 zarar_yuzdesi = (strategy.opentrades.profit(i) / (strategy.opentrades.entry_price(i) * strategy.opentrades.size(i))) * 100 // ^ Missing closing parenthesis here. toplam_zarar_yuzdesi := toplam_zarar_yuzdesi + zarar_yuzdesi ortalama_zarar_yuzdesi = zararda_pozisyon_sayisi > 0 ? toplam_zarar_yuzdesi / zararda_pozisyon_sayisi : 0 // Toplam Net Kar ve Yüzde Hesaplama toplam_net_kar = strategy.netprofit toplam_net_kar_yuzde = ((strategy.netprofit) / strategy.initial_capital) * 100 toplam_net_kar_rengi = toplam_net_kar >= 0 ? color.green : color.red // Tabloyu güncelleme if barstate.islast // Strateji Durumu strateji_durumu = calisma_araligi ? "Strateji Aktif" : "Strateji Pasif" strateji_durumu_rengi = calisma_araligi ? color.green : color.silver table.cell(tablo, 0, 0, "Strateji Durumu", text_color = color.white, bgcolor = color.silver, text_size = buyuk) table.cell(tablo, 0, 1, strateji_durumu, text_color = color.white, bgcolor = strateji_durumu_rengi, text_size = buyuk) // Başlangıç ve Bitiş Tarihleri baslangic_tarihi_formatli = str.tostring(year(baslangic_tarihi), "0000") + "-" + str.tostring(month(baslangic_tarihi), "00") + "-" + str.tostring(dayofmonth(baslangic_tarihi), "00") + " " + str.tostring(hour(baslangic_tarihi), "00") + ":" + str.tostring(minute(baslangic_tarihi), "00") bitis_tarihi_formatli = str.tostring(year(bitis_tarihi), "0000") + "-" + str.tostring(month(bitis_tarihi), "00") + "-" + str.tostring(dayofmonth(bitis_tarihi), "00") + " " + str.tostring(hour(bitis_tarihi), "00") + ":" + str.tostring(minute(bitis_tarihi), "00") baslangic_bitis_rengi = calisma_araligi ? color.green : color.silver table.cell(tablo, 1, 0, "Başlangıç Tarihi", text_color = color.white, bgcolor = color.silver, text_size = buyuk) table.cell(tablo, 1, 1, baslangic_tarihi_formatli, text_color = color.white, bgcolor = baslangic_bitis_rengi, text_size = buyuk) table.cell(tablo, 2, 0, "Bitiş Tarihi", text_color = color.white, bgcolor = color.silver, text_size = buyuk) table.cell(tablo, 2, 1, bitis_tarihi_formatli, text_color = color.white, bgcolor = baslangic_bitis_rengi, text_size = buyuk) // Açık Pozisyon Sayısı table.cell(tablo, 0, 2, "Açık Pozisyon", text_color = color.white, bgcolor = color.silver, text_size = buyuk) table.cell(tablo, 0, 3, str.tostring(acik_pozisyon_sayisi), text_color = color.white, bgcolor = color.green, text_size = buyuk) // Karlı Pozisyon Sayısı table.cell(tablo, 1, 2, "Karlı Pozisyon", text_color = color.white, bgcolor = color.silver, text_size = buyuk) table.cell(tablo, 1, 3, str.tostring(karli_pozisyon_sayisi), text_color = color.white, bgcolor = color.green, text_size = buyuk) // Zararda Pozisyon Sayısı table.cell(tablo, 2, 2, "Zararda Pozisyon", text_color = color.white, bgcolor = color.silver, text_size = buyuk) table.cell(tablo, 2, 3, str.tostring(zararda_pozisyon_sayisi), text_color = color.white, bgcolor = color.red, text_size = buyuk) // Toplam Net Kar ve Yüzde toplam_net_kar_metni = str.tostring(toplam_net_kar, "#.##") + " " + syminfo.currency + " (" + str.tostring(toplam_net_kar_yuzde, "#.##") + "%)" table.cell(tablo, 0, 4, "Toplam Net Kar", text_color = color.white, bgcolor = color.silver, text_size = buyuk) table.cell(tablo, 0, 5, toplam_net_kar_metni, text_color = color.white, bgcolor = toplam_net_kar_rengi, text_size = buyuk) // Karlı P.% table.cell(tablo, 1, 4, "Karlı P.%", text_color = color.white, bgcolor = color.green, text_size = buyuk) table.cell(tablo, 1, 5, str.tostring(ortalama_kar_yuzdesi, "#.##") + " %", text_color = color.white, bgcolor = color.green, text_size = buyuk) // Zararda P.% table.cell(tablo, 2, 4, "Zararda P.%", text_color = color.white, bgcolor = color.red, text_size = buyuk) table.cell(tablo, 2, 5, str.tostring(ortalama_zarar_yuzdesi, "#.##") + " %", text_color = color.white, bgcolor = color.red, text_size = buyuk)
Editor is loading...
Leave a Comment