HRM MTF CHOCH OR 1H QML — Strategy by HRM38

By version

Performance Metrics

Description

//version=6strategy("HRM MTF CHOCH OR 1H QML", overlay=true, pyramiding=0, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0.02)//==================================================// INPUTS//==================================================riskPct = input.float(1.0, "Risk %", step=0.1, minval=0.1)rr = input.float(2.0, "Risk/Reward", step=0.1, minval=1.0)pivotLenHTF = input.int(3, "HTF Pivot Length", minval=1)pivotLenLTF = input.int(2, "5m Pivot Length", minval=1)atrLen = input.int(14, "ATR Length", minval=1)atrBufferMult = input.float(0.25, "ATR Buffer", step=0.05)eqToleranceATR = input.float(0.20, "Double Top/Bottom Equality x ATR", step=0.05)qmlToleranceATR = input.float(0.30, "1H QML Tolerance x ATR", step=0.05)cooldownBars = input.int(10, "Cooldown Bars", minval=0)contractMult = input.float(1.0, "Contract Multiplier", step=0.1)sessionAllowed = input.session("1000-2355", "Allowed Session (Istanbul time)")showQML = input.bool(true, "Show 1H QML")//==================================================// ONLY 5M//==================================================is5m = timeframe.isminutes and timeframe.multiplier == 5if not is5m runtime.error("Bu strateji sadece 5 dakikalik grafikte calisir.")//==================================================// SESSION FILTER//==================================================inSession = not na(time(timeframe.period, sessionAllowed, "Europe/Istanbul"))//==================================================// HTF BIAS FUNCTION// Basit market structure bias// 1 = bullish// -1 = bearish// 0 = none//==================================================f_bias(_pivotLen) => ph = ta.pivothigh(high, _pivotLen, _pivotLen) pl = ta.pivotlow(low, _pivotLen, _pivotLen) var float lastPH = na var float lastPL = na var int dir = 0 if not na(ph) lastPH := ph if not na(pl) lastPL := pl if not na(lastPH) and close > lastPH dir := 1 else if not na(lastPL) and close high1 -> lower low -> break high1// bearish QML: high1 -> low1 -> higher high -> break low1//==================================================f_qml(_pivotLen) => ph = ta.pivothigh(high, _pivotLen, _pivotLen) pl = ta.pivotlow(low, _pivotLen, _pivotLen) var float prevPH = na var float lastPH = na var int prevPHBar = na var int lastPHBar = na var float prevPL = na var float lastPL = na var int prevPLBar = na var int lastPLBar = na var int dir = 0 var float qml = na dir := 0 if not na(ph) prevPH := lastPH prevPHBar := lastPHBar lastPH := ph lastPHBar := bar_index - _pivotLen if not na(pl) prevPL := lastPL prevPLBar := lastPLBar lastPL := pl lastPLBar := bar_index - _pivotLen bullQml = not na(prevPL) and not na(lastPH) and not na(lastPL) and prevPLBar lastPH bearQml = not na(prevPH) and not na(lastPL) and not na(lastPH) and prevPHBar prevPH and close necklineLongbearChoch = doubleTop and not na(necklineShort) and close qml1hbearQmlEntry = qmlDir1h == -1 and not na(qml1h) and high >= qml1h - qmlTol and close cooldownBars)flat = strategy.position_size == 0//==================================================// STOPS//==================================================longStopFromChoch = not na(lastSwingLow) ? lastSwingLow - atr * atrBufferMult : nashortStopFromChoch = not na(lastSwingHigh) ? lastSwingHigh + atr * atrBufferMult : nalongStopFromQml = ta.lowest(low, 6) - atr * atrBufferMultshortStopFromQml = ta.highest(high, 6) + atr * atrBufferMultuseLongQmlStop = bullQmlEntry and not bullChochuseShortQmlStop = bearQmlEntry and not bearChochlongStop = useLongQmlStop ? longStopFromQml : longStopFromChochshortStop = useShortQmlStop ? shortStopFromQml : shortStopFromChochlongEntry = closeshortEntry = closelongRisk = longEntry - longStopshortRisk = shortStop - shortEntry//==================================================// POSITION SIZE//==================================================f_qtyFromRisk(entryPrice, stopPrice) => stopDist = math.abs(entryPrice - stopPrice) riskCash = strategy.equity * (riskPct / 100.0) oneUnitRisk = stopDist * syminfo.pointvalue * contractMult qty = oneUnitRisk > 0 ? riskCash / oneUnitRisk : 0.0 qty//==================================================// FINAL VALIDATION//==================================================validLong = flat and inSession and cooldownOk and longBiasOk and longTrigger and not na(longStop) and longRisk > syminfo.mintickvalidShort = flat and inSession and cooldownOk and shortBiasOk and shortTrigger and not na(shortStop) and shortRisk > syminfo.mintick//==================================================// ORDERS//==================================================if validLong qtyLong = f_qtyFromRisk(longEntry, longStop) tpLong = longEntry + longRisk * rr if qtyLong > 0 strategy.entry("Long", strategy.long, qty=qtyLong) strategy.exit("Long Exit", from_entry="Long", stop=longStop, limit=tpLong) lastTradeBar := bar_indexif validShort qtyShort = f_qtyFromRisk(shortEntry, shortStop) tpShort = shortEntry - shortRisk * rr if qtyShort > 0 strategy.entry("Short", strategy.short, qty=qtyShort) strategy.exit("Short Exit", from_entry="Short", stop=shortStop, limit=tpShort) lastTradeBar := bar_index//==================================================// VISUALS// Sinyal oku yok//==================================================qmlColor = qmlDir1h == 1 ? color.lime : qmlDir1h == -1 ? color.red : color.grayplot(showQML and not na(qml1h) ? qml1h : na, "1H QML", color=qmlColor, linewidth=2, style=plot.style_linebr)

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView