SuperScript

//@version=6 strategy("SUPERRSI Trend by Taufik", overlay=true) //===================================================== // FILTER TANGGAL //===================================================== startDate = input.time( timestamp("2026-01-01 00:00"), "Tanggal Mulai" ) endDate = input.time( timestamp("2026-12-31 23:59"), "Tanggal Selesai" ) //===================================================== // FILTER JAM //===================================================== startHour = input.int(0, "Jam Mulai", minval=0, maxval=23) startMin = input.int(0, "Menit Mulai", minval=0, maxval=59) endHour = input.int(23, "Jam Selesai", minval=0, maxval=23) endMin = input.int(59, "Menit Selesai", minval=0, maxval=59) //===================================================== // INPUT //===================================================== tfHTF = input.timeframe("30", "TF Supertrend") rsiTF = input.timeframe("5", "TF RSI") atrPeriod = input.int(10, "ATR Length") factor = input.float(3.0, "Factor") lengthRSI = input.int(12, "RSI Length") smoothRSI = input.int(5, "RSI Smoothing") upperLevel = input.int(90, "Level Atas") middleLevel= input.int(50, "Level Tengah") lowerLevel = input.int(10, "Level Bawah") //===================================================== // FILTER WAKTU //===================================================== inDate = time >= startDate and time <= endDate currentMinutes = hour * 60 + minute startMinutes = startHour * 60 + startMin endMinutes = endHour * 60 + endMin inSession = currentMinutes >= startMinutes and currentMinutes <= endMinutes tradeAllowed = inDate and inSession //===================================================== // HEIKEN ASHI SOURCE //===================================================== haTicker = ticker.heikinashi(syminfo.tickerid) //===================================================== // SUPERTRREND HEIKEN ASHI //===================================================== haCloseHTF = request.security(haTicker, tfHTF, close) haHighHTF = request.security(haTicker, tfHTF, high) haLowHTF = request.security(haTicker, tfHTF, low) atrValue = request.security( haTicker, tfHTF, ta.atr(atrPeriod) ) hl2ha = (haHighHTF + haLowHTF) / 2 upperBand = hl2ha + factor * atrValue lowerBand = hl2ha - factor * atrValue var float finalUpper = na var float finalLower = na var int trend = 1 finalUpper := na(finalUpper[1]) ? upperBand : (upperBand < finalUpper[1] or haCloseHTF[1] > finalUpper[1]) ? upperBand : finalUpper[1] finalLower := na(finalLower[1]) ? lowerBand : (lowerBand > finalLower[1] or haCloseHTF[1] < finalLower[1]) ? lowerBand : finalLower[1] trend := na(trend[1]) ? 1 : trend[1] == -1 and haCloseHTF > finalUpper[1] ? 1 : trend[1] == 1 and haCloseHTF < finalLower[1] ? -1 : trend[1] //===================================================== // PLOT SUPERTRREND //===================================================== plot( trend == 1 ? finalLower : na, color=color.lime, linewidth=2, title="Uptrend" ) plot( trend == -1 ? finalUpper : na, color=color.red, linewidth=2, title="Downtrend" ) //===================================================== // CHEBYSHEV FILTER //===================================================== cosh(float x) => (math.exp(x) + math.exp(-x)) / 2 acosh(float x) => x < 1 ? na : math.log(x + math.sqrt(x * x - 1)) sinh(float x) => (math.exp(x) - math.exp(-x)) / 2 asinh(float x) => math.log(x + math.sqrt(x * x + 1)) chebyshevI(float src, float len, float ripple) => a = 0.0 b = 0.0 g = 0.0 cheb = 0.0 a := cosh(1 / len * acosh(1 / (1 - ripple))) b := sinh(1 / len * asinh(1 / ripple)) g := (a - b) / (a + b) cheb := (1 - g) * src + g * nz(cheb[1]) //===================================================== // RSI PRIMED //===================================================== rsi_primed(src, len, smooth)=> close_filtered = chebyshevI(src, smooth, 0.5) up = math.max(ta.change(close_filtered), 0) down = -math.min(ta.change(close_filtered), 0) up_filtered = chebyshevI(up, len, 0.5) down_filtered = chebyshevI(down, len, 0.5) down_filtered == 0 ? 100 : 100 - (100 / (1 + up_filtered / down_filtered)) //===================================================== // RSI MTF //===================================================== rsiOpen = request.security( syminfo.tickerid, rsiTF, rsi_primed(open, lengthRSI, smoothRSI) ) rsiHigh = request.security( syminfo.tickerid, rsiTF, rsi_primed(high, lengthRSI, smoothRSI) ) rsiLow = request.security( syminfo.tickerid, rsiTF, rsi_primed(low, lengthRSI, smoothRSI) ) rsiClose = request.security( syminfo.tickerid, rsiTF, rsi_primed(close, lengthRSI, smoothRSI) ) //===================================================== // RSI HEIKEN ASHI //===================================================== haCloseRSI = (rsiOpen + rsiHigh + rsiLow + rsiClose) / 4 var float haOpenRSI = na haOpenRSI := na(haOpenRSI[1]) ? (rsiOpen + rsiClose) / 2 : (haOpenRSI[1] + haCloseRSI[1]) / 2 haHighRSI = math.max( rsiHigh, math.max(haOpenRSI, haCloseRSI) ) haLowRSI = math.min( rsiLow, math.min(haOpenRSI, haCloseRSI) ) //===================================================== // PLOT RSI //===================================================== candleColor = haCloseRSI >= haOpenRSI ? color.lime : color.red plotcandle( haOpenRSI, haHighRSI, haLowRSI, haCloseRSI, title="RSI Primed HA", color=candleColor, wickcolor=candleColor, bordercolor=candleColor ) //===================================================== // LEVEL //===================================================== hline(upperLevel, "90", color=color.red) hline(middleLevel, "50", color=color.gray) hline(lowerLevel, "10", color=color.lime) //===================================================== // TREND FILTER //===================================================== uptrendCondition = haCloseHTF > finalLower downtrendCondition = haCloseHTF < finalUpper //===================================================== // ENTRY //===================================================== buyEntry = tradeAllowed and uptrendCondition and haLowRSI <= lowerLevel sellEntry = tradeAllowed and downtrendCondition and haHighRSI >= upperLevel //===================================================== // EXIT //===================================================== closeBuy = haHighRSI >= upperLevel closeSell = haLowRSI <= lowerLevel //===================================================== // EXECUTION //===================================================== if buyEntry and strategy.position_size <= 0 strategy.entry("BUY", strategy.long) if sellEntry and strategy.position_size >= 0 strategy.entry("SELL", strategy.short) if strategy.position_size > 0 and closeBuy strategy.close("BUY") if strategy.position_size < 0 and closeSell strategy.close("SELL") //===================================================== // SIGNAL //===================================================== plotshape( buyEntry, title="BUY", style=shape.labelup, location=location.belowbar, color=color.lime, text="BUY" ) plotshape( sellEntry, title="SELL", style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL" )

Komentar

Postingan populer dari blog ini

Script

Kode taufik (2)

RSI Primed