Skip to main content

Optimize your PineScript with QuantPilot Strategy Agent

Learn how to convert an existing TradingView PineScript strategy into a QuantPilot strategy and start the optimization workflow.

If you already have a TradingView PineScript strategy, use Optimize your PineScript to paste it into a dedicated code window and start the PineScript optimizer workflow

Important: Optimization does not guarantee better future performance. Always review the converted strategy, check the logic, and test the result before relying on it.


Open the Strategy Agent

  • Go to the strategy creation screen in QuantPilot.

  • On the empty strategy screen, click Optimize your PineScript.

  • This button opens the Code to Strategy dialog, where you can paste your TradingView PineScript.


Paste your PineScript

  • In the Code to Strategy dialog, paste your TradingView PineScript into the code field.

  • The dialog supports PineScript input from TradingView. You can paste a full strategy script, including:

    • strategy declaration

    • inputs

    • entry conditions

    • exit conditions

    • plots

    • indicator calculations

Use a complete PineScript strategy when possible. Scripts that clearly define entries and exits are easier for QuantPilot to convert and optimize.


Convert and optimize the strategy

  • After pasting your PineScript, click Convert & optimize.

  • QuantPilot will send the script to the Strategy Agent and start the PineScript optimizer workflow.

  • This works like pasting PineScript directly into the strategy chat and clicking Run, but the Code to Strategy dialog makes the process easier.


What QuantPilot may do next

  • After the workflow starts, QuantPilot analyzes the PineScript.

  • Depending on your script, QuantPilot may help with:

    • converting PineScript logic into a QuantPilot strategy workflow

    • generating or updating QuantScript

    • running a backtest

    • reviewing strategy behavior

    • suggesting parameter changes

    • optimizing the strategy

  • The result depends on the PineScript code, selected market, date range, and strategy logic.


Example PineScript strategies you can try

The examples below are basic starter scripts. They are not trading recommendations and should not be treated as ready-to-use profitable strategies

Example 1: Simple RSI strategy

This strategy enters a long position when RSI crosses above the oversold level and closes the position when RSI crosses below the overbought level.

//@version=6
strategy("Simple RSI Strategy", overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

rsiLength = input.int(14, "RSI Length")
oversold = input.int(30, "Oversold Level")
overbought = input.int(70, "Overbought Level")

rsi = ta.rsi(close, rsiLength)

longCondition = ta.crossover(rsi, oversold)
exitCondition = ta.crossunder(rsi, overbought)

if longCondition
strategy.entry("Long", strategy.long)

if exitCondition
strategy.close("Long")

plot(rsi, title="RSI")
hline(oversold, "Oversold")
hline(overbought, "Overbought")

Example 2: Simple EMA crossover strategy

This strategy enters long when the fast EMA crosses above the slow EMA and enters short when the fast EMA crosses below the slow EMA.

//@version=6
strategy("Simple EMA Crossover Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

fastLength = input.int(9, "Fast EMA Length")
slowLength = input.int(21, "Slow EMA Length")

fastEMA = ta.ema(close, fastLength)
slowEMA = ta.ema(close, slowLength)

longCondition = ta.crossover(fastEMA, slowEMA)
shortCondition = ta.crossunder(fastEMA, slowEMA)

if longCondition
strategy.entry("Long", strategy.long)

if shortCondition
strategy.entry("Short", strategy.short)

plot(fastEMA, title="Fast EMA")
plot(slowEMA, title="Slow EMA")

Example 3: Simple Bollinger Bands strategy

This strategy enters long when price crosses back above the lower band and enters short when price crosses back below the upper band.

//@version=6
strategy("Simple Bollinger Bands Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

length = input.int(20, "BB Length")
mult = input.float(2.0, "BB Multiplier")

basis = ta.sma(close, length)
dev = mult * ta.stdev(close, length)

upper = basis + dev
lower = basis - dev

longCondition = ta.crossover(close, lower)
shortCondition = ta.crossunder(close, upper)

if longCondition
strategy.entry("Long", strategy.long)

if shortCondition
strategy.entry("Short", strategy.short)

plot(basis, title="Middle Band")
plot(upper, title="Upper Band")
plot(lower, title="Lower Band")


Tips before optimizing PineScript

Before clicking Convert & optimize, check that your PineScript:

  • is complete enough for QuantPilot to understand the strategy logic

  • uses clear entry and exit rules

  • does not depend on missing external code

  • has readable input names and condition names

  • is a strategy script, not only an indicator script, when possible

If the script is incomplete or unclear, QuantPilot may ask for more information or the result may need more manual review.


Review the converted strategy

After QuantPilot converts or optimizes the strategy, review the output before saving or using it.

Check:

  • whether the strategy logic matches your original PineScript idea

  • whether entries and exits were interpreted correctly

  • whether parameters were changed

  • whether the backtest date range is appropriate

  • whether the results look realistic

  • whether the strategy may be overfitted to historical data

A strong-looking backtest does not mean the strategy will work the same way in live markets.


Learn more

To understand how backtesting works in QuantPilot, including what is included, what may not be fully reflected, performance metrics, strategy versions, and limitations, see Backtesting in QuantPilot: what is and isn’t included.

Did this answer your question?