Untitled

mail@pastecode.io avatar
unknown
plain_text
25 days ago
20 kB
9
Indexable
Never
//@version=5

//@strategy_alert_message {{strategy.order.alert_message}} 

//bu yukardaki otomatik olarak alarma ekleniyormus, diger turlu her seferinde bunu yapistirman gerekiyordu..
//19.05.2024
///////////////////////////////////////////////////////
// code combiner and developer @ Mustafa Özbakır mozbakir
// thank all other code owners 
strategy('mge-auto okx', pyramiding=3,close_entries_rule ="FIFO" , use_bar_magnifier = false ,process_orders_on_close=false,calc_on_order_fills = false,calc_on_every_tick= false,format=format.price, overlay=true,  default_qty_type=strategy.percent_of_equity , default_qty_value=100, initial_capital=50, currency=currency.USD, commission_value=0.05, commission_type=strategy.commission.percent)
//Fiyat Tick hesabi
RoundToTick( _price) => math.round(_price/syminfo.mintick)*syminfo.mintick
open_fiyat = RoundToTick(open)
close_fiyat = RoundToTick(close)
high_fiyat = RoundToTick(high)
low_fiyat = RoundToTick(low)
hlc3_fiyat = RoundToTick(hlc3)
var float percenval_most_indikator_long = 0.
var float percenval_most_indikator_short = 0.
var float ikinci_giris_long = 0.
var float ikinci_giris_short = 0.
percenval_most_indikator_long := input.float(defval=3.4, minval=0, step=0.1, title='most percent long') / 100 //değeri 0,034 1000 üzerinden
percenval_most_indikator_short := input.float(defval=3.4, minval=0, step=0.1, title='most percent short') / 100
slen_long = input.int(defval=20, title='Long Fiyat MA Period', minval=2)

slen_short = input.int(defval=20, title='Short Fiyat MA Period', minval=2)





sabit_tp_yl = percenval_most_indikator_long / 2 //input.float(defval = 1.9       , title = "_long Sabit Kar-aL Long (%)"   , step=0.1, minval=0.1) / 100
sabit_tp_ys = percenval_most_indikator_short / 2 //input.float(defval = 1.9       , title = "_short Sabit Kar-aL Short (%)" , step=0.1, minval=0.1) / 100



ikinci_giris_long := 0.009//(percenval_most_indikator_long) - 0.009 //input.float(defval=0.8, minval=0, step=0.1, title='2.Long Fiyat % Kac Düştüğünde',tooltip = 'İlk pozisyon girişi botun %50 bütçesi ile açılır. İlk açılış fiyatı % kaç düşerse geri kalan %50bütçe ile 2. giriş yapılsın?') / 100
ikinci_giris_short := 0.009//(percenval_most_indikator_short) - 0.009//input.float(defval=0.8, minval=0, step=0.1, title='2.Short Fiyat % Kac Yükseldiğinde',tooltip = 'İlk pozisyon girişi botun %50 bütçesi ile açılır. İlk açılış fiyatı % kaç yükselirse geri kalan %50bütçe ile 2. giriş yapılsın?') / 100
//risk_trail_stop = input.float(defval=1.8, minval=0, step=0.1, title='Trail StopLoss % Kar Çarpanı') 

//takipli_sloss_yl = sabit_tp_yl * risk_trail_stop
//takipli_sloss_ys = sabit_tp_ys * risk_trail_stop
//takipli_sloss_yl = input.float(defval = 3.8       , title = "_long Takipli Stop-loss Long (%)"   , step=0.1, minval=0.1) / 100
//takipli_sloss_ys = input.float(defval = 3.8       , title = "_short Takipli Stop-loss Short (%)" , step=0.1, minval=0.1) / 100
sabit_loss_yl = percenval_most_indikator_long//input.float(defval = 1.9       , title = "_long zarar (%)"   , step=0.1, minval=0.1) / 100
sabit_loss_ys = percenval_most_indikator_short//input.float(defval = 1.9       , title = "_short zarar (%)" , step=0.1, minval=0.1) / 100
vwap_gosterge_filtre_long_most = input.bool(true,'Vwap MOST Long filtre => Aktif / Değil', inline="rc2")
vwap_gosterge_secimi_long_most = input.bool(true,'Vwap MOST Long => rsi / cci', inline="rc2")
vwap_gosterge_filtre_short_most = input.bool(true,'Vwap MOST Short filtre => Aktif / Değil', inline="rc3")
vwap_gosterge_secimi_short_most = input.bool(true,'Vwap MOST Short => rsi / cci', inline="rc3")

