Skip to main content
On this page

How to Build Your Own TradingView Strategy

· 4 min read
Pineify Team
Pine Script and AI trading workflow research team

Build a custom TradingView strategy by defining conditions, position behavior and exits before interpreting its performance report. This example combines an SMA crossover with an RSI filter and illustrates a bracket exit; it does not establish a profitable setup.

How to Make Your Own Strategy in TradingView

Specify What the Strategy Should Do​

The demonstration enters long only when the fast SMA crosses above the slow SMA and RSI is below 70. It permits one position at a time. A stop and target are calculated from the signal bar's close, so their actual distance from a later fill can differ.

These choices are explicit teaching assumptions. They are not claims that RSI prevents false entries, that higher timeframes produce better signals or that a particular stop percentage fits every asset.

Use One Complete Script​

Open Pine Editor, create a strategy, paste the full example, save and add it to a standard chart. See the current editor guide for access controls.

//@version=6
strategy("Custom SMA RSI Example", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.1, slippage=1)
fastLength = input.int(10, "Fast SMA length", minval=1)
slowLength = input.int(30, "Slow SMA length", minval=1)
stopPct = input.float(1, "Stop distance from signal close (%)", minval=0.1)
targetPct = input.float(2, "Target distance from signal close (%)", minval=0.1)
fastSMA = ta.sma(close, fastLength)
slowSMA = ta.sma(close, slowLength)
rsiValue = ta.rsi(close, 14)
crossUp = ta.crossover(fastSMA, slowSMA)
longCondition = crossUp and rsiValue < 70
if longCondition and strategy.position_size == 0
strategy.entry("Long", strategy.long)
strategy.exit("Bracket", "Long", stop=close * (1 - stopPct / 100), limit=close * (1 + targetPct / 100))
plot(fastSMA, "Fast SMA", color.blue)
plot(slowSMA, "Slow SMA", color.orange)

The bracket prices are submitted with the entry instruction and remain based on that signal's close. This avoids describing them as percentages of an unknown future fill. Gaps can materially change the effective risk, and stops do not guarantee a maximum loss. Position allocation is also different from account equity at risk.

Pineify Website

Pineify can help assemble conditions and draft the code, but review the exact order behavior and verify it in TradingView.

Inspect the Strategy Report​

Record symbol, timeframe, session, available history, inputs and Properties settings. The test is not limited to bars currently visible in the viewport. Inspect individual entries, bracket prices and fills before comparing summary metrics.

Maximum drawdown is an equity peak-to-trough decline, not the same statistic as the longest sequence of losing trades. Win rate, average gains/losses, costs, exposure and sample size must be interpreted together. A 20% drawdown threshold or two-month forward test is not a universal standard of safety.

TradingView's strategy documentation explains order timing, costs and historical fill assumptions. Higher intrabar detail can improve the available simulation information where supported; it does not reproduce every real queue or fill.

Change Rules Without Concealing Selection​

Keep a record of tested parameter sets. Choose on one period, then evaluate on a later untouched period and compare different conditions. Repeatedly revising a rule after looking at its holdout result makes that result part of the selection process.

Use instrument-appropriate commission, slippage, capital and margin assumptions. The values in the code are placeholders for a reproducible demonstration, not a verified cost model. Review repainting and future leakage when adding higher-timeframe information or intrabar rules.

Does the script place real trades?

No. It creates simulated orders in TradingView's broker emulator.

Does an RSI filter improve the strategy?

That requires a defined comparison with costs and unseen data. It can remove both losing and winning opportunities.

Can I add shorts by swapping the same stop and target?

Define short-side distances independently: a protective short stop is above entry and its target below. Do not accidentally swap the intended percentage sizes.