Making Label Optional
Posted: Tue Feb 16, 2021 7:50 pm
Hello -
I have this label script and would like to make it optional to display. Where would I place the condition (? and : na)?
This label (dashboard ) is a work in progress, here is the full script
Also is there a better way to do averages?
Thank you and I hope your finding winning trades.
I have this label script and would like to make it optional to display. Where would I place the condition (? and : na)?
Code: Select all
f_print(_text) => var _label = label.new(time, y=na, text=_text, xloc=xloc.bar_time, yloc=yloc.price, color=color.white, style=label.style_label_center,
textcolor=color.black, size=size.large, textalign=text.align_left),
label.set_xy(_label, time + left_rightOffset, highestHigh),
label.set_text(_label, _text),
label.set_color(_label, labelCol),
label.set_textcolor(_label, textCol)
f_print(syminfo.ticker + ", " + timeframe.period + "\n" + atrText + "\n" + kijunText + "\n" + candleSizeTxt + "\n" + perText)
This label (dashboard ) is a work in progress, here is the full script
Code: Select all
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ForexTradingIdeas
//@version=4
study("Watermark Label", shorttitle="Watermark", overlay=true, precision=5)
// Kijun-Sen Line
show_kijun = input(false, title="Show Kijun-Sen Line", type=input.bool)
donchian(len) => avg(lowest(len), highest(len))
kijun_Sen_Line = donchian(26)
plot (show_kijun ? kijun_Sen_Line : na, color= close > kijun_Sen_Line ? color.lime : color.blue, title="Kijun", linewidth=1)
// Watermark Input
// showWaterMrk = input(title="Show WaterMark Details", type=input.bool, defval=true)
title = input(false, title="Determine Watermark Location", type=input.bool)
hhLookback = input(title="Highest High Lookback", type=input.integer, defval=21, minval=1)
up_down_YLoc = input(title="Y Location = HH + ATR Multiple", type=input.float, defval=3.0, step=0.5)
left_right_XLoc = input(title="X Location = # of bars from live bar", type=input.integer, defval=1)
divider = input(false, title=" Dashboard Inputs ", type=input.bool)
// Dashboard input and calculations
atrMult = input(title="ATR Multiplier Factor", type=input.float, defval=1.25, step=0.25, minval=0)
atr = atr(14)
atrMultValue = round(((atr * atrMult) / syminfo.mintick) / 10)
atrText = "ATR * " + tostring(atrMult) + " = " + tostring(atrMultValue)
candleSize = abs((high-low) / syminfo.mintick) / 10
avgCndlSize = (avg(abs(high-low), abs(high[1]-low[1]), abs(high[2]-low[2]), abs(high[3]-low[3]), abs(high[4]-low[4]))) / syminfo.mintick / 10
candleSizeTxt = "Avg[5] Candle Size " + tostring(avgCndlSize) + "\n" + "Current Candle Size " + tostring(candleSize)
bullKijun = close > kijun_Sen_Line
bearKijun = close < kijun_Sen_Line
kijunSignal = iff(bullKijun, "Bullish", "Bearish")
kijunText = "Kijun is " + kijunSignal
perText = "Trade edges, ONLY"
// Watermark Label Calculations
bar_Duration = time - time[1]
left_rightOffset = left_right_XLoc * bar_Duration
highestHigh = highest(high, hhLookback) + (atr(14)) * up_down_YLoc
labelCol = close[1]>open[1] ? color.green : color.red
textCol = close[1]>open[1] ?color.white : color.yellow
// Label - label.new(x, y, text, xloc, yloc, color, style, textcolor, size, textalign, tooltip)
// Label.new variables
f_print(_text) => var _label = label.new(time, y=na, text=_text, xloc=xloc.bar_time, yloc=yloc.price, color=color.white, style=label.style_label_center,
textcolor=color.black, size=size.large, textalign=text.align_left),
label.set_xy(_label, time + left_rightOffset, highestHigh),
label.set_text(_label, _text),
label.set_color(_label, labelCol),
label.set_textcolor(_label, textCol)
f_print(syminfo.ticker + ", " + timeframe.period + "\n" + atrText + "\n" + kijunText + "\n" + candleSizeTxt + "\n" + perText)
Code: Select all
avgCndlSize = (avg(abs(high-low), abs(high[1]-low[1]), abs(high[2]-low[2]), abs(high[3]-low[3]), abs(high[4]-low[4]))) / syminfo.mintick / 10