v5: add timeframe profiles with auto/override + default per-timeframe ATR/Multiplier; README updated
This commit is contained in:
@@ -54,9 +54,13 @@ showFlipLevelLine = input.bool(true, "Show Flip Level line")
|
||||
flipLineAutoColor = input.bool(true, "Flip line color by trend")
|
||||
flipLineCustomCol = input.color(color.new(color.silver, 0), "Flip line custom color")
|
||||
showFlipLevelValue = input.bool(true, "Show Flip Level value label")
|
||||
flipLabelPosOpt = input.string("Flip bar", "Flip Level label position", options=["Current bar","Flip bar"], tooltip="Where to place the Flip Level value label. 'Flip bar' anchors the label to the candle where the last flip occurred so it moves with that candle when you pan the chart.")
|
||||
extendLinesRight = input.bool(false, "Extend lines to right edge", tooltip="If enabled, flip and next-flip lines will extend to the right edge (HUD-style). Disable to keep them glued strictly to candles.")
|
||||
flipLineWidth = input.int(3, "Flip line width", minval=1, maxval=6)
|
||||
nextFlipLineWidth = input.int(2, "Next flip line width", minval=1, maxval=6)
|
||||
labelSizeOpt = input.string("small", "Value label size", options=["tiny","small","normal"])
|
||||
// Global label size derived from option (used by all labels)
|
||||
lblSize = labelSizeOpt == "tiny" ? size.tiny : labelSizeOpt == "small" ? size.small : size.normal
|
||||
// Preview of the next flip thresholds
|
||||
showNextBullFlip = input.bool(true, "Show Next Bull Flip level")
|
||||
showNextBearFlip = input.bool(false, "Show Next Bear Flip level")
|
||||
@@ -359,20 +363,35 @@ downTrend = trend == -1 ? supertrend : na
|
||||
|
||||
// Persistent Flip Level (holds value from last flip until next)
|
||||
var float flipLevel = na
|
||||
var int flipBarIndex = na
|
||||
flipLevel := (flipUp or flipDn) ? supertrend : nz(flipLevel[1])
|
||||
flipBarIndex := (flipUp or flipDn) ? bar_index : nz(flipBarIndex[1])
|
||||
flipLineColor = flipLineAutoColor ? (trend == 1 ? color.new(color.green, 0) : color.new(color.red, 0)) : flipLineCustomCol
|
||||
plot(showFlipLevelLine ? flipLevel : na, title="Flip Level", color=flipLineColor, linewidth=flipLineWidth, style=plot.style_linebr, trackprice=true)
|
||||
plot(showFlipLevelLine ? flipLevel : na, title="Flip Level", color=flipLineColor, linewidth=flipLineWidth, style=plot.style_linebr, trackprice=extendLinesRight)
|
||||
|
||||
// Optional always-visible value label at current bar (high-contrast)
|
||||
var label flipValLbl = na
|
||||
if showFlipLevelValue and not na(flipLevel)
|
||||
if not na(flipValLbl)
|
||||
label.delete(flipValLbl)
|
||||
// High-contrast: black text on green (bull), white text on maroon (bear)
|
||||
flipLblBg = flipLineAutoColor ? (trend == 1 ? color.new(color.green, 0) : color.new(color.maroon, 0)) : flipLineCustomCol
|
||||
flipLblTxt = flipLineAutoColor ? (trend == 1 ? color.black : color.white) : color.white
|
||||
lblSize = labelSizeOpt == "tiny" ? size.tiny : labelSizeOpt == "small" ? size.small : size.normal
|
||||
flipValLbl := label.new(bar_index, flipLevel, text="Flip Level: " + str.tostring(flipLevel, format.mintick), style=label.style_label_left, color=flipLblBg, textcolor=flipLblTxt, yloc=yloc.price, size=lblSize)
|
||||
// Determine x position based on user preference
|
||||
flipLblX = flipLabelPosOpt == "Flip bar" and not na(flipBarIndex) ? flipBarIndex : bar_index
|
||||
if na(flipValLbl)
|
||||
flipValLbl := label.new(flipLblX, flipLevel, text="Flip Level: " + str.tostring(flipLevel, format.mintick), xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_left, color=flipLblBg, textcolor=flipLblTxt, size=lblSize)
|
||||
else
|
||||
label.set_x(flipValLbl, flipLblX)
|
||||
label.set_y(flipValLbl, flipLevel)
|
||||
label.set_text(flipValLbl, "Flip Level: " + str.tostring(flipLevel, format.mintick))
|
||||
label.set_color(flipValLbl, flipLblBg)
|
||||
label.set_textcolor(flipValLbl, flipLblTxt)
|
||||
label.set_style(flipValLbl, label.style_label_left)
|
||||
label.set_size(flipValLbl, lblSize)
|
||||
|
||||
else
|
||||
if not na(flipValLbl)
|
||||
label.delete(flipValLbl)
|
||||
flipValLbl := na
|
||||
|
||||
// Next flip preview levels (dynamic thresholds)
|
||||
nextBullLevel = tsl + aBufferATR * atr // price needed to start bull flip counting
|
||||
@@ -384,23 +403,54 @@ nextBearActive = trend == 1
|
||||
nbCol = color.new(color.lime, 0)
|
||||
nsCol = color.new(color.red, 0)
|
||||
|
||||
plot(showNextBullFlip and nextBullActive ? nextBullLevel : na, title="Next Bull Flip Level", color=nbCol, linewidth=nextFlipLineWidth, style=plot.style_linebr, trackprice=true)
|
||||
plot(showNextBearFlip and nextBearActive ? nextBearLevel : na, title="Next Bear Flip Level", color=nsCol, linewidth=nextFlipLineWidth, style=plot.style_linebr, trackprice=true)
|
||||
plot(showNextBullFlip and nextBullActive ? nextBullLevel : na, title="Next Bull Flip Level", color=nbCol, linewidth=nextFlipLineWidth, style=plot.style_linebr, trackprice=extendLinesRight)
|
||||
plot(showNextBearFlip and nextBearActive ? nextBearLevel : na, title="Next Bear Flip Level", color=nsCol, linewidth=nextFlipLineWidth, style=plot.style_linebr, trackprice=extendLinesRight)
|
||||
|
||||
// Optional live value labels for next flip thresholds (high-contrast)
|
||||
var label nextBullLbl = na
|
||||
var label nextBearLbl = na
|
||||
if showNextFlipValue
|
||||
// Next Bull label lifecycle
|
||||
if showNextBullFlip and nextBullActive and not na(nextBullLevel)
|
||||
if na(nextBullLbl)
|
||||
nextBullLbl := label.new(bar_index, nextBullLevel, text="Next Bull Flip: " + str.tostring(nextBullLevel, format.mintick) + (aConfirmBars > 1 ? " (" + str.tostring(aConfirmBars) + " closes)" : ""), xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_left, color=color.new(color.lime, 0), textcolor=color.black, size=lblSize)
|
||||
else
|
||||
label.set_x(nextBullLbl, bar_index)
|
||||
label.set_y(nextBullLbl, nextBullLevel)
|
||||
label.set_text(nextBullLbl, "Next Bull Flip: " + str.tostring(nextBullLevel, format.mintick) + (aConfirmBars > 1 ? " (" + str.tostring(aConfirmBars) + " closes)" : ""))
|
||||
label.set_color(nextBullLbl, color.new(color.lime, 0))
|
||||
label.set_textcolor(nextBullLbl, color.black)
|
||||
label.set_style(nextBullLbl, label.style_label_left)
|
||||
label.set_size(nextBullLbl, lblSize)
|
||||
|
||||
else
|
||||
if not na(nextBullLbl)
|
||||
label.delete(nextBullLbl)
|
||||
// Bright lime background with black text for readability
|
||||
nextBullLbl := label.new(bar_index, nextBullLevel, text="Next Bull Flip: " + str.tostring(nextBullLevel, format.mintick) + (aConfirmBars > 1 ? " (" + str.tostring(aConfirmBars) + " closes)" : ""), style=label.style_label_left, color=color.new(color.lime, 0), textcolor=color.black, yloc=yloc.price, size=lblSize)
|
||||
nextBullLbl := na
|
||||
// Next Bear label lifecycle
|
||||
if showNextBearFlip and nextBearActive and not na(nextBearLevel)
|
||||
if na(nextBearLbl)
|
||||
nextBearLbl := label.new(bar_index, nextBearLevel, text="Next Bear Flip: " + str.tostring(nextBearLevel, format.mintick) + (aConfirmBars > 1 ? " (" + str.tostring(aConfirmBars) + " closes)" : ""), xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_left, color=color.new(color.maroon, 0), textcolor=color.white, size=lblSize)
|
||||
else
|
||||
label.set_x(nextBearLbl, bar_index)
|
||||
label.set_y(nextBearLbl, nextBearLevel)
|
||||
label.set_text(nextBearLbl, "Next Bear Flip: " + str.tostring(nextBearLevel, format.mintick) + (aConfirmBars > 1 ? " (" + str.tostring(aConfirmBars) + " closes)" : ""))
|
||||
label.set_color(nextBearLbl, color.new(color.maroon, 0))
|
||||
label.set_textcolor(nextBearLbl, color.white)
|
||||
label.set_style(nextBearLbl, label.style_label_left)
|
||||
label.set_size(nextBearLbl, lblSize)
|
||||
|
||||
else
|
||||
if not na(nextBearLbl)
|
||||
label.delete(nextBearLbl)
|
||||
// Darker red background for contrast
|
||||
nextBearLbl := label.new(bar_index, nextBearLevel, text="Next Bear Flip: " + str.tostring(nextBearLevel, format.mintick) + (aConfirmBars > 1 ? " (" + str.tostring(aConfirmBars) + " closes)" : ""), style=label.style_label_left, color=color.new(color.maroon, 0), textcolor=color.white, yloc=yloc.price, size=lblSize)
|
||||
nextBearLbl := na
|
||||
else
|
||||
if not na(nextBullLbl)
|
||||
label.delete(nextBullLbl)
|
||||
nextBullLbl := na
|
||||
if not na(nextBearLbl)
|
||||
label.delete(nextBearLbl)
|
||||
nextBearLbl := na
|
||||
|
||||
plot(upTrend, "Up Trend", color=color.new(color.green, 0), style=plot.style_linebr, linewidth=2)
|
||||
plot(downTrend, "Down Trend", color=color.new(color.red, 0), style=plot.style_linebr, linewidth=2)
|
||||
|
||||
Reference in New Issue
Block a user