1Copy the scriptPress Copy script above. It reads the file straight from GitHub.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.
Source Code
The code stays on GitHub. The author has not published this script under an open licence, so ForexR does not show its code. Copy script reads the file straight from GitHub into your clipboard, so you can still try it on your own chart. Ask the author before reusing the code anywhere else.
Overview
RG Structure Trading v4.0 fits robust trendline boundaries using pivot points, evaluates structural quality via a Q-Score metric, and filters entries through an Efficiency Ratio regime detector. Trades trigger on confirmed retests with candle rejection scoring, graded into tiers that scale risk. Exits utilize ATR-buffered stop losses, a breakeven mechanism, multi-stage partial profit-taking, and an ATR trailing stop alongside daily loss limits.
Robust pivot boundary estimation with touch scoring
Dual-threshold Q-Score structural quality grading
Efficiency ratio regime and crossing detection
Confirmation-based breakout and retest logic
Multi-stage exits with ATR trailing and breakeven stops
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Pivot Confirmation Bars
int
2
pivotConfirm
Max Pivots to Track
int
12
maxPivots
Touch Tolerance (ATR)
float
0.30
touchTolerance
Violation Penalty λ
float
2.0
violationPenalty
Persistence Weight ω
float
0.20
persistenceWeight
Minimum Touches (RANSAC)
int
3
minTouches
Max Slope (ATR/bar)
float
0.02
maxSlopeATR
Q-Score Grade A Threshold
float
0.70
qScoreA
Q-Score Grade B Threshold
float
0.55
qScoreB
Max Risk Geometry d_geom (ATR)
float
2.5
maxRiskGeometry
Min Risk Geometry d_geom (ATR)
float
0.5
minRiskGeometry
Efficiency Ratio Period
int
20
erPeriod
Show all 40 settings
Setting
Type
Default
Variable
ER Trend Threshold
float
0.45
erTrendThreshold
Cross Count Period
int
20
crossCountPeriod
Max Crossings for Trend
int
4
maxCrossings
Penetration Buffer (ATR)
float
0.20
penetrationBuffer
Close Confirmation Buffer (ATR)
float
0.40
closeBuffer
Retest Window (bars)
int
12
retestWindow
Retest Tolerance (ATR)
float
0.40
retestTolerance
Min Rejection Score (0-4)
int
3
minRejectionScore
Risk Grade A (%)
float
1.0
riskPerTradeA
Risk Grade B (%)
float
0.5
riskPerTradeB
Stop Buffer Beyond Safety (ATR)
float
0.20
stopBuffer
Break Even at (R)
float
0.8
breakEvenR
Partial Exit at (R)
float
1.0
partialExitR
Partial Exit %
float
60.0
partialExitPct
Trail Start at (R)
float
1.2
trailStartR
Trail Buffer (ATR)
float
0.25
trailBufferATR
Max Portfolio Heat (%)
float
6.0
maxPortfolioHeat
Max Daily Loss (%)
float
3.0
maxDailyLossPct
Max Consecutive Losses
int
4
maxConsecLosses
Max Bars in Trade
int
40
maxBarsInTrade
Time Stop Min R
float
0.3
timeStopMinR
Enable Drawdown Scaling
bool
true
enableDDScaling
DD Threshold 1 (%)
float
5.0
ddThreshold1
Scale at DD1
float
0.75
ddScale1
DD Threshold 2 (%)
float
10.0
ddThreshold2
Scale at DD2
float
0.50
ddScale2
DD Threshold 3 (%)
float
15.0
ddThreshold3
Scale at DD3
float
0.25
ddScale3
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
This trend-following strategy executes a classic Donchian channel breakout system designed to cross-validate backtest results against external framework benchmarks. It triggers a long entry when the closing price breaks above the highest high of the prior entr
This strategy plots running pivot highs as red R circles and pivot lows as blue S circles directly on the price chart. It computes an EMA 3 and a Cto trend line from close prices, then generates long signals on upward EMA-Cto crossovers combined with price pos
The Chained Linear Regression Reversal Strategy plots linear regression channels with upper and lower standard deviation bands directly on the price chart across a user-defined time window. When price breaks out of the static channel for a confirmed number of
Calculates multi-period logarithmic regression trend channels and deviation bands across up to twenty selectable lookback lengths directly on the price chart. It evaluates channel slopes and Pearson's correlation coefficient to detect market trends and generat
This trend breakout strategy plots Donchian Channels consisting of upper, lower, and middle bands directly on the main price chart. Long positions enter when price touches the upper channel and pulls back to or below the middle band, placing a stop loss at the
This strategy executes trades on short-term cryptocurrency charts using a combination of pivot support and resistance levels and a multi-pole smoothed trend filter. Entries trigger when price crosses the smoothed trend line and confirms above or below a short-