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:
@@ -13,6 +13,8 @@ strategy(
|
|||||||
calc_on_every_tick=false
|
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
|
// 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.")
|
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
|
multiplier = profileBucket == "Single" ? multiplierSingle : profileBucket == "Minutes" ? mult_m : profileBucket == "Hours" ? mult_h : profileBucket == "Daily" ? mult_d : mult_w
|
||||||
activeProfile := profileBucket
|
activeProfile := profileBucket
|
||||||
|
|
||||||
// Core Money Line logic (unchanged from v1)
|
// Core Money Line logic (with selectable source)
|
||||||
atr = ta.atr(atrPeriod)
|
haTicker = ticker.heikinashi(syminfo.tickerid)
|
||||||
src = (high + low) / 2
|
[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)
|
up = src - (multiplier * atr)
|
||||||
dn = src + (multiplier * atr)
|
dn = src + (multiplier * atr)
|
||||||
@@ -94,8 +104,8 @@ var float dn1 = na
|
|||||||
up1 := nz(up1[1], up)
|
up1 := nz(up1[1], up)
|
||||||
dn1 := nz(dn1[1], dn)
|
dn1 := nz(dn1[1], dn)
|
||||||
|
|
||||||
up1 := close[1] > up1 ? math.max(up, up1) : up
|
up1 := calcC[1] > up1 ? math.max(up, up1) : up
|
||||||
dn1 := close[1] < dn1 ? math.min(dn, dn1) : dn
|
dn1 := calcC[1] < dn1 ? math.min(dn, dn1) : dn
|
||||||
|
|
||||||
var int trend = 1
|
var int trend = 1
|
||||||
var float tsl = na
|
var float tsl = na
|
||||||
@@ -104,10 +114,10 @@ tsl := nz(tsl[1], up1)
|
|||||||
|
|
||||||
if trend == 1
|
if trend == 1
|
||||||
tsl := math.max(up1, tsl)
|
tsl := math.max(up1, tsl)
|
||||||
trend := close < tsl ? -1 : 1
|
trend := calcC < tsl ? -1 : 1
|
||||||
else
|
else
|
||||||
tsl := math.min(dn1, tsl)
|
tsl := math.min(dn1, tsl)
|
||||||
trend := close > tsl ? 1 : -1
|
trend := calcC > tsl ? 1 : -1
|
||||||
|
|
||||||
supertrend = tsl
|
supertrend = tsl
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
//@version=5
|
//@version=5
|
||||||
indicator("Bullmania Money Line v5", overlay=true)
|
indicator("Bullmania Money Line v5", overlay=true)
|
||||||
|
|
||||||
|
// 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 the line calculation.")
|
||||||
|
|
||||||
// Parameter Mode
|
// 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.")
|
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.")
|
||||||
|
|
||||||
@@ -63,9 +66,18 @@ atrPeriod = profileBucket == "Single" ? atrPeriodSingle : profileBucket == "Minu
|
|||||||
multiplier = profileBucket == "Single" ? multiplierSingle : profileBucket == "Minutes" ? mult_m : profileBucket == "Hours" ? mult_h : profileBucket == "Daily" ? mult_d : mult_w
|
multiplier = profileBucket == "Single" ? multiplierSingle : profileBucket == "Minutes" ? mult_m : profileBucket == "Hours" ? mult_h : profileBucket == "Daily" ? mult_d : mult_w
|
||||||
activeProfile := profileBucket
|
activeProfile := profileBucket
|
||||||
|
|
||||||
// Core Money Line logic (unchanged from v1)
|
// Core Money Line logic (with selectable source)
|
||||||
atr = ta.atr(atrPeriod)
|
// Build selected source OHLC
|
||||||
src = (high + low) / 2
|
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)
|
up = src - (multiplier * atr)
|
||||||
dn = src + (multiplier * atr)
|
dn = src + (multiplier * atr)
|
||||||
@@ -76,8 +88,8 @@ var float dn1 = na
|
|||||||
up1 := nz(up1[1], up)
|
up1 := nz(up1[1], up)
|
||||||
dn1 := nz(dn1[1], dn)
|
dn1 := nz(dn1[1], dn)
|
||||||
|
|
||||||
up1 := close[1] > up1 ? math.max(up, up1) : up
|
up1 := calcC[1] > up1 ? math.max(up, up1) : up
|
||||||
dn1 := close[1] < dn1 ? math.min(dn, dn1) : dn
|
dn1 := calcC[1] < dn1 ? math.min(dn, dn1) : dn
|
||||||
|
|
||||||
var int trend = 1
|
var int trend = 1
|
||||||
var float tsl = na
|
var float tsl = na
|
||||||
@@ -86,10 +98,10 @@ tsl := nz(tsl[1], up1)
|
|||||||
|
|
||||||
if trend == 1
|
if trend == 1
|
||||||
tsl := math.max(up1, tsl)
|
tsl := math.max(up1, tsl)
|
||||||
trend := close < tsl ? -1 : 1
|
trend := calcC < tsl ? -1 : 1
|
||||||
else
|
else
|
||||||
tsl := math.min(dn1, tsl)
|
tsl := math.min(dn1, tsl)
|
||||||
trend := close > tsl ? 1 : -1
|
trend := calcC > tsl ? 1 : -1
|
||||||
|
|
||||||
supertrend = tsl
|
supertrend = tsl
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user