BUNU KULLANABİLİRMİYİM DESTEK VERİRSENİZ SEVİNİRİM.

strategy("Backtesting 3commas DCA Bot v2", overlay=true, pyramiding=99, process_orders_on_close=true, commission_type=strategy.commission.percent, commission_value=0.1, initial_capital=1094.56)

// Important Note : Initial Capital above is written to match the default value based on bot parameters.
//                  It is expected the user will update the initial_capital via the GUI Parameters > Properties tab
//                  A warning will displayed in case initial capital and max amount for bot usage do not match.

// ----------------------------------
// Strategy Inputs
// ----------------------------------
take_profit             = input(3.0, type=input.float,  title="Take Profit (%)", minval=0.0, step=0.1)/100
take_profit_type        = input(defval="% from total volume", title="Take Profit Type", options=["% from total volume", "% from base order"])
ttp                     = input(0.5, type=input.float,  title="Trailing Take Profit (%) [0 = Disabled]", minval=0.0, step=0.1)/100
stop_loss               = input(0.0, type=input.float,  title="Stop Loss (%) [0 = Disabled]", minval=0.0, step=0.1)/100
order_size_type         = input(defval="Fixed",         title="Order Size Type", options=["Fixed", "% of equity"])
base_order              = input(100.0, type=input.float,title="Base Order")
safe_order              = input(140.0, type=input.float,title="Safety Order")
max_safe_order          = input(4,                      title="Max Safety Trades Count", minval=0, maxval=99, step=1)
price_deviation         = input(2.0, type=input.float,  title="Price deviation to open safety order (%)", minval=0.0, step=0.1)/100
safe_order_volume_scale = input(1.4, type=input.float,  title="Safety Order Volume Scale", step=0.1)
safe_order_step_scale   = input(1.5, type=input.float,  title="Safety Order Step Scale", step=0.1)
dsc                     = input(defval="RSI-7",         title="Deal Start Condition", options=["Start ASAP", "RSI-7", "TA Presets"])
dsc_rsi_threshold       = input(defval=30,              title="[RSI-7 only] RSI Threshold", minval=1, maxval=99)
dsc_technicals          = input(defval="Strong",        title="[TA Presets only] Strength", options=["Strong", "Weak"])
dsc_res                 = input("",                     title="[RSI-7 and TA Presets Only] Indicator Timeframe", type=input.resolution)
bot_direction           = input(defval="Long",          title="Bot Direction", options=["Long", "Short"])
start_time              = input(defval=timestamp("1 May 2021 06:00"),   title="Start Time",     type=input.time)
end_time                = input(defval=timestamp("31 Dec 2021 20:00"),   title="End Time",       type=input.time)

// ----------------------------------
// Declarations
// ----------------------------------
var bo_level = 0.0
var last_so_level = 0.0
var so_level = 0.0
var ttp_active = false
var ttp_extremum = 0.0
var ttp_level = 0.0
var stop_level = 0.0
var take_profit_level = 0.0
var deal_counter = 0
var stop_loss_counter = 0
var stop_loss_on_bar = false
var latest_price = close
var deal_start_condition = false
var start_time_actual = start_time
var end_time_actual = start_time

// CONSTANTS
var float init_price = na
var IS_LONG = bot_direction == "Long"

 

// ----------------------------------
// Utilities functions
// ----------------------------------
pretty_date(t) => tostring(dayofmonth(t)) + "/" + tostring(month(t)) + "/" + tostring(year(t))

within_window() => time >= start_time and time <= end_time

base_order_size() => order_size_type == "Fixed" ? base_order : base_order/100 * strategy.equity
safe_order_size() => order_size_type == "Fixed" ? safe_order : safe_order/100 * strategy.equity

safety_order_deviation(index) => price_deviation * pow(safe_order_step_scale,  index - 1)

safety_order_price(index, last_safety_order_price) =>
    if IS_LONG
        last_safety_order_price * (1 - safety_order_deviation(index))
    else
        last_safety_order_price * (1 + safety_order_deviation(index))

safety_order_qty(index) => safe_order_size() * pow(safe_order_volume_scale, index - 1)

max_amount_for_bot_usage() =>
    var total_qty = 0.0
    var last_order_qty = 0.0
    total_qty := base_order_size()
    last_order_qty := safe_order_size()
    if max_safe_order > 0
        for index = 1 to max_safe_order
            total_qty := total_qty + safety_order_qty(index)
    total_qty // returned value

max_deviation() =>
    var total_deviation = 0.0
    total_deviation := 0.0
    for index = 1 to max_safe_order
        total_deviation := total_deviation + safety_order_deviation(index)

currency_format() =>
    if syminfo.currency == "USDT" or syminfo.currency == "USD" or syminfo.currency == "TUSD" or syminfo.currency == "BUSD" or syminfo.currency == "USDC" or syminfo.currency == "EUR" or syminfo.currency == "AUD"
        "#.##"
    else if syminfo.currency == "BTC"
        "#.########"
    else
        // TODO (rouxam) list more options
        "#.####"

bot_setup_string() =>
    var ret = ""
    ret := "Deal Start Condition: " + dsc + "\n"
    if ttp > 0.0
        ret := ret + "TTP: " + tostring(take_profit, "#.##%") + "(" + tostring(ttp, "#.##%") + "), "
    else
        ret := ret + "TP: " + tostring(take_profit, "#.##%") + ", "
    ret := ret + "BO: " + tostring(base_order, currency_format()) + " " + (order_size_type == "Fixed" ? "" : "% ") + syminfo.currency + ", "
    ret := ret + "SO: " + tostring(safe_order, currency_format()) + " " + (order_size_type == "Fixed" ? "" : "% ") + syminfo.currency + ", "
    ret := ret + "OS: " + tostring(safe_order_volume_scale) + ", "
    ret := ret + "SS: " + tostring(safe_order_step_scale) + ", "
    ret := ret + "SOS: " + tostring(price_deviation, "#.##%")
    if stop_loss > 0.0
        ret := ret + ", " + "SL: " + tostring(stop_loss, "#.##%")
    ret := ret + "\n"

// ***********************************
// Deal Start Condition Strategies
// ***********************************

// RSI-7
// ***********************************

rsi_signal() =>
    // Regular strat would be crossover but not for 3C DCA Bot
    rsi7 = rsi(close, 7)
    if IS_LONG
        [rsi7 < dsc_rsi_threshold, close]
    else
        [rsi7 > dsc_rsi_threshold, close]

// TA Presets
// ***********************************
// This whole section is from the TradingView "Technical Ratings" code.
// Adding the Technical Ratings "indicator" as input to this "strategy" is not sufficient for our purpose,
// Therefore the code is copy-pasted.
// ***********************************

// Awesome Oscillator
AO() =>
    sma(hl2, 5) - sma(hl2, 34)

// Stochastic RSI
StochRSI() =>
    rsi1 = rsi(close, 14)
    K = sma(stoch(rsi1, rsi1, rsi1, 14), 3)
    D = sma(K, 3)
    [K, D]

// Ultimate Oscillator
tl() => close[1] < low ? close[1]: low
uo(ShortLen, MiddlLen, LongLen) =>
    Value1 = sum(tr, ShortLen)
    Value2 = sum(tr, MiddlLen)
    Value3 = sum(tr, LongLen)
    Value4 = sum(close - tl(), ShortLen)
    Value5 = sum(close - tl(), MiddlLen)
    Value6 = sum(close - tl(), LongLen)
    float UO = na
    if Value1 != 0 and Value2 != 0 and Value3 != 0
        var0 = LongLen / ShortLen
        var1 = LongLen / MiddlLen
        Value7 = (Value4 / Value1) * (var0)
        Value8 = (Value5 / Value2) * (var1)
        Value9 = (Value6 / Value3)
        UO := (Value7 + Value8 + Value9) / (var0 + var1 + 1)
    UO

// Ichimoku Cloud
donchian(len) => avg(lowest(len), highest(len))
ichimoku_cloud() =>
    conversionLine = donchian(9)
    baseLine = donchian(26)
    leadLine1 = avg(conversionLine, baseLine)
    leadLine2 = donchian(52)
    [conversionLine, baseLine, leadLine1, leadLine2]

calcRatingMA(ma, src) => na(ma) or na(src) ? na : (ma == src ? 0 : ( ma < src ? 1 : -1 ))
calcRating(buy, sell) => buy ? 1 : ( sell ? -1 : 0 )

