OPEN-SOURCE SCRIPT
new_youtube_strategy

//version=5
strategy("Dow + Homma 1m Scalper (15m filter)", overlay=true, margin_long=100, margin_short=100, initial_capital=10000)
//===== INPUTS =====
maLen = input.int(50, "Trend SMA Length", minval=5)
htf_tf = input.timeframe("15", "Higher TF")
priceTolPct = input.float(0.05, "SR tolerance %", step=0.01)
wickFactor = input.float(2.0, "Hammer/ShootingStar wick factor", step=0.1)
dojiThresh = input.float(0.1, "Doji body % of range", step=0.01)
risk_RR = input.float(2.0, "Reward:Risk", step=0.1)
capitalRiskPct = input.float(1.0, "Risk % of equity per trade", step=0.1)
//===== 1m TREND (SMA) =====
sma1 = ta.sma(close, maLen)
sma1Up = sma1 > sma1[1]
sma1Down = sma1 < sma1[1]
uptrend1 = close > sma1 and sma1Up
downtrend1 = close < sma1 and sma1Down
//===== 15m TREND VIA request.security =====
sma15 = request.security(syminfo.tickerid, htf_tf, ta.sma(close, maLen), lookahead=barmerge.lookahead_off)
sma15Up = sma15 > sma15[1]
sma15Down = sma15 < sma15[1]
uptrend15 = close > sma15 and sma15Up
downtrend15 = close < sma15 and sma15Down
//===== SWING HIGHS/LOWS (LOCAL EXTREMA) =====
var int left = 3
var int right = 3
swHigh = ta.pivothigh(high, left, right)
swLow = ta.pivotlow(low, left, right)
//===== SR FLIP LEVELS =====
var float srSupport = na
var float srResistance = na
// when a swing high is broken -> new support
if not na(swHigh)
if close > swHigh
srSupport := swHigh
// when a swing low is broken -> new resistance
if not na(swLow)
if close < swLow
srResistance := swLow
//===== CANDLE METRICS =====
body = math.abs(close - open)
cRange = high - low
upperW = high - math.max(open, close)
lowerW = math.min(open, close) - low
isBull() => close > open
isBear() => close < open
bullHammer() =>
cRange > 0 and
isBull() and
lowerW >= wickFactor * body and
upperW <= body
bearShootingStar() =>
cRange > 0 and
isBear() and
upperW >= wickFactor * body and
lowerW <= body
isDoji() =>
cRange > 0 and body <= dojiThresh * cRange
bullEngulfing() =>
isBear()[1] and isBull() and
open <= close[1] and close >= open[1]
bearEngulfing() =>
isBull()[1] and isBear() and
open >= close[1] and close <= open[1]
//===== SR PROXIMITY =====
tol = priceTolPct * 0.01 * close
nearSupport = not na(srSupport) and math.abs(close - srSupport) <= tol
nearResistance = not na(srResistance) and math.abs(close - srResistance) <= tol
//===== SIGNAL CONDITIONS =====
bullCandle = bullHammer() or isDoji() or bullEngulfing()
bearCandle = bearShootingStar() or isDoji() or bearEngulfing()
longTrendOK = uptrend1 and uptrend15
shortTrendOK = downtrend1 and downtrend15
longSignal = longTrendOK and nearSupport and bullCandle
shortSignal = shortTrendOK and nearResistance and bearCandle
//===== POSITION SIZING (IN RISK UNITS) =====
var float lastEquity = strategy.equity
riskCapital = strategy.equity * (capitalRiskPct * 0.01)
//===== ENTRY / EXIT PRICES =====
longStop = math.min(low, nz(srSupport, low))
longRisk = close - longStop
longTP = close + risk_RR * longRisk
shortStop = math.max(high, nz(srResistance, high))
shortRisk = shortStop - close
shortTP = close - risk_RR * shortRisk
// qty in contracts (approx; assumes price * qty ≈ capital used)
longQty = longRisk > 0 ? riskCapital / longRisk : 0.0
shortQty = shortRisk > 0 ? riskCapital / shortRisk : 0.0
//===== EXECUTION =====
if longSignal and longRisk > 0 and longQty > 0
strategy.entry("Long", strategy.long, qty=longQty)
strategy.exit("Long TP/SL", from_entry="Long", stop=longStop, limit=longTP)
if shortSignal and shortRisk > 0 and shortQty > 0
strategy.entry("Short", strategy.short, qty=shortQty)
strategy.exit("Short TP/SL", from_entry="Short", stop=shortStop, limit=shortTP)
//===== PLOTS =====
plot(sma1, color=color.orange, title="SMA 1m")
plot(sma15, color=color.blue, title="HTF SMA (15m)")
plot(srSupport, "SR Support", color=color.new(color.green, 50), style=plot.style_linebr)
plot(srResistance,"SR Resistance",color=color.new(color.red, 50), style=plot.style_linebr)
// Visual debug for signals
plotshape(longSignal, title="Long Signal", style=shape.triangleup, location=location.belowbar, color=color.lime, size=size.tiny)
plotshape(shortSignal, title="Short Signal", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.tiny)
strategy("Dow + Homma 1m Scalper (15m filter)", overlay=true, margin_long=100, margin_short=100, initial_capital=10000)
//===== INPUTS =====
maLen = input.int(50, "Trend SMA Length", minval=5)
htf_tf = input.timeframe("15", "Higher TF")
priceTolPct = input.float(0.05, "SR tolerance %", step=0.01)
wickFactor = input.float(2.0, "Hammer/ShootingStar wick factor", step=0.1)
dojiThresh = input.float(0.1, "Doji body % of range", step=0.01)
risk_RR = input.float(2.0, "Reward:Risk", step=0.1)
capitalRiskPct = input.float(1.0, "Risk % of equity per trade", step=0.1)
//===== 1m TREND (SMA) =====
sma1 = ta.sma(close, maLen)
sma1Up = sma1 > sma1[1]
sma1Down = sma1 < sma1[1]
uptrend1 = close > sma1 and sma1Up
downtrend1 = close < sma1 and sma1Down
//===== 15m TREND VIA request.security =====
sma15 = request.security(syminfo.tickerid, htf_tf, ta.sma(close, maLen), lookahead=barmerge.lookahead_off)
sma15Up = sma15 > sma15[1]
sma15Down = sma15 < sma15[1]
uptrend15 = close > sma15 and sma15Up
downtrend15 = close < sma15 and sma15Down
//===== SWING HIGHS/LOWS (LOCAL EXTREMA) =====
var int left = 3
var int right = 3
swHigh = ta.pivothigh(high, left, right)
swLow = ta.pivotlow(low, left, right)
//===== SR FLIP LEVELS =====
var float srSupport = na
var float srResistance = na
// when a swing high is broken -> new support
if not na(swHigh)
if close > swHigh
srSupport := swHigh
// when a swing low is broken -> new resistance
if not na(swLow)
if close < swLow
srResistance := swLow
//===== CANDLE METRICS =====
body = math.abs(close - open)
cRange = high - low
upperW = high - math.max(open, close)
lowerW = math.min(open, close) - low
isBull() => close > open
isBear() => close < open
bullHammer() =>
cRange > 0 and
isBull() and
lowerW >= wickFactor * body and
upperW <= body
bearShootingStar() =>
cRange > 0 and
isBear() and
upperW >= wickFactor * body and
lowerW <= body
isDoji() =>
cRange > 0 and body <= dojiThresh * cRange
bullEngulfing() =>
isBear()[1] and isBull() and
open <= close[1] and close >= open[1]
bearEngulfing() =>
isBull()[1] and isBear() and
open >= close[1] and close <= open[1]
//===== SR PROXIMITY =====
tol = priceTolPct * 0.01 * close
nearSupport = not na(srSupport) and math.abs(close - srSupport) <= tol
nearResistance = not na(srResistance) and math.abs(close - srResistance) <= tol
//===== SIGNAL CONDITIONS =====
bullCandle = bullHammer() or isDoji() or bullEngulfing()
bearCandle = bearShootingStar() or isDoji() or bearEngulfing()
longTrendOK = uptrend1 and uptrend15
shortTrendOK = downtrend1 and downtrend15
longSignal = longTrendOK and nearSupport and bullCandle
shortSignal = shortTrendOK and nearResistance and bearCandle
//===== POSITION SIZING (IN RISK UNITS) =====
var float lastEquity = strategy.equity
riskCapital = strategy.equity * (capitalRiskPct * 0.01)
//===== ENTRY / EXIT PRICES =====
longStop = math.min(low, nz(srSupport, low))
longRisk = close - longStop
longTP = close + risk_RR * longRisk
shortStop = math.max(high, nz(srResistance, high))
shortRisk = shortStop - close
shortTP = close - risk_RR * shortRisk
// qty in contracts (approx; assumes price * qty ≈ capital used)
longQty = longRisk > 0 ? riskCapital / longRisk : 0.0
shortQty = shortRisk > 0 ? riskCapital / shortRisk : 0.0
//===== EXECUTION =====
if longSignal and longRisk > 0 and longQty > 0
strategy.entry("Long", strategy.long, qty=longQty)
strategy.exit("Long TP/SL", from_entry="Long", stop=longStop, limit=longTP)
if shortSignal and shortRisk > 0 and shortQty > 0
strategy.entry("Short", strategy.short, qty=shortQty)
strategy.exit("Short TP/SL", from_entry="Short", stop=shortStop, limit=shortTP)
//===== PLOTS =====
plot(sma1, color=color.orange, title="SMA 1m")
plot(sma15, color=color.blue, title="HTF SMA (15m)")
plot(srSupport, "SR Support", color=color.new(color.green, 50), style=plot.style_linebr)
plot(srResistance,"SR Resistance",color=color.new(color.red, 50), style=plot.style_linebr)
// Visual debug for signals
plotshape(longSignal, title="Long Signal", style=shape.triangleup, location=location.belowbar, color=color.lime, size=size.tiny)
plotshape(shortSignal, title="Short Signal", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.tiny)
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.