v5: add Calculation source toggle (Chart vs Heikin Ashi) with ATR computed from selected OHLC; strategy uses HA signals but fills on chart bars

This commit is contained in:
root
2025-10-18 20:59:41 +02:00
parent d5c8b8b34a
commit e1067f211a
2 changed files with 36 additions and 14 deletions

View File

@@ -13,6 +13,8 @@ strategy(
calc_on_every_tick=false
)
// Calculation source (Chart vs Heikin Ashi)
srcMode = input.string("Chart", "Calculation source", options=["Chart","Heikin Ashi"], tooltip="Use regular chart candles or Heikin Ashi for signal calculation. Fills occur on chart bars.")
// Parameter Mode
paramMode = input.string("Profiles by timeframe", "Parameter Mode", options=["Single", "Profiles by timeframe"], tooltip="Choose whether to use one global set of parameters or timeframe-specific profiles.")
@@ -81,9 +83,17 @@ atrPeriod = profileBucket == "Single" ? atrPeriodSingle : profileBucket == "Minu
multiplier = profileBucket == "Single" ? multiplierSingle : profileBucket == "Minutes" ? mult_m : profileBucket == "Hours" ? mult_h : profileBucket == "Daily" ? mult_d : mult_w
activeProfile := profileBucket
// Core Money Line logic (unchanged from v1)
atr = ta.atr(atrPeriod)
src = (high + low) / 2
// Core Money Line logic (with selectable source)
haTicker = ticker.heikinashi(syminfo.tickerid)
[haO, haH, haL, haC] = request.security(haTicker, timeframe.period, [open, high, low, close], lookahead=barmerge.lookahead_off)
calcH = srcMode == "Heikin Ashi" ? haH : high
calcL = srcMode == "Heikin Ashi" ? haL : low
calcC = srcMode == "Heikin Ashi" ? haC : close
// ATR on selected source
tr = math.max(calcH - calcL, math.max(math.abs(calcH - calcC[1]), math.abs(calcL - calcC[1])))
atr = ta.rma(tr, atrPeriod)
src = (calcH + calcL) / 2
up = src - (multiplier * atr)
dn = src + (multiplier * atr)
@@ -94,8 +104,8 @@ var float dn1 = na
up1 := nz(up1[1], up)
dn1 := nz(dn1[1], dn)
up1 := close[1] > up1 ? math.max(up, up1) : up
dn1 := close[1] < dn1 ? math.min(dn, dn1) : dn
up1 := calcC[1] > up1 ? math.max(up, up1) : up
dn1 := calcC[1] < dn1 ? math.min(dn, dn1) : dn
var int trend = 1
var float tsl = na
@@ -104,10 +114,10 @@ tsl := nz(tsl[1], up1)
if trend == 1
tsl := math.max(up1, tsl)
trend := close < tsl ? -1 : 1
trend := calcC < tsl ? -1 : 1
else
tsl := math.min(dn1, tsl)
trend := close > tsl ? 1 : -1
trend := calcC > tsl ? 1 : -1
supertrend = tsl