IMACD nya (16/6)

 //@version=5

strategy("Impulse MACD Strategy [Custom]", shorttitle="IMACD_Strat", overlay=false, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)


// === INPUT PARAMETERS ===

lengthMA = input.int(15, title="Length MA")

lengthSignal = input.int(8, title="Length Signal")


// === INPUT FILTER WAKTU PENGUJIAN (BACKTEST RANGE) ===

string g_time = "Filter Periode Backtest"

startDate  = input.int(1, title="Dari Tanggal", group=g_time)

startMonth = input.int(1, title="Dari Bulan", group=g_time)

startYear  = input.int(2020, title="Dari Tahun", group=g_time)


endDate    = input.int(31, title="Sampai Tanggal", group=g_time)

endMonth   = input.int(12, title="Sampai Bulan", group=g_time)

endYear    = input.int(2026, title="Sampai Tahun", group=g_time)


// === INPUT FILTER JAM TRADING HARIAN ===

string g_session = "Filter Jam Trading Harian"

timeSession = input.session("0500-2359", title="Sesi Jam Trading", group=g_session, tooltip="Format: HHMM-HHMM (Contoh: 0500-2359)")

timeZone    = input.string("GMT+7", title="Zona Waktu", group=g_session, options=["GMT+7", "UTC", "Exchange"], tooltip="Pilih GMT+7 untuk WIB")


// 1. Cek rentang tahun/tanggal backtest

inDateRange = time >= timestamp(timeZone == "Exchange" ? syminfo.timezone : timeZone, startYear, startMonth, startDate, 0, 0, 0) and 

              time <= timestamp(timeZone == "Exchange" ? syminfo.timezone : timeZone, endYear, endMonth, endDate, 23, 59, 59)


// 2. Cek rentang jam harian (Senin-Minggu: 1234567)

tzString = timeZone == "Exchange" ? syminfo.timezone : timeZone

inDailySession = not na(time(timeframe.period, timeSession + ":1234567", tzString))


// Gabungkan kedua kondisi waktu

inTimeRange = inDateRange and inDailySession


// === FUNCTIONS ===

calc_smma(src, len) =>

    var float smma = na

    smma := na(smma[1]) ? ta.sma(src, len) : (smma[1] * (len - 1) + src) / len

    smma


calc_zlema(src, length) =>

    ema1 = ta.ema(src, length)

    ema2 = ta.ema(ema1, length)

    d = ema1 - ema2

    ema1 + d


// === LOGIC IMPULSE MACD ===

src = hlc3

hi = calc_smma(high, lengthMA)

lo = calc_smma(low, lengthMA)

mi = calc_zlema(src, lengthMA) 


md = (mi > hi) ? (mi - hi) : (mi < lo) ? (mi - lo) : 0

sb = ta.sma(md, lengthSignal)

sh = md - sb


// Batasan Warna

mdc = src > mi ? (src > hi ? color.lime : color.green) : (src < lo ? color.red : color.orange)


// === PLOT INDICATOR ===

plot(0, color=color.gray, linewidth=1, title="MidLine")

plot(md, color=mdc, linewidth=2, title="ImpulseMACD", style=plot.style_histogram)

plot(sh, color=color.blue, linewidth=2, title="ImpulseHisto", style=plot.style_histogram)

plot(sb, color=color.maroon, linewidth=2, title="ImpulseMACDCDSignal")


ebc = input.bool(false, title="Enable bar colors")

barcolor(ebc ? mdc : na)


// === LOGIKA TRADING ===

buyCondition  = md > 0

sellCondition = md < 0


// Eksekusi Order (Hanya berjalan jika masuk dalam rentang waktu & jam harian)

if (inTimeRange)

    if (buyCondition)

        strategy.entry("Buy", strategy.long)

        

    if (sellCondition)

        strategy.entry("Sell", strategy.short)


// Otomatis close semua posisi jika di luar jam trading harian atau periode habis

if (not inTimeRange)

    strategy.close_all(comment="Di luar Jam/Periode")

Komentar

Postingan populer dari blog ini

Script

Kode taufik (2)

RSI Primed