TradingView Helper Indicators
This page contains ready-to-copy TradingView indicator codes that you can use immediately with OptAlgo. Simply copy the entire code block and paste it into TradingView's Pine Editor.
Non-Repainting RSI with Signals
A complete RSI indicator that works across multiple timeframes without repainting. Includes visual signals and output signal for integration with OptAlgo.
Features
- Multi-timeframe RSI calculation (non-repainting)
- Customizable overbought/oversold levels
- Visual signals with colored backgrounds
- Output signal format: LONG=1, SHORT=-1, CLOSE=0
Code
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © OptAlgo
//@version=6
indicator("Non-Repainting RSI Example [OptAlgo]", overlay=false)
//═══════════════════════════════════════════════════════════════════════════════════════════════
// FUNCTIONS
//═══════════════════════════════════════════════════════════════════════════════════════════════
Non_Repainting_Security_Function(_market, _res, _exp) =>
(_res == timeframe.period or _res == "") and (_market == ticker.standard(syminfo.tickerid)) ?
_exp :
(request.security(_market, _res, _exp[barstate.isrealtime ? 1 : 0])[barstate.isrealtime ? 0 : 1])
//═══════════════════════════════════════════════════════════════════════════════════════════════
// INPUTS
//═══════════════════════════════════════════════════════════════════════════════════════════════
rsi_length = input.int(defval=14, title='RSI Length', minval=1, group='RSI Settings')
rsi_timeframe = input.timeframe(defval='', title='RSI Timeframe', group='RSI Settings')
rsi_overbought = input.int(defval=70, title='Overbought Level', minval=50, maxval=100, group='RSI Settings')
rsi_oversold = input.int(defval=30, title='Oversold Level', minval=0, maxval=50, group='RSI Settings')
//═══════════════════════════════════════════════════════════════════════════════════════════════
// CALCULATIONS
//═══════════════════════════════════════════════════════════════════════════════════════════════
// Define RSI function
rsi_function(length) =>
ta.rsi(close, length)
// Get non-repainting RSI value
rsi_val = Non_Repainting_Security_Function(syminfo.tickerid, rsi_timeframe, rsi_function(rsi_length))
//═══════════════════════════════════════════════════════════════════════════════════════════════
// SIGNAL CREATION
//═══════════════════════════════════════════════════════════════════════════════════════════════
long_condition = ta.crossover(rsi_val, rsi_oversold)
short_condition = ta.crossunder(rsi_val, rsi_overbought)
close_condition = ta.cross(rsi_val, 50)
output_signal = close_condition ? 0 : (long_condition ? 1 : short_condition ? -1 : 2)
//═══════════════════════════════════════════════════════════════════════════════════════════════
// PLOTTING
//═══════════════════════════════════════════════════════════════════════════════════════════════
// Plot RSI
plot(rsi_val, title='RSI', color=color.new(#2962FF, 0), linewidth=2)
// Plot levels
hline(rsi_overbought, title='Overbought', color=color.new(color.red, 50), linestyle=hline.style_dashed)
hline(50, title='Middle', color=color.new(color.gray, 50), linestyle=hline.style_dotted)
hline(rsi_oversold, title='Oversold', color=color.new(color.green, 50), linestyle=hline.style_dashed)
// Plot background colors
bgcolor(rsi_val > rsi_overbought ? color.new(color.red, 90) : na, title='Overbought Zone')
bgcolor(rsi_val < rsi_oversold ? color.new(color.green, 90) : na, title='Oversold Zone')
// Plot signals
plotshape(long_condition, title='Long Signal', style=shape.triangleup, location=location.bottom,
color=color.new(color.green, 0), size=size.small)
plotshape(short_condition, title='Short Signal', style=shape.triangledown, location=location.top,
color=color.new(color.red, 0), size=size.small)
// Plot output signal for data window
plot(output_signal == 2 ? na : output_signal, title='Output Signal (LONG==1, SHORT==-1, CLOSE==0)',
display=display.data_window)
How to Use
- Copy the entire code above
- Open TradingView and go to Pine Editor
- Paste the code and click "Add to Chart"
- Customize RSI settings in the indicator settings
- Use the output signal with OptAlgo for automated trading
Higher Expansion & Lower Expansion (HE & LE)
A simple yet powerful indicator that tracks the highest and lowest prices over a specified period. Perfect for identifying support and resistance levels dynamically.
Features
- Tracks highest high over specified length (Higher Expansion)
- Tracks lowest low over specified length (Lower Expansion)
- Customizable source and length
- Visual overlay on price chart
Code
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © OptAlgo
//@version=6
indicator(title="HE & LE [OptAlgo]", overlay=true, timeframe="", timeframe_gaps=true)
//═══════════════════════════════════════════════════════════════════════════════════════════════
// INPUTS
//═══════════════════════════════════════════════════════════════════════════════════════════════
src_import = input.source(close, 'HE & LE Src')
length = input.int(title="Length", defval=14, minval=1)
//═══════════════════════════════════════════════════════════════════════════════════════════════
// CALCULATIONS
//═══════════════════════════════════════════════════════════════════════════════════════════════
higher_expansion_plot = ta.highest(src_import, length)
lower_expansion_plot = ta.lowest(src_import, length)
//═══════════════════════════════════════════════════════════════════════════════════════════════
// PLOTTING
//═══════════════════════════════════════════════════════════════════════════════════════════════
plot(higher_expansion_plot, title="H Expansion", color=color.new(#f86909, 0), linewidth=2)
plot(lower_expansion_plot, title="L Expansion", color=color.new(#d9ff00, 0), linewidth=2)
How to Use
- Copy the entire code above
- Open TradingView and go to Pine Editor
- Paste the code and click "Add to Chart"
- Adjust the Length parameter to your preference (default: 14)
- Use HE as dynamic resistance and LE as dynamic support
Trading Ideas
- Breakout Strategy: Enter long when price breaks above Higher Expansion
- Support/Resistance: Use as dynamic S/R levels for entries and exits
- Trend Following: Stay long when price is above both lines, short when below
- Mean Reversion: Look for reversals when price touches the expansion lines
Average Plot (Weighted Average)
A customizable weighted average indicator that calculates the average between high and low prices based on a ratio. Useful for identifying mid-range levels and potential entry/exit points.
Features
- Customizable source inputs (high/low)
- Adjustable ratio for weighted calculation
- Visual overlay on price chart
- Simple and effective for finding balance zones
Code
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © OptAlgo
//@version=6
indicator('AVG [OptAlgo]', overlay=true, timeframe='', timeframe_gaps=false)
//═══════════════════════════════════════════════════════════════════════════════════════════════
// INPUTS
//═══════════════════════════════════════════════════════════════════════════════════════════════
a = input.source(high, title='Source H')
b = input.source(low, title='Source L')
m = input.float(1, title='Ratio')
//═══════════════════════════════════════════════════════════════════════════════════════════════
// CALCULATIONS
//═══════════════════════════════════════════════════════════════════════════════════════════════
w_avg = b + ((a - b) / (m + 1))
//═══════════════════════════════════════════════════════════════════════════════════════════════
// PLOTTING
//═══════════════════════════════════════════════════════════════════════════════════════════════
plot(w_avg, title='AVG PLOT', color=color.yellow, linewidth=2)
How to Use
- Copy the entire code above
- Open TradingView and go to Pine Editor
- Paste the code and click "Add to Chart"
- Adjust the Ratio parameter to change the weighting (default: 1)
- Change source inputs to use different price data
Trading Ideas
- Fair Value Zone: Use as a midpoint reference for mean reversion strategies
- Entry Filter: Enter trades when price crosses the average line
- Dynamic Support/Resistance: Acts as a moving equilibrium level
- Scalping Guide: Quick reference for short-term price balance
Parameters Explained
- Ratio (m): Controls the weighted calculation. Higher values shift the average closer to the low, lower values shift it toward the midpoint.
- m = 1 (default): Weighted toward midpoint
- m = 0.5: More weight toward high
- m = 2: More weight toward low
More Indicators Coming Soon
This page will be regularly updated with more ready-to-copy indicator codes. Check back often for new additions!
Integration with OptAlgo
All these indicators can be integrated with OptAlgo for automated trading:
- Add Signal Logic: Use the output_signal format (LONG=1, SHORT=-1, CLOSE=0)
- Configure Webhook: Set up TradingView alerts with webhook to OptAlgo API
- Send Signals: Use the Signal Parameters to control your trades
Example Signal Integration
//═══════════════════════════════════════════════════════════════════════════════════════════════
// SIGNAL CREATION
//═════════════════════════════════════════════════ ══════════════════════════════════════════════
long_condition = // your long entry logic
short_condition = // your short entry logic
close_condition = // your exit logic
output_signal = close_condition ? 0 : (long_condition ? 1 : short_condition ? -1 : 2)
plot(output_signal == 2 ? na : output_signal, title='Output Signal (LONG==1, SHORT==-1, CLOSE==0)',
display=display.data_window)
Helper Functions
Need reusable functions for your indicators? Check out our TradingView Helper Functions page.
Contributing
Have an indicator you'd like to share with the OptAlgo community? Contact us through the Discord community.