stop_loss_secimi_long = input.bool(true,'Long Zarar => Sabit / Takipli', inline="rc3")
stop_loss_secimi_short = input.bool(true,'Short Zarar => Sabit / Takipli', inline="rc3")


//slen = 20//input.int(defval=20, title='MA Period', minval=1)

//////////////////////___trade_gunleri_long__//////////////////////////////////////////////
InSession_long (sessionTimes_long , sessionTimeZone_long =syminfo.timezone) =>
    not na(time(timeframe.period, sessionTimes_long , sessionTimeZone_long ))
// Create the session and string inputs
sessionInput = "0000-2359"//input.session("0000-2345", title="Session Times")//, group="Trading Session") 
// Create the session string
//weekdays_long = "Long Günleri"
sadece_yer_icin_long = input.bool(defval=false, title="L_Gün :", inline="dL1")
on_mon_long = input.bool(defval=true, title="Psi", inline="dL1")
on_tue_long = input.bool(defval=true, title="S", inline="dL1")
on_wed_long = input.bool(defval=true, title="Ç", inline="dL1")
on_thu_long = input.bool(defval=true, title="P", inline="dL1")
on_fri_long = input.bool(defval=true, title="C", inline="dL1")
on_sat_long = input.bool(defval=true, title="Csi", inline="dL1")
on_sun_long = input.bool(defval=true, title="P", inline="dL1")

session_weekdays_long = ':'
if on_sun_long
    session_weekdays_long := session_weekdays_long + "1"
if on_mon_long
    session_weekdays_long := session_weekdays_long + "2"
if on_tue_long
    session_weekdays_long := session_weekdays_long + "3"
if on_wed_long
    session_weekdays_long := session_weekdays_long + "4"
if on_thu_long
    session_weekdays_long := session_weekdays_long + "5"
if on_fri_long
    session_weekdays_long := session_weekdays_long + "6"
if on_sat_long
    session_weekdays_long := session_weekdays_long + "7"
tradingSession_long  = sessionInput + session_weekdays_long//":" + daysInput_long 
// Highlight background of bars inside the specified session
bgcolor(InSession_long (tradingSession_long ) ? na : color.new(color.teal, 80))
trade_yap_zaman_long  = InSession_long(tradingSession_long ) ? true : false
//////////////////////___trade_gunleri_long__bitti___/////////////////////////////////////////////////
/////////////////___trade_gunleri_short__//////////////////////////////////////////////////////
InSession_short (sessionTimes_short , sessionTimeZone_short =syminfo.timezone) =>
    not na(time(timeframe.period, sessionTimes_short , sessionTimeZone_short ))
//weekdays_short = "Short Günleri"
sadece_yer_icin_short = input.bool(defval=false, title="S_Gün :", inline="ds1")
on_mon_short = input.bool(defval=true, title="Psi", inline="ds1")
on_tue_short = input.bool(defval=true, title="S", inline="ds1")
on_wed_short = input.bool(defval=true, title="Ç", inline="ds1")
on_thu_short = input.bool(defval=true, title="P", inline="ds1")
on_fri_short = input.bool(defval=true, title="C", inline="ds1")
on_sat_short = input.bool(defval=true, title="Csi", inline="ds1")
on_sun_short = input.bool(defval=true, title="P", inline="ds1")

