Funções de Input
6 funções para criar parâmetros configuráveis
Funções de Input (6 funções)
input.int(default, options) - Cria parâmetro de entrada inteiro
var length = input.int(14, title="Period", minval=1, maxval=200)
var level = input.int(100, title="Level", step=10, tooltip="Overbought level")
var rsi = ta.rsi(close, length)Opções disponíveis:
title: Rótulo do parâmetrominval: Valor mínimo permitidomaxval: Valor máximo permitidostep: Incremento para controles de UItooltip: Texto de ajuda
input.float(default, options) - Cria parâmetro de entrada decimal
var factor = input.float(0.5, title="Factor", minval=0.0, maxval=1.0)
var multiplier = input.float(2.5, title="Multiplier", step=0.1, tooltip="ATR multiplier")
var atr = ta.atr(high, low, close, 14)
var stopLoss = close - multiplier * atrOpções disponíveis: Mesmas de input.int
input.bool(default, options) - Cria parâmetro de entrada booleano
var showLabels = input.bool(true, title="Show Labels")
var enableAlerts = input.bool(false, title="Enable Alerts", tooltip="Alert on signal")
if showLabels
plot(sma, "SMA")Opções disponíveis:
title: Rótulo do parâmetrotooltip: Texto de ajuda
input.string(default, options) - Cria parâmetro de entrada texto
var symbol = input.string("BTCUSDT", title="Symbol")
var maType = input.string("SMA", title="MA Type", options=["SMA", "EMA", "WMA"], tooltip="Moving average type")
// Usar maType para selecionar função
var ma = maType == "SMA" ? ta.sma(close, 20) :
maType == "EMA" ? ta.ema(close, 20) :
ta.wma(close, 20)Opções disponíveis:
title: Rótulo do parâmetrooptions: Array de valores permitidos (cria dropdown)tooltip: Texto de ajuda
input.source(default, options) - Seleciona fonte de dados (série de preço)
// Permite usuário escolher entre close, open, high, low, etc.
var src = input.source(close, title="Source")
var ma = ta.sma(src, 20)Nota: Na implementação atual,
input.sourceestá documentado mas pode ser implementado comoinput.stringcom opções predefinidas
input.color(default, options) - Cria parâmetro de entrada de cor
Sintaxe:
input.color(defval, title?, tooltip?, inline?, group?) → input colorParâmetros:
defval(color): Cor padrão (hex como "#FF0000" ou constante como color.red)title(string, opcional): Rótulo do parâmetrotooltip(string, opcional): Texto de ajudainline(string, opcional): ID de agrupamento inline (coloca inputs na mesma linha)group(string, opcional): Nome do grupo para organização
Retorna: input color
Exemplo:
// Cores configuráveis para estratégia
bullColor = input.color("#09ff00", title="Bullish Color", group="Style", inline="c")
bearColor = input.color("#FF0000", title="Bearish Color", group="Style", inline="c")
neutralColor = input.color("#2962FF", title="Neutral Color", group="Style")
// Usar em plots
trend = close > ta.sma(close, 20)
plotColor = trend ? bullColor : bearColor
plot(close, "Price", color=plotColor)
// Combinar com transparência
transparentBull = color.new(bullColor, 70)
fill(upperBand, lowerBand, color=transparentBull)Uso Comum:
- Temas customizáveis para indicators
- Heatmaps e gradientes configuráveis
- Estratégias com cores personalizadas
- Integração com color.new() e color.from_gradient()