ta_presets_signal() =>
    //============== MA =================
    SMA10 = sma(close, 10)
    SMA20 = sma(close, 20)
    SMA30 = sma(close, 30)
    SMA50 = sma(close, 50)
    SMA100 = sma(close, 100)
    SMA200 = sma(close, 200)
    
    EMA10 = ema(close, 10)
    EMA20 = ema(close, 20)
    EMA30 = ema(close, 30)
    EMA50 = ema(close, 50)
    EMA100 = ema(close, 100)
    EMA200 = ema(close, 200)
    
    HullMA9 = hma(close, 9)
    
    // Volume Weighted Moving Average (VWMA)
    VWMA = vwma(close, 20)
    
    [IC_CLine, IC_BLine, IC_Lead1, IC_Lead2] = ichimoku_cloud()
    
    // ======= Other =============
    // Relative Strength Index, RSI
    RSI = rsi(close,14)
    
    // Stochastic
    lengthStoch = 14
    smoothKStoch = 3
    smoothDStoch = 3
    kStoch = sma(stoch(close, high, low, lengthStoch), smoothKStoch)
    dStoch = sma(kStoch, smoothDStoch)
    
    // Commodity Channel Index, CCI
    CCI = cci(close, 20)
    
    // Average Directional Index
    float adxValue = na, float adxPlus = na, float adxMinus = na
    [P, M, V] = dmi(14, 14)
    adxValue := V
    adxPlus := P
    adxMinus := M
    // Awesome Oscillator
    ao = AO()
    
    // Momentum
    Mom = mom(close, 10)
    // Moving Average Convergence/Divergence, MACD
    [macdMACD, signalMACD, _] = macd(close, 12, 26, 9)
    // Stochastic RSI
    [Stoch_RSI_K, Stoch_RSI_D] = StochRSI()
    // Williams Percent Range
    WR = wpr(14)
    
    // Bull / Bear Power
    BullPower = high - ema(close, 13)
    BearPower = low - ema(close, 13)
    // Ultimate Oscillator
    UO = uo(7,14,28)
    if not na(UO)
        UO := UO * 100
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    PriceAvg = ema(close, 50)
    DownTrend = close < PriceAvg
    UpTrend = close > PriceAvg
    // calculate trading recommendation based on SMA/EMA
    float ratingMA = 0
    float ratingMAC = 0
    
    if not na(SMA10)
        ratingMA := ratingMA + calcRatingMA(SMA10, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA20)
        ratingMA := ratingMA + calcRatingMA(SMA20, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA30)
        ratingMA := ratingMA + calcRatingMA(SMA30, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA50)
        ratingMA := ratingMA + calcRatingMA(SMA50, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA100)
        ratingMA := ratingMA + calcRatingMA(SMA100, close)
        ratingMAC := ratingMAC + 1
    if not na(SMA200)
        ratingMA := ratingMA + calcRatingMA(SMA200, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA10)
        ratingMA := ratingMA + calcRatingMA(EMA10, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA20)
        ratingMA := ratingMA + calcRatingMA(EMA20, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA30)
        ratingMA := ratingMA + calcRatingMA(EMA30, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA50)
        ratingMA := ratingMA + calcRatingMA(EMA50, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA100)
        ratingMA := ratingMA + calcRatingMA(EMA100, close)
        ratingMAC := ratingMAC + 1
    if not na(EMA200)
        ratingMA := ratingMA + calcRatingMA(EMA200, close)
        ratingMAC := ratingMAC + 1
    
    if not na(HullMA9)
        ratingHullMA9 = calcRatingMA(HullMA9, close)
        ratingMA := ratingMA + ratingHullMA9
        ratingMAC := ratingMAC + 1
    
    if not na(VWMA)
        ratingVWMA = calcRatingMA(VWMA, close)
        ratingMA := ratingMA + ratingVWMA
        ratingMAC := ratingMAC + 1
    
    float ratingIC = na
    if not (na(IC_Lead1) or na(IC_Lead2) or na(close) or na(close[1]) or na(IC_BLine) or na(IC_CLine))
        ratingIC := calcRating(
         IC_Lead1 > IC_Lead2 and close > IC_Lead1 and close < IC_BLine and close[1] < IC_CLine and close > IC_CLine,
         IC_Lead2 > IC_Lead1 and close < IC_Lead2 and close > IC_BLine and close[1] > IC_CLine and close < IC_CLine)
    if not na(ratingIC)
        ratingMA := ratingMA + ratingIC
        ratingMAC := ratingMAC + 1
    
    ratingMA := ratingM