session_weekdays_short = ':'
if on_sun_short
    session_weekdays_short := session_weekdays_short + "1"
if on_mon_short
    session_weekdays_short := session_weekdays_short + "2"
if on_tue_short
    session_weekdays_short := session_weekdays_short + "3"
if on_wed_short
    session_weekdays_short := session_weekdays_short + "4"
if on_thu_short
    session_weekdays_short := session_weekdays_short + "5"
if on_fri_short
    session_weekdays_short := session_weekdays_short + "6"
if on_sat_short
    session_weekdays_short := session_weekdays_short + "7"
tradingSession_short  = sessionInput + session_weekdays_short//":" + daysInput_short 
// Highlight background of bars inside the specified session
bgcolor(InSession_short (tradingSession_short ) ? na :color.new(color.purple, 80) )
trade_yap_zaman_short  = InSession_short(tradingSession_short ) ? true : false
/////////////////___trade_gunleri_short__bitti//////////////////////////////////////////////////////



//////////////////////////////////////////////////////////////
Amount_1a = input.float(51, "1. Giris %Bütce", minval = 0.01, inline = "31")//, group = ALERTGRP_CRED) //pozisyon_1_yuzde
Amount_2a = input.float(49, "2. Giris %Bütce", minval = 0.01, inline = "31")//, group = ALERTGRP_CRED) //pozisyon_2_yuzde
okx_bot_butcesi = input.int(50,'Okx Bot Bütcesi $', inline = "bb1")
okx_bot_kaldirac = input.int(2,'Okx Bot Kaldirac x', inline = "bb1")

/////////////////////////////////////

OpenDirection  = input.string(defval="BIRLIKTE", title="ISLEM SECIMI", options=["BIRLIKTE", "LONG", "SHORT"])

///////////////////////////////////////////////////////////////////////

Zlema_Func(src, length) =>
    zxLag = length / 2 == math.round(length / 2) ? length / 2 : (length - 1) / 2
    zxEMAData = src + src - src[zxLag]
    ZLEMA = ta.ema(zxEMAData, length)
    ZLEMA
fiyat_zlema = Zlema_Func(close_fiyat,20)
fiyat_alma =ta.alma(close_fiyat,96,8,0.6185)//ta.roc(fiyat_alma2,20) //math.sum(ta.roc(fiyat_alma2,1),1) == -3 and math.sum(ta.roc(fiyat_alma3,1),1) == -2
plot(fiyat_alma,'Fiyat Alma ',color.yellow)  
//////////////////////////////////////////

cro_anatrend= ta.crossover(fiyat_zlema,fiyat_alma)//ta.crossover(anatrend_fiyat, mtf_fiyat_alma)
cru_anatrend= ta.crossunder(fiyat_zlema,fiyat_alma)//ta.crossunder(anatrend_fiyat, mtf_fiyat_alma)
direction_anatrend = 0
direction_anatrend := cro_anatrend ? 1 : cru_anatrend ? -1 : direction_anatrend[1]

//////////////////////////////////////////
vwap_cci_Length = 20//input.int(20, minval=1)
vwap_sma_Length = 9//input.int(9, minval=1)
vwap_cci = ta.cci(ta.vwap(close_fiyat[1]),vwap_cci_Length)
vwap_rsi = ta.rsi(ta.vwap(close_fiyat[1]),vwap_cci_Length)
vwap_sma_gosterge_cci = ta.sma(vwap_cci,vwap_sma_Length)  // Most momentum icin
vwap_sma_gosterge_rsi = ta.sma(vwap_rsi,vwap_sma_Length) // Most momentum icin

