PlotStudio

Write Pine. Debug it like code.

PlotStudio is the scripts workspace of the terminal: an editor, a compiler, a debugger and a backtest for scripts compatible with Pine Script® v3 to v6. They run in your browser, on every plan.

showcase.pine
1//@version=62indicator("Regime Pilot", overlay = true)34// Settings5fastLen = input.int(21, "Fast EMA", minval = 2, group = "Trend ribbon")6slowLen = input.int(55, "Slow EMA", minval = 3, group = "Trend ribbon")7atrLen = input.int(14, "ATR length", minval = 1, group = "Volatility stop")8atrMult = input.float(2.5, "ATR multiple", minval = 0.5, step = 0.25, group = "Volatility stop", tooltip = "How far the stop trails price, in ATRs")9htf = input.timeframe("240", "Confirmation timeframe", group = "Higher timeframe", tooltip = "Signals fire only when price is on the same side of this timeframe's slow EMA")10showDash = input.bool(true, "Show dashboard", group = "Display")1112BULL = #26A69A13BEAR = #EF535014tone(bool up, int transp) => color.new(up ? BULL : BEAR, transp)1516// A stop that ratchets with the trend and flips when a close crosses it17type Stop18    float level19    int dir = 12021method trail(Stop s, float band) =>22    if na(s.level) or (s.dir == 1 and close < s.level) or (s.dir == -1 and close > s.level)23        s.dir := na(s.level) ? 1 : -s.dir24        s.level := s.dir == 1 ? close - band : close + band25    else26        s.level := s.dir == 1 ? math.max(s.level, close - band) : math.min(s.level, close + band)27    s2829fastEma = ta.ema(close, fastLen)30slowEma = ta.ema(close, slowLen)31var stop = Stop.new()32dir = stop.trail(ta.atr(atrLen) * atrMult).dir3334// Higher-timeframe filter: flips against it are only marked, never signalled35htfEma = request.security(syminfo.tickerid, htf, ta.ema(close, slowLen))36htfBull = close > htfEma37flipUp = dir == 1 and dir[1] == -138flipDn = dir == -1 and dir[1] == 139longSignal = flipUp and htfBull40shortSignal = flipDn and close < htfEma4142// Ribbon, stop and regime43ribbonUp = fastEma > slowEma44pFast = plot(fastEma, "Fast EMA", tone(ribbonUp, 0), 2)45pSlow = plot(slowEma, "Slow EMA", tone(ribbonUp, 50), 1)46fill(pFast, pSlow, tone(ribbonUp, 80), "Ribbon")47pStop = plot(dir == dir[1] ? stop.level : na, "Stop", tone(dir == 1, 0), 2, plot.style_linebr)48pMid = plot(hl2, "Mid", display = display.none)49fill(pMid, pStop, tone(dir == 1, 88), "Stop zone")50bgcolor((dir == 1) == htfBull and ribbonUp == htfBull ? tone(htfBull, 94) : na, title = "Aligned regime")5152plotshape(longSignal, "Long", shape.triangleup, location.belowbar, BULL, text = "Long", textcolor = BULL, size = size.small)53plotshape(shortSignal, "Short", shape.triangledown, location.abovebar, BEAR, text = "Short", textcolor = BEAR, size = size.small)54plotshape((flipUp or flipDn) and not (longSignal or shortSignal) ? stop.level : na, "Unconfirmed flip", shape.circle, location.absolute, color.new(color.gray, 30), size = size.tiny)55alertcondition(longSignal, "Long flip", "Regime Pilot: long flip confirmed by the higher timeframe")56alertcondition(shortSignal, "Short flip", "Regime Pilot: short flip confirmed by the higher timeframe")5758// Dashboard59row(table t, int r, string key, string value, color c) =>60    table.cell(t, 0, r, key, text_color = color.gray, text_size = size.small, text_halign = text.align_left)61    table.cell(t, 1, r, value, text_color = c, text_size = size.small, text_halign = text.align_right)6263var dash = table.new(position.top_right, 2, 3, bgcolor = color.new(#131722, 20), border_width = 1)64if showDash and barstate.islast65    row(dash, 0, "Trend", dir == 1 ? "Up" : "Down", tone(dir == 1, 0))66    row(dash, 1, "Higher TF", na(htfEma) ? "n/a" : htfBull ? "Above EMA" : "Below EMA", tone(htfBull, 0))67    row(dash, 2, "Stop dist.", str.tostring(math.abs(close - stop.level) / close * 100, "#.##") + "%", color.silver)

An editor that knows Pine.

It checks your script as you type, and answers from the language itself.

  • Suggestions

    Functions, variables and their parameters as you type, with the signature of each call.

  • Documentation in place

    Hover over a name to read about it, jump to its definition, and search the reference of the language.

  • Problems as you type

    Errors and warnings on their line, before you compile.

  • Editing

    Several cursors, find and replace, lines you move and comment, and a formatter.

  • Versions

    A script keeps the versions you save, and goes back to any of them.

  • Libraries

    Write a library once and import it from your other scripts.

Stop on a line. Step both ways.

A script runs a whole bar at once, so the debugger records the bar where it stops and lets you walk through it.

  • Breakpoints

    On any line, from the margin of the editor or with a key.

  • Steps

    Into a call, over it, out of it, and back, as far back as the start of the bar.

  • Every value

    The calls in progress and the value of every variable in sight, at each step.

  • Safe

    It records bars that already closed: debugging never sends an order.

Test a strategy on real bars.

A simulated broker fills the orders of your strategy on the bars of the chart, with the settings the strategy declares.

  • What the strategy says

    Initial capital, order size, pyramiding, commission and slippage, from strategy().

  • Fills

    Market, limit, stop and stop-limit orders, exits with target, stop and trailing stop, partial closes and reversals.

  • The report

    Net result, max drawdown, win rate, profit factor, and every trade with its entry and its exit.

  • On every plan

    It runs in your browser, as often as you want.

It runs in your browser.

The same virtual machine as our servers, compiled to WebAssembly: a script gives the same result in both.

  • On the chart

    Plots, shapes, labels, lines, boxes, tables and fills on the bars of the chart, updated as each price arrives.

  • Trading from the browser

    A strategy can send its orders to a paper or a real account while its tab stays open. Closing the tab stops it.

Languages.

Pine Script® v3 to v6 today, each with the semantics of its version, including 24/7 server execution on paid plans. MQL4, MQL5 and EasyLanguage® are on the way.

  • Pine Script® v3–v6
  • MQL4 · soon
  • MQL5 · soon
  • EasyLanguage® · soon

Write your first script.