If you want to create a complete Pine Script strategy
(TradingView) that supports backtesting and an information table,
you should define the following components.
1. Strategy Settings
These are the basic settings.
- Strategy
Name
- Pine
Script Version (v5/v6)
- Initial
Capital
- Position
Size
- Commission
- Slippage
- Pyramiding
- Long
Only / Short Only / Both
Example:
Initial Capital: $10,000
Position Size: 10% of Equity
Commission: 0.05%
Slippage: 2 ticks
2. Entry Conditions
Define exactly when a trade should open.
Example:
Long Entry
- EMA
20 crosses above EMA 50
- RSI
> 55
- Price
above VWAP
Short Entry
- EMA
20 crosses below EMA 50
- RSI
< 45
- Price
below VWAP
3. Exit Conditions
Specify when a trade closes.
Examples:
- Stop
Loss Hit
- Target
Hit
- Opposite
Signal
- Trailing
Stop
- Time-based
Exit
- End
of Day Exit
4. Stop Loss
Choose the stop-loss method.
Examples:
- Fixed
Points
- Fixed
Percentage
- ATR
Based
- Swing
High/Low
- Previous
Candle High/Low
Example
SL = Entry - 2 × ATR
5. Take Profit Levels
Most traders use multiple targets.
Example
Target 1 = 1R
Target 2 = 2R
Target 3 = 3R
OR
Target 1 = 1%
Target 2 = 2%
Target 3 = 3%
6. Risk Management
Define risk rules.
Examples
- Risk
per trade = 1%
- Max
Daily Loss
- Max
Consecutive Losses
- Maximum
Open Trades
- Maximum
Drawdown
7. Position Sizing
Examples
- Fixed
Quantity
- Fixed
Cash
- % of
Equity
- ATR
Position Size
8. Filters
Optional filters improve trade quality.
Examples
- Trend
Filter (EMA 200)
- Volume
Filter
- ADX
Filter
- RSI
Filter
- Session
Filter
- Day
Filter
- Higher
Timeframe Trend
- News
Filter (manual)
9. Trading Session
Example
Trade only between
09:15–15:15
OR
London Session
OR
New York Session
10. Alerts
Create TradingView alerts.
Examples
- Buy
Alert
- Sell
Alert
- SL
Hit
- Target
Hit
11. Chart Display
Show visual elements on the chart.
- Buy
Arrow
- Sell
Arrow
- Stop
Loss Line
- Target
Lines
- Entry
Line
- EMA
- VWAP
- Labels
12. Backtesting Statistics
TradingView automatically provides many metrics.
Examples
- Net
Profit
- Gross
Profit
- Gross
Loss
- Profit
Factor
- Win
Rate
- Average
Trade
- Max
Drawdown
- Number
of Trades
- Average
Bars in Trade
- Sharpe
Ratio (if implemented)
- Sortino
Ratio (optional)
13. Information Table
A table on the chart can display live trade information.
Example Layout
|
Item |
Value |
|
Trend |
Bullish |
|
Signal |
BUY |
|
Entry |
24,560 |
|
Stop Loss |
24,350 |
|
Target 1 |
24,760 |
|
Target 2 |
24,950 |
|
Target 3 |
25,150 |
|
Risk Reward |
1:3 |
|
Position |
Long |
|
Trade Status |
Active |
|
Profit/Loss |
+₹1,250 |
|
ATR |
180 |
|
RSI |
63 |
|
Volume |
High |
14. Performance Table
You can also create a custom statistics table.
Example
|
Metric |
Value |
|
Total Trades |
250 |
|
Winning Trades |
168 |
|
Losing Trades |
82 |
|
Win Rate |
67.2% |
|
Profit Factor |
2.18 |
|
Average Win |
₹1,850 |
|
Average Loss |
₹720 |
|
Max Drawdown |
6.5% |
|
Net Profit |
₹2,45,000 |
15. User Inputs
Allow users to customize the strategy.
Examples
- EMA
Length
- RSI
Length
- ATR
Multiplier
- Risk
%
- Stop
Loss %
- Target
%
- Session
Time
- Enable
Long
- Enable
Short
- Enable
Trailing Stop
- Enable
Breakeven
Complete Feature Checklist
- ✅
Long Entry
- ✅
Short Entry
- ✅
Stop Loss
- ✅
Target 1
- ✅
Target 2
- ✅
Target 3
- ✅
Trailing Stop
- ✅
Break Even
- ✅
Risk Management
- ✅
Position Sizing
- ✅
Trading Session Filter
- ✅
Trend Filter
- ✅
Volume Filter
- ✅
Higher Timeframe Filter
- ✅
Buy/Sell Alerts
- ✅
Entry & Exit Labels
- ✅
SL & Target Lines
- ✅
Information Table
- ✅
Performance Table
- ✅
Full Backtesting Support
- ✅
Custom User Inputs
- ✅
Clean, Non-Repainting Logic
This structure is a solid foundation for a professional Pine
Script strategy that is suitable for both live trading and historical
backtesting.