vwap_gosterge_cci = vwap_sma_gosterge_cci
vwap_gosterge_rsi = vwap_sma_gosterge_rsi
vwap_gosterge_long_most = vwap_gosterge_secimi_long_most ? vwap_gosterge_rsi : vwap_gosterge_cci
vwap_gosterge_short_most = vwap_gosterge_secimi_short_most ? vwap_gosterge_rsi : vwap_gosterge_cci 
vwap_long_most = vwap_gosterge_secimi_long_most ? (vwap_gosterge_long_most > 70) : (vwap_gosterge_long_most > 50) 
vwap_short_most = vwap_gosterge_secimi_short_most ? (vwap_gosterge_short_most < 30) and not(vwap_gosterge_short_most < 10)  : (vwap_gosterge_short_most < -50)

///////////////////////////////////


//calculation of the most trend price
/////////////////////////////////////
averprice_long = Zlema_Func(close_fiyat, slen_long)//averprice//input(close)
averprice_short = Zlema_Func(close_fiyat, slen_short)
//plot(plot_goster_fiyat ? averprice : na ,title = 'fiyat')

////////////////////////////////////
exMov_indikator_long = averprice_long
fark_indikator_long = exMov_indikator_long * percenval_most_indikator_long //* 0.01
longStop_indikator_long = exMov_indikator_long - fark_indikator_long
longStopPrev_indikator_long = nz(longStop_indikator_long[1], longStop_indikator_long)
longStop_indikator_long := exMov_indikator_long > longStopPrev_indikator_long ? math.max(longStop_indikator_long, longStopPrev_indikator_long) : longStop_indikator_long
shortStop_indikator_long = exMov_indikator_long + fark_indikator_long
shortStopPrev_indikator_long = nz(shortStop_indikator_long[1], shortStop_indikator_long)
shortStop_indikator_long := exMov_indikator_long < shortStopPrev_indikator_long ? math.min(shortStop_indikator_long, shortStopPrev_indikator_long) : shortStop_indikator_long
dir_indikator_long = 1
dir_indikator_long := nz(dir_indikator_long[1], dir_indikator_long)
dir_indikator_long := dir_indikator_long == -1 and exMov_indikator_long > shortStopPrev_indikator_long ? 1 : dir_indikator_long == 1 and exMov_indikator_long < longStopPrev_indikator_long ? -1 : dir_indikator_long
MOST_indikator_long = dir_indikator_long == 1 ? longStop_indikator_long : shortStop_indikator_long
cro_indikator_long = ta.crossover(exMov_indikator_long, MOST_indikator_long)
cru_indikator_long = ta.crossunder(exMov_indikator_long, MOST_indikator_long)
direction_indikator_long = 0
direction_indikator_long := cro_indikator_long ? 1 : cru_indikator_long ? -1 : direction_indikator_long[1]
colorM_indikator_long = direction_indikator_long == 1 ? color.rgb(14, 241, 52) : direction_indikator_long == -1  ? color.red : color.rgb(59, 248, 255)
plot( MOST_indikator_long, color = colorM_indikator_long, linewidth=3, title='MOST_indikator_long')
//plot(exMov_indikator_long, color=colorM_indikator_long, linewidth=2, title='exMov_indikator_long')
////////////////////////////
exMov_indikator_short = averprice_short
fark_indikator_short = exMov_indikator_short * percenval_most_indikator_short //* 0.01
longStop_indikator_short = exMov_indikator_short - fark_indikator_short
longStopPrev_indikator_short = nz(longStop_indikator_short[1], longStop_indikator_short)
longStop_indikator_short := exMov_indikator_short > longStopPrev_indikator_short ? math.max(longStop_indikator_short, longStopPrev_indikator_short) : longStop_indikator_short
shortStop_indikator_short = exMov_indikator_short + fark_indikator_short
shortStopPrev_indikator_short = nz(shortStop_indikator_short[1], shortStop_indikator_short)
shortStop_indikator_short := exMov_indikator_short < shortStopPrev_indikator_short ? math.min(shortStop_indikator_short, shortStopPrev_indikator_short) : shortStop_indikator_short
dir_indikator_short = 1
dir_indikator_short := nz(dir_indikator_short[1], dir_indikator_short)
dir_indikator_short := dir_indikator_short == -1 and exMov_indikator_short > shortStopPrev_indikator_short ? 1 : dir_indikator_short == 1 and exMov_indikator_short < longStopPrev_indikator_short ? -1 : dir_indikator_short
MOST_indikator_short = dir_indikator_short == 1 ? longStop_indikator_short : shortStop_indikator_short
cro_indikator_short= ta.crossover(exMov_indikator_short, MOST_indikator_short)
cru_indikator_short= ta.crossunder(exMov_indikator_short, MOST_indikator_short)
direction_indikator_short = 0
direction_indikator_short := cro_indikator_short ? 1 : cru_indikator_short ? -1 : direction_indikator_short[1]
colorM_indikator_short = direction_indikator_short == 1 ? color.rgb(14, 241, 52) : direction_indikator_short == -1  ? color.red : color.rgb(59, 248, 255)
plot( MOST_indikator_short, color=colorM_indikator_short, linewidth=3, title='MOST_indikator_short')
//plot(exMov_indikator_short, color=colorM_indikator_short, linewidth=2, title='exMov_indikator_short')

