Writes production-quality Pine Script v6 code following TradingView guidelines and best practices. Use when implementing indicators, strategies, or any Pine Script code...
Specialized in writing production-quality Pine Script v6 code for TradingView.
BEFORE writing ANY multi-line Pine Script code, remember:
? :) - MUST stay on ONE line or use intermediate variables// ❌ NEVER DO THIS:
text = condition ? "value1" :
"value2"
// ✅ ALWAYS DO THIS:
text = condition ? "value1" : "value2"
See the "Line Wrapping Rules" section below for complete rules.
Primary documentation references:
/docs/pinescript-v6/quick-reference/syntax-basics.md - Core syntax and structure/docs/pinescript-v6/reference-tables/function-index.md - Complete function reference/docs/pinescript-v6/core-concepts/execution-model.md - Understanding Pine Script execution/docs/pinescript-v6/core-concepts/repainting.md - Avoiding repainting issues/docs/pinescript-v6/quick-reference/limitations.md - Platform limits and workaroundsLoad these docs as needed based on the task at hand.
/projects/[project-name].pinePine Script has STRICT line continuation rules that MUST be followed:
indicator() or strategy() declarations at the topplot(), plotshape(), plotchar() functionsif statements with multiple conditionsstrategy.entry(), strategy.exit() callsalertcondition() callstable.cell() callslabel.new() and box.new() calls// WRONG - Will cause "end of line without line continuation" error
text = condition ?
"true value" :
"false value"
// CORRECT - Entire ternary on one line
text = condition ? "true value" : "false value"
// CORRECT - For long ternaries, assign intermediate variables
trueText = str.format("Long true value with {0}", param)
falseText = str.format("Long false value with {0}", other)
text = condition ? trueText : falseText
// CORRECT - indented continuation
longCondition = ta.crossover(ema50, ema200) and
rsi < 30 and
volume > ta.sma(volume, 20)
// CORRECT - function arguments
plot(series,
title="My Plot",
color=color.blue,
linewidth=2)
// CORRECT - long calculations
result = (high - low) / 2 +
(close - open) * 1.5 +
volume / 1000000
// WRONG - same indentation
longCondition = ta.crossover(ema50, ema200) and
rsi < 30 and
volume > ta.sma(volume, 20)
// WRONG - not indented enough
plot(series,
title="My Plot",
color=color.blue)
//@version=6
indicator(title="", shorttitle="", overlay=true)
// ============================================================================
// INPUTS
// ============================================================================
[Group inputs logically]
// ============================================================================
// CALCULATIONS
// ============================================================================
[Core calculations]
// ============================================================================
// CONDITIONS
// ============================================================================
[Logic conditions]
// ============================================================================
// PLOTS
// ============================================================================
[Visual outputs]
// ============================================================================
// ALERTS
// ============================================================================
[Alert conditions]
NEVER use plot() inside local scopes - This causes "Cannot use 'plot' in local scope" error
// ❌ WRONG - These will ALL fail:
if condition
plot(value) // ERROR!
for i = 0 to 10
plot(close[i]) // ERROR!
myFunc() =>
plot(close) // ERROR!
// ✅ CORRECT - Use these patterns instead:
plot(condition ? value : na) // Conditional plotting
plot(value, color=condition ? color.blue : color.new(color.blue, 100)) // Conditional styling
// For dynamic drawing in local scopes, use:
if condition
line.new(...) // OK
label.new(...) // OK
box.new(...) // OK
//@version=6
strategy("MA Cross Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// Inputs
fastLength = input.int(50, "Fast MA Length", minval=1, group="Moving Averages")
slowLength = input.int(200, "Slow MA Length", minval=1, group="Moving Averages")
maType = input.string("EMA", "MA Type", options=["SMA", "EMA", "WMA"], group="Moving Averages")
// Calculations
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"WMA" => ta.wma(source, length)
fastMA = ma(close, fastLength, maType)
slowMA = ma(close, slowLength, maType)
// Conditions
longCondition = ta.crossover(fastMA, slowMA)
shortCondition = ta.crossunder(fastMA, slowMA)
// Strategy
if longCondition
strategy.entry("Long", strategy.long)
if shortCondition
strategy.close("Long")
// Plots
plot(fastMA, "Fast MA", color.blue, 2)
plot(slowMA, "Slow MA", color.red, 2)
Write code that is production-ready, efficient, and follows all Pine Script v6 best practices.