Skip to content
TradequixDocsOpen the terminal
OverviewStart here, search, progress
  • Introduction
  • Quickstart
  • How a script runs
  • Types and qualifiers
  • Operators, conditionals and loops
  • Functions and methods
  • Objects and enums
  • Arrays, matrices and maps
  • Strings and colours
  • Time and sessions
  • Bar states
  • Plotting
  • Inputs
  • Technical analysis
  • Drawings and tables
  • Multiple timeframes
  • Strategies
  • Alerts in scripts
  • Repainting
  • The Pine editor
  • Indicator settings
  • Coming from TradingView
  • The data
  • Publish and sell
  • Catalogue and community
  • Your dashboard and earnings
  • Errors and debugging
  • Limits
  • Coverage
  • Built-in catalogue
  • Cookbook
  • Write Pine with AI
  • FAQ
  • Glossary
  • Cheat sheet
  • Function reference
  • Will it run here?
  • Error index

Reference

Cookbook

Complete, runnable recipes to copy and adapt: Heikin Ashi, a squeeze, a trailing stop, divergence, a ribbon, volume spikes and a breakout strategy.

View as MarkdownOpen in ClaudeOpen in ChatGPT

Each recipe is a complete script. Run it here, then Open in editor to try it on the live feed and change it.

Heikin Ashi, computed yourself#

The feed does not serve Heikin Ashi candles, but they are four lines of Pine. This draws them in a pane.

RunnableHeikin Ashi
1//@version=62indicator("Heikin Ashi")3haClose = (open + high + low + close) / 44var float haOpen = na5haOpen := na(haOpen[1]) ? (open + close) / 2 : (haOpen[1] + haClose[1]) / 26haHigh = math.max(high, math.max(haOpen, haClose))7haLow = math.min(low, math.min(haOpen, haClose))8plotcandle(haOpen, haHigh, haLow, haClose, "HA", color = haClose >= haOpen ? color.teal : color.red)

Squeeze: Bollinger inside Keltner#

When the Bollinger Bands contract inside the Keltner Channel, volatility is low and a move often follows.

RunnableSqueeze
1//@version=62indicator("Squeeze")3[bbMid, bbUp, bbLo] = ta.bb(close, 20, 2)4[kcMid, kcUp, kcLo] = ta.kc(close, 20, 1.5)5squeezed = bbUp < kcUp and bbLo > kcLo6mom = ta.linreg(close - ta.sma(close, 20), 20, 0)7plot(mom, "Momentum", style = plot.style_columns, color = mom >= 0 ? color.new(color.teal, 30) : color.new(color.red, 30))8plotshape(squeezed, "Squeeze on", style = shape.circle, location = location.bottom, color = color.orange, size = size.tiny)

ATR trailing stop#

A stop that follows price up and never moves down (for longs), flipping when price crosses it.

RunnableATR trailing stop
1//@version=62indicator("ATR trailing stop", overlay = true)3mult = input.float(3.0, "ATR multiple", minval = 0.5, step = 0.5)4a = ta.atr(14) * mult5var float stop = na6var int dir = 17if dir == 18 stop := math.max(nz(stop, close - a), close - a)9 if close < stop10 dir := -111 stop := close + a12else13 stop := math.min(nz(stop, close + a), close + a)14 if close > stop15 dir := 116 stop := close - a17plot(stop, "Stop", color = dir == 1 ? color.teal : color.red, style = plot.style_linebr, linewidth = 2)

RSI divergence#

Bearish divergence: price makes a higher pivot high while RSI makes a lower one. Pivots are confirmed 5 bars later, so markers are shifted back with offset.

RunnableRSI divergence
1//@version=62indicator("RSI divergence")3r = ta.rsi(close, 14)4lb = 55ph = ta.pivothigh(r, lb, lb)6isPh = not na(ph)7prevR = ta.valuewhen(isPh, r[lb], 1)8prevH = ta.valuewhen(isPh, high[lb], 1)9bear = isPh and r[lb] < prevR and high[lb] > prevH10plot(r, "RSI", color = color.purple)11hline(70, color = color.gray)12hline(30, color = color.gray)13plotshape(bear, "Bearish divergence", style = shape.triangledown, location = location.top, color = color.red, offset = -lb, size = size.small)

Moving average ribbon#

RunnableEMA ribbon
1//@version=62indicator("EMA ribbon", overlay = true)3plot(ta.ema(close, 10), "10", color = color.new(#8b7cff, 0))4plot(ta.ema(close, 20), "20", color = color.new(#a48cf0, 0))5plot(ta.ema(close, 30), "30", color = color.new(#c59bff, 0))6plot(ta.ema(close, 40), "40", color = color.new(#e3a58f, 0))7plot(ta.ema(close, 50), "50", color = color.new(#ffb547, 0))

Volume spikes#

Volume is a tick count here, which makes spikes a good activity signal.

RunnableVolume spikes
1//@version=62indicator("Volume spikes")3avg = ta.sma(volume, 20)4spike = volume > avg * 1.85plot(volume, "Ticks", style = plot.style_columns, color = spike ? color.orange : color.new(color.gray, 60))6plot(avg, "Average", color = color.new(#8b7cff, 0))

Donchian breakout strategy#

RunnableDonchian breakout
1//@version=62strategy("Donchian breakout", overlay = true, initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)3len = input.int(20, "Channel", minval = 5)4upper = ta.highest(high, len)[1]5lower = ta.lowest(low, len)[1]6plot(upper, "Upper", color = color.teal)7plot(lower, "Lower", color = color.red)8if close > upper9 strategy.entry("Long", strategy.long)10if close < lower11 strategy.entry("Short", strategy.short)

Using [1] compares with the channel as it stood before this bar, so a bar cannot break out of a channel that already includes it.

PreviousBuilt-in catalogueNext Write Pine with AI

On this page

  • Heikin Ashi, computed yourself
  • Squeeze: Bollinger inside Keltner
  • ATR trailing stop
  • RSI divergence
  • Moving average ribbon
  • Volume spikes
  • Donchian breakout strategy

Use with AI

View as MarkdownOpen in ClaudeOpen in ChatGPT