/////////////////////////////////

trend_yonu_oto = input.bool(true,'Ana Trend Indikator Pozisyon Sekli (Yonu Devam Eden - Tersi Tekli) => Auto / Manuel', inline="rb")
indikator_long_sekli = input.bool(true,'Indikator Long Manuel => Devam Eden / Tekli', inline="rc")
indikator_short_sekli = input.bool(true,'Indikator Short Manuel => Devam Eden / Tekli', inline="rc") 
longCondition_most_indikator = (indikator_long_sekli == true and not(trend_yonu_oto == true)) or (trend_yonu_oto == true and direction_anatrend == 1) ? direction_indikator_long == 1 and not(low <= MOST_indikator_long): cro_indikator_long and not(low <= MOST_indikator_long)//ta.crossover(averprice, trendprice) //and (averprice[1] < trendprice[1]) //and ( close[1] < averprice[1])
shortCondition_most_indikator = (indikator_short_sekli == true and not(trend_yonu_oto == true)) or (trend_yonu_oto == true and direction_anatrend == -1) ? direction_indikator_short == -1 and not(high >= MOST_indikator_short): cru_indikator_short and not(high >= MOST_indikator_short)//ta.crossunder(averprice , trendprice_short) //and (averprice[1] > trendprice_short[1]) //and ( close[1] > averprice[1])
//////////////////////////////
////////////////////////////
//longCondition_most_indikator = cro_indikator_long//(indikator_long_sekli == true and not(trend_yonu_oto == true)) or (trend_yonu_oto == true and direction_anatrend == 1) ? direction_indikator_long == 1 : cro_indikator_long//ta.crossover(averprice, trendprice) //and (averprice[1] < trendprice[1]) //and ( close[1] < averprice[1])
//shortCondition_most_indikator = cru_indikator_short// or (direction_indikator_short == -1 and ta.crossunder(open,MOST_indikator_short))//(indikator_short_sekli == true and not(trend_yonu_oto == true)) or (trend_yonu_oto == true and direction_anatrend == -1) ? direction_indikator_short == -1 : cru_indikator_short//ta.crossunder(averprice , trendprice_short) //and (averprice[1] > trendprice_short[1]) //and ( close[1] > averprice[1])
//////////////////////////////

