Free Pine Script generator, tested before you trade it

Most Pine Script generators write code. Extractor tests your idea first: describe the strategy in plain English, see every trade and whether it beat buy & hold, then copy the TradingView script.

Try it with an example →Write your own

How it works

  1. Describe it. "Buy Apple when the 14 day RSI is below 35 and the close is above the 200 day SMA. Sell when the 14 day RSI is above 60. Stop loss 8%."
  2. See the backtest. Every trade on the chart, win rate, worst drop, and the buy & hold comparison.
  3. Copy the Pine Script. An indicator with buy/sell signals, stop loss and take profit lines, and alerts, or a strategy script for TradingView's tester.

Unclear description? It asks you a question instead of guessing. Found the strategy on YouTube? Paste the video link.

Example output

Generated from the rules above (RSI dip in an uptrend):

//@version=5
// Indicator generated by Extractor from your rules.
// Built for AAPL on the daily (1D) chart.
//   Buy when:  rsi(14) < 35 AND close > sma(200)
//   Sell when: rsi(14) > 60
//   Stop loss: 8%
// Marks where your rules say buy and sell, and adds alerts you can turn on in TradingView.

indicator("RSI dip in an uptrend signals", overlay=true)

rsi14 = ta.rsi(close, 14)
sma200 = ta.sma(close, 200)
entrySignal = (rsi14 < 35) and (close > sma200)
exitSignal = (rsi14 > 60)

// Track whether the rules are in a trade, so signals don't repeat while already long.
var bool inTrade = false
var float entryPrice = na
stopHit = inTrade and low <= entryPrice * (1 - 8.0 / 100)
targetHit = false
buy = not inTrade and entrySignal
sell = inTrade and (exitSignal or stopHit or targetHit)
if sell
    inTrade := false
    entryPrice := na
else if buy
    inTrade := true
    entryPrice := close

// Levels stay drawn through the bar where the trade closes.
wasInTrade = inTrade or sell
levelBase = sell ? entryPrice[1] : entryPrice
// Position levels from your inputs
float entryLine = wasInTrade ? levelBase : na
float tpLine = na
float slLine = entryLine * (1 - 8.0 / 100)
pEntry = plot(entryLine, "Entry", color.new(color.gray, 0), 1, plot.style_linebr)
pTp = plot(tpLine, "Take profit (not set)", color.new(color.green, 0), 2, plot.style_linebr)
pSl = plot(slLine, "Stop loss 8%", color.new(color.red, 0), 2, plot.style_linebr)
fill(pEntry, pTp, color.new(color.green, 85))
fill(pEntry, pSl, color.new(color.red, 85))
if (wasInTrade) and not (wasInTrade)[1]
    label.new(bar_index, high, "Entry " + str.tostring(entryLine, format.mintick) + "\nSL " + str.tostring(slLine, format.mintick) + " (-8%)", style=label.style_label_lower_left, color=color.new(color.gray, 20), textcolor=color.white, size=size.small)

plot(sma200, "SMA 200", color.orange)
plotshape(buy, "Buy", shape.labelup, location.belowbar, color.new(color.teal, 0), text="BUY", textcolor=color.white, size=size.small)
plotshape(sell, "Sell", shape.labeldown, location.abovebar, color.new(color.red, 0), text="SELL", textcolor=color.white, size=size.small)
alertcondition(buy, "Buy signal", "RSI dip in an uptrend: buy signal on {{ticker}} at {{close}}")
alertcondition(sell, "Sell signal", "RSI dip in an uptrend: sell signal on {{ticker}} at {{close}}")

Strategies with ready-made indicators