//////////////////////////////
tahmin_uzunlugu_1 = 20//input.int(5,title =' 1=' , minval=1,inline='tu')
tahmin_uzunlugu_2 = 40//input.int(8,title =' 2=' , minval=1,inline='tu')
tahmin_uzunlugu_3 = 96//input.int(20,title =' 3=' , minval=1,inline='tu')
//tahmin_kaynak_secimi = ' close '// input.string(' close ',title="TOlası Tepe/Dip Fiyat Kaynak", options=[' close ', ' Zlema '])
tahmin_kaynak_fiyat = close_fiyat// tahmin_kaynak_secimi == ' close ' ? close : Zlema_Func(close,8)
fonk_tepe_dip_tahmin(string gozuksunmu,float tahmin_kaynak_fiyat,string tepe_dip,int tahmin_uzunluk,int gosterge_yeri) =>
    sitil_shape = tepe_dip == "tepe" ? shape.triangledown : tepe_dip == "dip" ? shape.triangleup : na
    sitil_label = tepe_dip == "tepe" ? label.style_triangledown : tepe_dip == "dip" ? label.style_triangleup : na
    //philo = input.string("Lows", "Highs or Lows?", options=["Highs", "Lows"])
    linecolor = color.gray//input.color(color.new(color.gray,0), "Label/Line Color")
    ptransp = 33//input.int(33, "Radar Transparency", minval=0, maxval=100)
    ltransp = 100//input.int(100, "Line Transparency", minval=0, maxval=100)
    n = bar_index

    // Input/2 (Default 5) Length Pivot Cycle
    hcol =  tepe_dip == "tepe" ?color.purple : color.green//input.color(color.purple, "Half Cycle Color", inline="hc")
    cych = tahmin_uzunluk//input.int(5, "Length", inline="hc")
    labh = true//input.bool(true, "Label?", inline="hc")
    labhf = true//input.bool(true, "Forecast?", inline="hc")
    plh = tepe_dip == "tepe" ? ta.pivothigh(tahmin_kaynak_fiyat,cych, cych) : ta.pivotlow(tahmin_kaynak_fiyat,cych, cych) // Define a PL or PH based on L/H Switch in settings
    plhy = tepe_dip == "tepe" ? gosterge_yeri : -(math.abs(gosterge_yeri)) // Position the pivot on the Y axis of the oscillator
    plhi = ta.barssince(plh) // Bars since pivot occured?
    plhp = plhi>cych // Bars since pivot occured greater than cycle length?
    lowhin = tepe_dip == "tepe" ? ta.highest(tahmin_kaynak_fiyat, cych*2) : ta.lowest(tahmin_kaynak_fiyat, cych*2) // Highest/Lowest for the cycle
    lowh = ta.barssince(plh)>cych ? lowhin : na // If the barssince pivot are greater than cycle length, show the uncomnfirmed "pivot tracker"
    //plot(plhy, "Half Cycle Radar Line", color=plhp?hcol:color.new(linecolor,ltransp), offset=(cych*-1), display=display.none) // Cycle detection lines v1
    //plotshape(plh ? plhy : na, "Half Cycle Confirmed", style=sitil_shape, location=location.absolute, color=hcol, size = size.tiny, offset=(cych*-1)) // Past Pivots
    //plotshape(lowh ? plhy : na, "Half Cycle Radar", style=shape.circle, location=location.absolute, color=color.new(hcol, ptransp), size = size.tiny, offset=(cych*-1), show_last=1, display=display.none) // AKA the "Tracker/Radar" v1
    // LuxAlgo pivot average calculation used for the forecast
    barssince_ph = 0
    ph_x2 = ta.valuewhen(plh, n - cych, 1) // x values for pivot
    if plh
        barssince_ph := (n - cych) - ph_x2 // if there is a pivot, then BarsSincePivot = (BarIndex - Cycle Length) - x values for pivot
    avg_barssince_ph = ta.cum(barssince_ph) / ta.cum(math.sign(barssince_ph)) // AvgBarsSincePivot = Sum of the BarsSincePivot divided by (Sum of the number of signs of BarsSincePivot, AKA the number of BarsSincePivots)
    // Draw a diamond forecast label and forecast range line
    tooltiph = "🔄 Pivot Cycle: " + str.tostring(cych) + " bars" +
     "\n⏱ Last Pivot: " + str.tostring(plhi + cych) + " bars ago" + 
     "\n🧮 Average Pivot: " + str.tostring(math.round(avg_barssince_ph)) + " bars" + 
     "\n🔮 Next Pivot: " + str.tostring(math.round(avg_barssince_
Leave a Comment