EMA Indicators with BUY sell SignalCombine 3 EMA indicators into 1. Buy and Sell signal is based on
- Buy signal based on 20 Days Highest High resistance
- Sell signal based on 10 Days Lowest Low support
Input :-
1 - Short EMA (20), Mid EMA (50) and Long EMA (200)
2 - Resistance (20) = 20 Days Highest High line
3 - Support (10) = 10 Days Lowest Low line
Buscar en scripts para "A股市场较发行价上涨最多的10个股票"
Volume Range EventsChanges in the feelings (positive, negative, neutral) in the market concerning the valuation of an instrument are often preceded with sudden outbursts of buying and selling frenzies. The aim of this indicator is to report such outbursts. We can see them as expansions of volume, sometimes 10 times more than usual. and as extensions of the trading range, also sometimes 10 times more than usual (e.g. usual range is 10 cent suddenly a whole dollar.) The changes are calculated in such a way that these fit between plus and minus 100 percent, the bars are scaled in some sort of logarithmic way. The Emoline is the same as the one in the True Balance of Power indicator, which I already published
ONLY RISES ARE EVENTS
Sometimes analysts are tempted to give meaning to low volume or small ranges. These simply mean that the market has little interest in trading this instrument. I believe that in such cases the trader needs to wait for expansion and extension events to happen, then he can make a better guess of where the market is heading. As events often mark the beginning or ending of a trend, this indicator provides an early and clear signal, because it doesn’t bother us about non-events.
WHAT IS USUAL?
If the algorithm would use an average as a normal to scale volume or range events, then previous peaks will act as spoilers by making the average so high that a following peak is scaled too small. I developed a function, usual() , that kicks out all extremes of a ‘population of values’ and which returns the average of the non-extreme values. It can be called with any serial. This function is called by both algorithms that report volume and range peaks, which guarantees that the results are really comparable. As this function has a fixed look back of 8 periods, we might state that ‘usual’ is a short lived relative value. I think this doesn’t matter for the practical use of the indicator.
COLORING AND INTERPRETATION
I follow the categories in the ‘Better Volume Indicator’, published by LeazyBear, these are:
1. Climactic Volumes, event >40 % (this means peak is 1.5 X usual)
LIME: Climax Buying Volume, direction up, range event also > 30 %
RED: Climax Selling Volume, direction down, range event also > 30 %
AQUA: Climax Churning Volume, both directions, range event < 30%
2. Smaller Volumes, event <40 %
GREEN: Supportive Volume, both directions, if combined with range event
BLUE: Churning Volume, both directions, if not combined with range event (Professional Trading)
3. Just Range Events
BLACK histogram bars (Amateurish Trading)
Forex Master v4.0 (EUR/USD Mean-Reversion Algorithm)DESCRIPTION
Forex Master v4.0 is a mean-reversion algorithm currently optimized for trading the EUR/USD pair on the 5M chart interval. All indicator inputs use the period's closing price and all trades are executed at the open of the period following the period where the trade signal was generated.
There are 3 main components that make up Forex Master v4.0:
I. Trend Filter
The algorithm uses a version of the ADX indicator as a trend filter to trade only in certain time periods where price is more likely to be range-bound (i.e., mean-reverting). This indicator is composed of a Fast ADX and a Slow ADX, both using the same look-back period of 50. However, the Fast ADX is smoothed with a 6-period EMA and the Slow ADX is smoothed with a 12-period EMA. When the Fast ADX is above the Slow ADX, the algorithm does not trade because this indicates that price is likelier to trend, which is bad for a mean-reversion system. Conversely, when the Fast ADX is below the Slow ADX, price is likelier to be ranging so this is the only time when the algorithm is allowed to trade.
II. Bollinger Bands
When allowed to trade by the Trend Filter, the algorithm uses the Bollinger Bands indicator to enter long and short positions. The Bolliger Bands indicator has a look-back period of 20 and a standard deviation of 1.5 for both upper and lower bands. When price crosses over the lower band, a Long Signal is generated and a long position is entered. When price crosses under the upper band, a Short Signal is generated and a short position is entered.
III. Money Management
Rule 1 - Each trade will use a limit order for a fixed quantity of 50,000 contracts (0.50 lot). The only exception is Rule
Rule 2 - Order pyramiding is enabled and up to 10 consecutive orders of the same signal can be executed (for example: 14 consecutive Long Signals are generated over 8 hours and the algorithm sends in 10 different buy orders at various prices for a total of 350,000 contracts).
Rule 3 - Every order will include a bracket with both TP and SL set at 50 pips (note: the algorithm only closes the current open position and does not enter the opposite trade once a TP or SL has been hit).
Rule 4 - When a new opposite trade signal is generated, the algorithm sends in a larger order to close the current open position as well as open a new one (for example: 14 consecutive Long Signals are generated over 8 hours and the algorithm sends in 10 different buy orders at various prices for a total of 350,000 contracts. A Short Signal is generated shortly after the 14th Long Signal. The algorithm then sends in a sell order for 400,000 contracts to close the 350,000 contracts long position and open a new short position of 50,000 contracts).
My5min1. Follow the instructions for entry and exit exactly as above. Don’t second guess, or assume/presume anything.
2. Avoid entering the trade when the price is temporarily above /below 10 day MA, but the price candle hasn’t fully formed yet. Enter the trade only after the price candle closes above/below the 10 day MA.
3. Exit the trade immediately when the price candle closes above/below 10 day MA in the direction opposite to the trade. Don’t remain in the trade wishing it to turn in your favor.
4. Never ever trade in the opposite direction of the market. i.e. don’t buy when the price is below 200 day MA and sell when the price is above 200 day MA.
5. Take profits when limit is reached. Don’t be greedy and keep on increasing the target. Remember- A bird in hand is worth two in the bush.
MACD, backtest 2015+ only, cut in half and doubledThis is only a slight modification to the existing "MACD Strategy" strategy plugin!
found the default MACD strategy to be lacking, although impressive for its simplicity. I added "year>2014" to the IF buy/sell conditions so it will only backtest from 2015 and beyond ** .
I also had a problem with the standard MACD trading late, per se. To that end I modified the inputs for fast/slow/signal to double. Example: my defaults are 10, 21, 10 so I put 20, 42, 20 in. This has the effect of making a 30min interval the same as 1 hour at 10,21,10. So if you want to backtest at 4hr, you would set your time interval to 2hr on the main chart. This is a handy way to make shorter time periods more useful even regardless of strategy/testing, since you can view 15min with alot less noise but a better response.
Used on BTCCNY OKcoin, with the chart set at 45 min (so really 90min in the strategy) this gave me a percent profitable of 42% and a profit factor of 1.998 on 189 trades.
Personally, I like to set the length/signals to 30,63,30. Meaning you need to triple the time, it allows for much better use of shorter time periods and the backtests are remarkably profitable. (i.e. 15min chart view = 45min on script, 30min= 1.5hr on script)
** If you want more specific time periods you need to try plugging in different bar values: replace "year" with "n" and "2014" with "5500". The bars are based on unix time I believe so you will need to play around with the number for n, with n being the numbers of bars.
Double Pattern Screener v7 //@version=6
indicator("Double Pattern Screener", shorttitle="DPS", overlay=false)
// Screener Inputs
leftBars = input.int(5, "Left Bars", minval=3, maxval=10)
rightBars = input.int(5, "Right Bars", minval=3, maxval=10)
tolerance = input.float(0.02, "Max Difference", step=0.01)
atrLength = input.int(14, "ATR Length", minval=1)
// NEW: Filter for number of equal peaks
filterPeaks = input.int(3, "Filter: Show Only X Equal Peaks", minval=2, maxval=5)
enableFilter = input.bool(true, "Enable Peak Count Filter")
// Arrays for tracking swings
var array todaySwingLevels = array.new(0)
var array swingCounts = array.new(0)
var array isResistance = array.new(0)
var array swingBars = array.new(0)
var int maxEqualPeaks = 0
var float nearestEqualLevel = na
var float distanceToNearest = na
var bool hasPattern = false
// Detect swings
swingHigh = ta.pivothigh(high, leftBars, rightBars)
swingLow = ta.pivotlow(low, leftBars, rightBars)
// Track current day
currentDay = dayofmonth
isNewDay = currentDay != currentDay
// Clear on new day
if barstate.isfirst or isNewDay
array.clear(todaySwingLevels)
array.clear(swingCounts)
array.clear(isResistance)
array.clear(swingBars)
maxEqualPeaks := 0
nearestEqualLevel := na
distanceToNearest := na
hasPattern := false
// Function to find matching level
findMatchingLevel(newLevel, isHigh) =>
matchIndex = -1
if array.size(todaySwingLevels) > 0
for i = 0 to array.size(todaySwingLevels) - 1
existingLevel = array.get(todaySwingLevels, i)
existingIsResistance = array.get(isResistance, i)
if math.abs(newLevel - existingLevel) <= tolerance and existingIsResistance == isHigh
matchIndex := i
break
matchIndex
// Process swing highs
if not na(swingHigh)
matchIndex = findMatchingLevel(swingHigh, true)
if matchIndex >= 0
newCount = array.get(swingCounts, matchIndex) + 1
array.set(swingCounts, matchIndex, newCount)
// Update max equal peaks
if newCount > maxEqualPeaks
maxEqualPeaks := newCount
else
array.push(todaySwingLevels, swingHigh)
array.push(swingCounts, 1)
array.push(isResistance, true)
array.push(swingBars, bar_index)
// Process swing lows
if not na(swingLow)
matchIndex = findMatchingLevel(swingLow, false)
if matchIndex >= 0
newCount = array.get(swingCounts, matchIndex) + 1
array.set(swingCounts, matchIndex, newCount)
// Update max equal peaks
if newCount > maxEqualPeaks
maxEqualPeaks := newCount
else
array.push(todaySwingLevels, swingLow)
array.push(swingCounts, 1)
array.push(isResistance, false)
array.push(swingBars, bar_index)
// Remove broken levels
if array.size(todaySwingLevels) > 0
for i = array.size(todaySwingLevels) - 1 to 0
level = array.get(todaySwingLevels, i)
isRes = array.get(isResistance, i)
levelBroken = isRes ? close > level : close < level
if levelBroken
removedCount = array.get(swingCounts, i)
array.remove(todaySwingLevels, i)
array.remove(swingCounts, i)
array.remove(isResistance, i)
array.remove(swingBars, i)
// Recalculate max if we removed the highest count
if removedCount == maxEqualPeaks
maxEqualPeaks := 0
if array.size(swingCounts) > 0
for j = 0 to array.size(swingCounts) - 1
count = array.get(swingCounts, j)
if count > maxEqualPeaks
maxEqualPeaks := count
// Calculate nearest equal level and distance
nearestEqualLevel := na
distanceToNearest := na
smallestDistance = 999999.0
if array.size(todaySwingLevels) > 0
for i = 0 to array.size(todaySwingLevels) - 1
count = array.get(swingCounts, i)
level = array.get(todaySwingLevels, i)
// Only consider levels with 2+ touches
if count >= 2
distance = math.abs(close - level)
if distance < smallestDistance
smallestDistance := distance
nearestEqualLevel := level
distanceToNearest := distance
// Pattern detection with filter
hasPattern := false
if maxEqualPeaks >= 2
if enableFilter
hasPattern := maxEqualPeaks == filterPeaks
else
hasPattern := true
// Screener outputs
patternSignal = hasPattern ? 1 : 0
numberEqualPeaks = maxEqualPeaks
nearestLevelPrice = nearestEqualLevel
distanceCents = distanceToNearest
// Calculate ATR normalized distance
atr = ta.atr(atrLength)
atrDistance = not na(distanceToNearest) and not na(atr) and atr > 0 ? distanceToNearest / atr : na
// Plot screener values
plot(patternSignal, title="Pattern Signal", display=display.data_window)
plot(numberEqualPeaks, title="Number Equal Peaks", display=display.data_window)
plot(nearestLevelPrice, title="Nearest Equal Level Price", display=display.data_window)
plot(distanceCents, title="Distance to Nearest (Price Units)", display=display.data_window)
plot(atrDistance, title="ATR Normalized Distance", display=display.data_window)
// Table for current symbol info
if barstate.islast
var table infoTable = table.new(position.top_right, 2, 6, bgcolor=color.new(color.black, 70))
table.cell(infoTable, 0, 0, "Symbol:", bgcolor=color.new(color.gray, 50), text_color=color.white)
table.cell(infoTable, 1, 0, syminfo.ticker, bgcolor=color.new(color.blue, 50), text_color=color.white)
table.cell(infoTable, 0, 1, "Pattern:", bgcolor=color.new(color.gray, 50), text_color=color.white)
table.cell(infoTable, 1, 1, str.tostring(patternSignal), bgcolor=patternSignal == 1 ? color.new(color.purple, 50) : color.new(color.gray, 50), text_color=color.white)
table.cell(infoTable, 0, 2, "Equal Peaks:", bgcolor=color.new(color.gray, 50), text_color=color.white)
table.cell(infoTable, 1, 2, str.tostring(numberEqualPeaks), bgcolor=color.new(color.yellow, 50), text_color=color.black)
table.cell(infoTable, 0, 3, "Nearest Level:", bgcolor=color.new(color.gray, 50), text_color=color.white)
table.cell(infoTable, 1, 3, str.tostring(nearestLevelPrice, "#.####"), bgcolor=color.new(color.orange, 50), text_color=color.white)
table.cell(infoTable, 0, 4, "Distance:", bgcolor=color.new(color.gray, 50), text_color=color.white)
table.cell(infoTable, 1, 4, str.tostring(distanceCents, "#.####"), bgcolor=color.new(color.green, 50), text_color=color.white)
table.cell(infoTable, 0, 5, "Filter Active:", bgcolor=color.new(color.gray, 50), text_color=color.white)
filterText = enableFilter ? str.tostring(filterPeaks) + " peaks" : "OFF"
table.cell(infoTable, 1, 5, filterText, bgcolor=enableFilter ? color.new(color.red, 50) : color.new(color.gray, 50), text_color=color.white)
❄️ Lin Kuei Elite SuperTrend ⚔️Lin Kuei Elite SuperTrend - Technical Analysis Indicator
Overview
The Lin Kuei Elite SuperTrend is an advanced trend-following indicator that enhances the traditional SuperTrend algorithm with multiple layers of analysis and sophisticated visual effects. Built on Pine Script v6, it provides traders with dynamic trend identification, signal generation, and comprehensive market intelligence.
Core Algorithm
The indicator calculates SuperTrend using an enhanced ATR (Average True Range) methodology with adaptive smoothing and rank-based multipliers. The core logic determines trend direction by comparing price action to dynamically adjusted upper and lower bands, creating clear trend reversals and continuation signals.
Key Components:
Enhanced ATR calculation with EMA smoothing
Rank-based sensitivity scaling (0.8x to 1.6x multipliers)
Volume and momentum filtering options
Multi-timeframe shadow clone analysis
Assassin Rank System
The indicator features four distinct operational modes that adjust sensitivity and visual complexity:
Shadow Ninja (Conservative): 80% sensitivity with stable, low-noise signals ideal for risk-averse traders seeking high-confidence entries.
Ice Warrior (Balanced): Standard 100% sensitivity providing optimal balance between responsiveness and stability for most trading scenarios.
Frost Master (Aggressive): 130% sensitivity with enhanced trend detection for experienced traders in volatile markets.
Grandmaster Sub-Zero (Ultimate): 160% sensitivity with maximum responsiveness and exclusive visual effects for professional-level analysis.
Visual Features
Frost Aura Effects: Multi-layered glow effects around the main trend line with dynamic transparency based on trend velocity, creating visual depth and trend strength indication.
Shadow Clone Technique: Displays fast and slow SuperTrend variants using different ATR periods (0.7x and 1.5x) to provide confirmation and early warning signals.
Future Sight Projections: Three predictive projection lines showing potential trend continuation based on current velocity and acceleration calculations.
Quantum Particles: Animated particle effects positioned above and below the main trend line, appearing at regular intervals to enhance visual appeal.
Protection Zones: Shaded areas around the main trend line representing dynamic support/resistance zones calculated at 30% of the adjusted ATR.
Signal Generation
The indicator generates two primary signal types:
Trend Change Signals: Triangle markers appear when the trend direction shifts from bullish to bearish or vice versa, with confirmation based on price position relative to the calculated bands.
Rank-Specific Signals: Higher ranks display additional character-based signals (snowflake, fire, ice cube, lightning) with corresponding size scaling based on the selected assassin rank.
Technical Specifications
Input Parameters:
ATR Period: 10 (adjustable 1-50)
Ice Multiplier: 3.0 (adjustable 0.5-10.0)
Crystallization Period: 2 (adjustable 1-10)
Line Thickness: 4 (adjustable 1-8)
Optional Filters:
Volume confirmation with threshold settings
Momentum filtering based on 5-period price changes
Noise reduction capabilities
Intelligence Dashboard
A compact real-time dashboard displays:
Current assassin rank and associated color coding
Trend direction with visual indicators
Power level classification (LOW/MODERATE/HIGH/EXTREME)
Protection zone status
Signal system status
Battle readiness assessment
Alert System
Comprehensive alert functionality includes:
Basic trend change notifications
Rank-specific ultimate technique alerts
Customizable message content for different signal types
Use Cases
The indicator suits multiple trading styles:
Trend Following: Primary trend identification with clear entry/exit points
Swing Trading: Medium-term trend changes with protection zones for position management
Scalping: Fast rank settings for quick trend reversals (use with caution due to increased noise)
Risk Management: Protection zones help determine stop-loss placement and position sizing
Limitations
This indicator is a trend-following tool and may generate false signals in ranging or choppy markets. The multiple visual effects, while aesthetically appealing, may cause information overload for some users. Higher sensitivity ranks increase signal frequency but also false signal probability. The indicator works best in trending market conditions and should be combined with other forms of analysis for optimal results.
The thematic elements (assassin ranks, frost/fire imagery) are purely cosmetic and do not affect the underlying mathematical calculations, which remain based on established technical analysis principles.
Double Top/Bottom Screener - Clean Today Only v5 //@version=6
indicator("Double Top/Bottom Screener - Clean Today Only", overlay=true, max_lines_count=100)
// Inputs
leftBars = input.int(5, "Left Bars", minval=3, maxval=10)
rightBars = input.int(5, "Right Bars", minval=3, maxval=10)
tolerance = input.float(0.02, "Max Difference (e.g., 0.02 for 2 cents)", step=0.01)
atrLength = input.int(14, "ATR Length for Normalized Distance", minval=1)
requiredPeaks = input.int(3, "Required Identical Peaks", minval=2, maxval=5)
// Arrays to store today's swing levels only
var array todaySwingLevels = array.new(0)
var array swingCounts = array.new(0)
var array swingLines = array.new(0)
var array isResistance = array.new(0)
var array swingBars = array.new(0)
var bool hasDoubleTop = false
var bool hasDoubleBottom = false
var float doubleTopLevel = na
var float doubleBottomLevel = na
var float nearestDoubleLevel = na
var int currentDay = na
// Detect significant swings only
swingHigh = ta.pivothigh(high, leftBars, rightBars)
swingLow = ta.pivotlow(low, leftBars, rightBars)
// Track current day
currentDay := dayofmonth
isNewDay = currentDay != currentDay
// Clear everything on new day
if barstate.isfirst or isNewDay
// Delete all existing lines
if array.size(swingLines) > 0
for i = array.size(swingLines) - 1 to 0
line.delete(array.get(swingLines, i))
// Clear all arrays
array.clear(todaySwingLevels)
array.clear(swingCounts)
array.clear(swingLines)
array.clear(isResistance)
array.clear(swingBars)
// Reset flags
hasDoubleTop := false
hasDoubleBottom := false
doubleTopLevel := na
doubleBottomLevel := na
nearestDoubleLevel := na
// Function to find matching level within today's swings only
findMatchingLevel(newLevel, isHigh) =>
matchIndex = -1
if array.size(todaySwingLevels) > 0
for i = 0 to array.size(todaySwingLevels) - 1
existingLevel = array.get(todaySwingLevels, i)
existingIsResistance = array.get(isResistance, i)
if math.abs(newLevel - existingLevel) <= tolerance and existingIsResistance == isHigh
matchIndex := i
break
matchIndex
// Process swing highs (resistance levels) - today only
if not na(swingHigh)
matchIndex = findMatchingLevel(swingHigh, true)
if matchIndex >= 0
// Found matching resistance level
newCount = array.get(swingCounts, matchIndex) + 1
array.set(swingCounts, matchIndex, newCount)
// Delete old line and create new one with appropriate color
line.delete(array.get(swingLines, matchIndex))
lineColor = newCount >= requiredPeaks ? color.yellow : color.red
// Start line from the original swing bar, not current bar
originalBar = array.get(swingBars, matchIndex)
newLine = line.new(originalBar, swingHigh, bar_index + 20, swingHigh,
color=lineColor, width=2, extend=extend.right)
array.set(swingLines, matchIndex, newLine)
// Update pattern detection
if newCount >= requiredPeaks
hasDoubleTop := true
doubleTopLevel := swingHigh
else
// New resistance level - add to today's levels
array.push(todaySwingLevels, swingHigh)
array.push(swingCounts, 1)
array.push(isResistance, true)
array.push(swingBars, bar_index)
// Create red horizontal line starting from swing bar
newLine = line.new(bar_index, swingHigh, bar_index + 20, swingHigh,
color=color.red, width=2, extend=extend.right)
array.push(swingLines, newLine)
// Process swing lows (support levels) - today only
if not na(swingLow)
matchIndex = findMatchingLevel(swingLow, false)
if matchIndex >= 0
// Found matching support level
newCount = array.get(swingCounts, matchIndex) + 1
array.set(swingCounts, matchIndex, newCount)
// Delete old line and create new one with appropriate color
line.delete(array.get(swingLines, matchIndex))
lineColor = newCount >= requiredPeaks ? color.yellow : color.green
// Start line from the original swing bar, not current bar
originalBar = array.get(swingBars, matchIndex)
newLine = line.new(originalBar, swingLow, bar_index + 20, swingLow,
color=lineColor, width=2, extend=extend.right)
array.set(swingLines, matchIndex, newLine)
// Update pattern detection
if newCount >= requiredPeaks
hasDoubleBottom := true
doubleBottomLevel := swingLow
else
// New support level - add to today's levels
array.push(todaySwingLevels, swingLow)
array.push(swingCounts, 1)
array.push(isResistance, false)
array.push(swingBars, bar_index)
// Create green horizontal line starting from swing bar
newLine = line.new(bar_index, swingLow, bar_index + 20, swingLow,
color=color.green, width=2, extend=extend.right)
array.push(swingLines, newLine)
// Remove broken levels immediately (strict enforcement)
if array.size(todaySwingLevels) > 0
for i = array.size(todaySwingLevels) - 1 to 0
level = array.get(todaySwingLevels, i)
isRes = array.get(isResistance, i)
// Check if level is broken (even slightly)
levelBroken = isRes ? close > level : close < level
if levelBroken
// Delete line and remove from arrays
line.delete(array.get(swingLines, i))
array.remove(swingLines, i)
array.remove(todaySwingLevels, i)
array.remove(swingCounts, i)
array.remove(isResistance, i)
array.remove(swingBars, i)
// Reset pattern flags if broken level was part of pattern
if level == doubleTopLevel
hasDoubleTop := false
doubleTopLevel := na
if level == doubleBottomLevel
hasDoubleBottom := false
doubleBottomLevel := na
// Calculate pattern signal
patternSignal = (hasDoubleTop or hasDoubleBottom) ? 1 : 0
// Find nearest double level (only from unbroken levels)
if patternSignal == 1
if hasDoubleTop and not na(doubleTopLevel)
nearestDoubleLevel := doubleTopLevel
if hasDoubleBottom and not na(doubleBottomLevel)
if na(nearestDoubleLevel)
nearestDoubleLevel := doubleBottomLevel
else
nearestDoubleLevel := math.abs(close - doubleBottomLevel) < math.abs(close - nearestDoubleLevel) ? doubleBottomLevel : nearestDoubleLevel
else
nearestDoubleLevel := na
// Distance calculation
atr = ta.atr(atrLength)
distanceNormalizedATR = not na(nearestDoubleLevel) and not na(atr) and atr > 0 ? math.abs(close - nearestDoubleLevel) / atr : na
// Outputs (minimal plotting)
plot(patternSignal, title="Pattern Signal", color=patternSignal == 1 ? color.purple : na, style=plot.style_circles)
plot(nearestDoubleLevel, title="Nearest Double Level Price", color=color.orange)
plot(distanceNormalizedATR, title="Normalized Distance (ATR)", color=color.blue)
// Background highlight for pattern
bgcolor(patternSignal == 1 ? color.new(color.purple, 80) : na)
// Alert for pattern detection
if patternSignal == 1 and barstate.isconfirmed
alert("Double Pattern detected on " + syminfo.ticker + " at " + str.tostring(close), alert.freq_once_per_bar_close)
// Clean information table
if barstate.islast
var table infoTable = table.new(position.top_right, 2, 4, bgcolor=color.new(color.black, 70))
table.cell(infoTable, 0, 0, "Pattern:", bgcolor=color.new(color.gray, 50), text_color=color.white)
table.cell(infoTable, 1, 0, str.tostring(patternSignal), bgcolor=patternSignal == 1 ? color.new(color.purple, 50) : color.new(color.gray, 50), text_color=color.white)
table.cell(infoTable, 0, 1, "Level:", bgcolor=color.new(color.gray, 50), text_color=color.white)
table.cell(infoTable, 1, 1, str.tostring(nearestDoubleLevel, "#.####"), bgcolor=color.new(color.orange, 50), text_color=color.white)
table.cell(infoTable, 0, 2, "Unbroken Swings:", bgcolor=color.new(color.gray, 50), text_color=color.white)
table.cell(infoTable, 1, 2, str.tostring(array.size(todaySwingLevels)), bgcolor=color.new(color.gray, 50), text_color=color.white)
// Count double levels
doubleCount = 0
if array.size(swingCounts) > 0
for i = 0 to array.size(swingCounts) - 1
if array.get(swingCounts, i) >= requiredPeaks
doubleCount += 1
table.cell(infoTable, 0, 3, "Double Levels:", bgcolor=color.new(color.gray, 50), text_color=color.white)
table.cell(infoTable, 1, 3, str.tostring(doubleCount), bgcolor=color.new(color.yellow, 50), text_color=color.black)
Double Top/Bottom Screener - Today Only V4//@version=6
indicator("Double Top/Bottom Screener - Today Only", overlay=true, max_lines_count=500)
// Inputs
leftBars = input.int(5, "Left Bars")
rightBars = input.int(5, "Right Bars")
tolerance = input.float(0.02, "Max Difference (e.g., 0.02 for 2 cents)", step=0.01)
atrLength = input.int(14, "ATR Length for Normalized Distance", minval=1)
requiredPeaks = input.int(3, "Required Identical Peaks", minval=2, maxval=5)
// Declarations of persistent variables and arrays
var array resistanceLevels = array.new(0)
var array resistanceCounts = array.new(0)
var array supportLevels = array.new(0)
var array supportCounts = array.new(0)
var array resLines = array.new(0)
var array supLines = array.new(0)
var bool hasDoubleTop = false
var bool hasDoubleBottom = false
var float doubleTopLevel = na
var float doubleBottomLevel = na
var int todayStart = na
var float nearestDoubleLevel = na // Explicitly declared as na by default
// Step 1: Identify Swing Highs/Lows
swingHigh = ta.pivothigh(high, leftBars, rightBars)
swingLow = ta.pivotlow(low, leftBars, rightBars)
// Today's premarket start (04:00 AM ET)
todayStart := timestamp(syminfo.timezone, year, month, dayofmonth, 4, 0, 0)
// Clear arrays and delete lines on the first bar or new day
if barstate.isfirst or (dayofmonth != dayofmonth and time >= todayStart)
// Delete all existing lines only if arrays are not empty
if array.size(resLines) > 0
for i = array.size(resLines) - 1 to 0
line.delete(array.get(resLines, i))
if array.size(supLines) > 0
for i = array.size(supLines) - 1 to 0
line.delete(array.get(supLines, i))
// Clear arrays
array.clear(resistanceLevels)
array.clear(supportLevels)
array.clear(resistanceCounts)
array.clear(supportCounts)
array.clear(resLines)
array.clear(supLines)
// Reset flags and levels
hasDoubleTop := false
hasDoubleBottom := false
doubleTopLevel := na
doubleBottomLevel := na
nearestDoubleLevel := na // Ensure reset on new day
// Add new swings only if today and after premarket
if not na(swingHigh) and time >= todayStart and dayofmonth == dayofmonth
bool isEqualHigh = false
int peakIndex = -1
float prevLevel = na
if array.size(resistanceLevels) > 0
for i = 0 to array.size(resistanceLevels) - 1
prevLevel := array.get(resistanceLevels, i)
if math.abs(swingHigh - prevLevel) <= tolerance
isEqualHigh := true
peakIndex := i
break
if isEqualHigh and peakIndex >= 0
array.set(resistanceCounts, peakIndex, array.get(resistanceCounts, peakIndex) + 1)
if array.get(resistanceCounts, peakIndex) == requiredPeaks
hasDoubleTop := true
doubleTopLevel := prevLevel
else
array.push(resistanceLevels, swingHigh)
array.push(resistanceCounts, 1)
line newResLine = line.new(bar_index - rightBars, swingHigh, bar_index, swingHigh, color=color.red, width=2, extend=extend.none)
array.push(resLines, newResLine)
if not na(swingLow) and time >= todayStart and dayofmonth == dayofmonth
bool isEqualLow = false
int peakIndex = -1
float prevLevel = na
if array.size(supportLevels) > 0
for i = 0 to array.size(supportLevels) - 1
prevLevel := array.get(supportLevels, i)
if math.abs(swingLow - prevLevel) <= tolerance
isEqualLow := true
peakIndex := i
break
if isEqualLow and peakIndex >= 0
array.set(supportCounts, peakIndex, array.get(supportCounts, peakIndex) + 1)
if array.get(supportCounts, peakIndex) == requiredPeaks
hasDoubleBottom := true
doubleBottomLevel := prevLevel
else
array.push(supportLevels, swingLow)
array.push(supportCounts, 1)
line newSupLine = line.new(bar_index - rightBars, swingLow, bar_index, swingLow, color=color.green, width=2, extend=extend.none)
array.push(supLines, newSupLine)
// Monitor and remove broken levels/lines; reset pattern if the equal level breaks
if array.size(resistanceLevels) > 0
for i = array.size(resistanceLevels) - 1 to 0
float level = array.get(resistanceLevels, i)
if close > level
line.delete(array.get(resLines, i))
array.remove(resLines, i)
array.remove(resistanceLevels, i)
array.remove(resistanceCounts, i)
if level == doubleTopLevel
hasDoubleTop := false
doubleTopLevel := na
nearestDoubleLevel := na // Reset if level breaks
if array.size(supportLevels) > 0
for i = array.size(supportLevels) - 1 to 0
float level = array.get(supportLevels, i)
if close < level
line.delete(array.get(supLines, i))
array.remove(supLines, i)
array.remove(supportLevels, i)
array.remove(supportCounts, i)
if level == doubleBottomLevel
hasDoubleBottom := false
doubleBottomLevel := na
nearestDoubleLevel := na // Reset if level breaks
// Limit arrays (after removals)
if array.size(resistanceLevels) > 10
line oldLine = array.shift(resLines)
line.delete(oldLine)
array.shift(resistanceLevels)
array.shift(resistanceCounts)
if array.size(supportLevels) > 10
line oldLine = array.shift(supLines)
line.delete(oldLine)
array.shift(supportLevels)
array.shift(supportCounts)
// Pattern Signal: 1 only if the exact required number of peaks is met
patternSignal = (hasDoubleTop or hasDoubleBottom) ? 1 : 0
// New: Nearest Double Level Price - Only update if pattern is active today and on current day
if time >= todayStart and dayofmonth == dayofmonth // Restrict to today
if patternSignal == 1 // Only set if pattern is active
if hasDoubleTop and not na(doubleTopLevel)
nearestDoubleLevel := doubleTopLevel
if hasDoubleBottom and not na(doubleBottomLevel)
nearestDoubleLevel := na(nearestDoubleLevel) ? doubleBottomLevel : (math.abs(close - doubleBottomLevel) < math.abs(close - nearestDoubleLevel) ? doubleBottomLevel : nearestDoubleLevel)
else
nearestDoubleLevel := na // Reset to na if no pattern today
else
nearestDoubleLevel := na // Reset for all historical bars
// New: Distance to Nearest Level (using ATR for normalization)
var float atr = ta.atr(atrLength)
var float distanceNormalizedATR = na
if not na(nearestDoubleLevel) and not na(atr) and atr > 0
distanceNormalizedATR := math.abs(close - nearestDoubleLevel) / atr
// Outputs
plot(patternSignal, title="Pattern Signal", color=patternSignal == 1 ? color.purple : na, style=plot.style_circles)
plot(nearestDoubleLevel, title="Nearest Double Level Price", color=color.orange)
plot(distanceNormalizedATR, title="Normalized Distance (ATR)", color=color.green)
bgcolor(patternSignal == 1 ? color.new(color.purple, 80) : na)
if patternSignal == 1 and barstate.isconfirmed
alert("Double Pattern detected on " + syminfo.ticker + " at " + str.tostring(close), alert.freq_once_per_bar_close)
if barstate.islast
var table infoTable = table.new(position.top_right, 1, 3, bgcolor=color.new(color.black, 50))
table.cell(infoTable, 0, 0, "Pattern: " + str.tostring(patternSignal), bgcolor=patternSignal == 1 ? color.purple : color.gray)
table.cell(infoTable, 0, 1, "Level: " + str.tostring(nearestDoubleLevel, "#.##"), bgcolor=color.orange)
table.cell(infoTable, 0, 2, "ATR Dist: " + str.tostring(distanceNormalizedATR, "#.##"), bgcolor=color.green)
AMHA + 4 EMAs + EMA50/200 Counter + Avg10CrossesDescription:
This script combines two types of Heikin-Ashi visualization with multiple Exponential Moving Averages (EMAs) and a counting function for EMA50/200 crossovers. The goal is to make trends more visible, measure recurring market cycles, and provide statistical context without generating trading signals.
Logic in Detail:
Adaptive Median Heikin-Ashi (AMHA):
Instead of the classic Heikin-Ashi calculation, this method uses the median of Open, High, Low, and Close. The result smooths out price movements, emphasizes trend direction, and reduces market noise.
Standard Heikin-Ashi Overlay:
Classic HA candles are also drawn in the background for comparison and transparency. Both HA types can be shifted below the chart’s price action using a customizable Offset (Ticks) parameter.
EMA Structure:
Five exponential moving averages (21, 50, 100, 200, 500) are included to highlight different trend horizons. EMA50 and EMA200 are emphasized, as their crossovers are widely monitored as potential trend signals. EMA21 and EMA100 serve as additional structure layers, while EMA500 represents the long-term trend.
EMA50/200 Counter:
The script counts how many bars have passed since the last EMA50/200 crossover. This makes it easy to see the age of the current trend phase. A colored label above the chart displays the current counter.
Average of the Last 10 Crossovers (Avg10Crosses):
The script stores the last 10 completed count phases and calculates their average length. This provides historical context and allows traders to compare the current cycle against typical past behavior.
Benefits for Analysis:
Clearer trend visualization through adaptive Heikin-Ashi calculation.
Multi-EMA setup for quick structural assessment.
Objective measurement of trend phase duration.
Statistical insight from the average cycle length of past EMA50/200 crosses.
Flexible visualization through adjustable offset positioning below the price chart.
Usage:
Add the indicator to your chart.
For a clean look, you may switch your chart type to “Line” or hide standard candlesticks.
Interpret visual signals:
White candles = bullish phases
Orange candles = bearish phases
EMAs = structural trend filters (e.g., EMA200 as a long-term boundary)
The counter label shows the current number of bars since the last cross, while Avg10 represents the historical mean.
Special Feature:
This script is not a trading system. It does not provide buy/sell recommendations. Instead, it serves as a visual and statistical tool for market structure analysis. The unique combination of Adaptive Median Heikin-Ashi, multi-EMA framework, and EMA50/200 crossover statistics makes it especially useful for trend-followers and swing traders who want to add cycle-length analysis to their toolkit.
Double Top/Bottom Screener - Today Only v3 //@version=6
indicator("Double Top/Bottom Screener - Today Only", overlay=true, max_lines_count=500)
// Inputs
leftBars = input.int(5, "Left Bars")
rightBars = input.int(5, "Right Bars")
tolerance = input.float(0.02, "Max Difference (e.g., 0.02 for 2 cents)", step=0.01)
atrLength = input.int(14, "ATR Length for Normalized Distance", minval=1)
requiredPeaks = input.int(3, "Required Identical Peaks", minval=2, maxval=5)
// Declarations of persistent variables and arrays
var array resistanceLevels = array.new(0)
var array resistanceCounts = array.new(0)
var array supportLevels = array.new(0)
var array supportCounts = array.new(0)
var array resLines = array.new(0)
var array supLines = array.new(0)
var bool hasDoubleTop = false
var bool hasDoubleBottom = false
var float doubleTopLevel = na
var float doubleBottomLevel = na
var int todayStart = na
var float nearestDoubleLevel = na // Explicitly declared as na by default
// Step 1: Identify Swing Highs/Lows
swingHigh = ta.pivothigh(high, leftBars, rightBars)
swingLow = ta.pivotlow(low, leftBars, rightBars)
// Today's premarket start (04:00 AM ET)
todayStart := timestamp(syminfo.timezone, year, month, dayofmonth, 4, 0, 0)
// Clear arrays and delete lines on the first bar or new day
if barstate.isfirst or (dayofmonth != dayofmonth and time >= todayStart)
// Delete all existing lines only if arrays are not empty
if array.size(resLines) > 0
for i = array.size(resLines) - 1 to 0
line.delete(array.get(resLines, i))
if array.size(supLines) > 0
for i = array.size(supLines) - 1 to 0
line.delete(array.get(supLines, i))
// Clear arrays
array.clear(resistanceLevels)
array.clear(supportLevels)
array.clear(resistanceCounts)
array.clear(supportCounts)
array.clear(resLines)
array.clear(supLines)
// Reset flags and levels
hasDoubleTop := false
hasDoubleBottom := false
doubleTopLevel := na
doubleBottomLevel := na
nearestDoubleLevel := na // Ensure reset on new day
// Add new swings only if today and after premarket
if not na(swingHigh) and time >= todayStart and dayofmonth == dayofmonth
bool isEqualHigh = false
int peakIndex = -1
float prevLevel = na
if array.size(resistanceLevels) > 0
for i = 0 to array.size(resistanceLevels) - 1
prevLevel := array.get(resistanceLevels, i)
if math.abs(swingHigh - prevLevel) <= tolerance
isEqualHigh := true
peakIndex := i
break
if isEqualHigh and peakIndex >= 0
array.set(resistanceCounts, peakIndex, array.get(resistanceCounts, peakIndex) + 1)
if array.get(resistanceCounts, peakIndex) == requiredPeaks
hasDoubleTop := true
doubleTopLevel := prevLevel
else
array.push(resistanceLevels, swingHigh)
array.push(resistanceCounts, 1)
line newResLine = line.new(bar_index - rightBars, swingHigh, bar_index, swingHigh, color=color.red, width=2, extend=extend.none)
array.push(resLines, newResLine)
if not na(swingLow) and time >= todayStart and dayofmonth == dayofmonth
bool isEqualLow = false
int peakIndex = -1
float prevLevel = na
if array.size(supportLevels) > 0
for i = 0 to array.size(supportLevels) - 1
prevLevel := array.get(supportLevels, i)
if math.abs(swingLow - prevLevel) <= tolerance
isEqualLow := true
peakIndex := i
break
if isEqualLow and peakIndex >= 0
array.set(supportCounts, peakIndex, array.get(supportCounts, peakIndex) + 1)
if array.get(supportCounts, peakIndex) == requiredPeaks
hasDoubleBottom := true
doubleBottomLevel := prevLevel
else
array.push(supportLevels, swingLow)
array.push(supportCounts, 1)
line newSupLine = line.new(bar_index - rightBars, swingLow, bar_index, swingLow, color=color.green, width=2, extend=extend.none)
array.push(supLines, newSupLine)
// Monitor and remove broken levels/lines; reset pattern if the equal level breaks
if array.size(resistanceLevels) > 0
for i = array.size(resistanceLevels) - 1 to 0
float level = array.get(resistanceLevels, i)
if close > level
line.delete(array.get(resLines, i))
array.remove(resLines, i)
array.remove(resistanceLevels, i)
array.remove(resistanceCounts, i)
if level == doubleTopLevel
hasDoubleTop := false
doubleTopLevel := na
nearestDoubleLevel := na // Reset if level breaks
if array.size(supportLevels) > 0
for i = array.size(supportLevels) - 1 to 0
float level = array.get(supportLevels, i)
if close < level
line.delete(array.get(supLines, i))
array.remove(supLines, i)
array.remove(supportLevels, i)
array.remove(supportCounts, i)
if level == doubleBottomLevel
hasDoubleBottom := false
doubleBottomLevel := na
nearestDoubleLevel := na // Reset if level breaks
// Limit arrays (after removals)
if array.size(resistanceLevels) > 10
line oldLine = array.shift(resLines)
line.delete(oldLine)
array.shift(resistanceLevels)
array.shift(resistanceCounts)
if array.size(supportLevels) > 10
line oldLine = array.shift(supLines)
line.delete(oldLine)
array.shift(supportLevels)
array.shift(supportCounts)
// Pattern Signal: 1 only if the exact required number of peaks is met
patternSignal = (hasDoubleTop or hasDoubleBottom) ? 1 : 0
// New: Nearest Double Level Price - Only update if pattern is active today
if time >= todayStart and dayofmonth == dayofmonth // Restrict to today
if (hasDoubleTop and not na(doubleTopLevel)) or (hasDoubleBottom and not na(doubleBottomLevel))
if hasDoubleTop and not na(doubleTopLevel)
nearestDoubleLevel := doubleTopLevel
if hasDoubleBottom and not na(doubleBottomLevel)
nearestDoubleLevel := na(nearestDoubleLevel) ? doubleBottomLevel : (math.abs(close - doubleBottomLevel) < math.abs(close - nearestDoubleLevel) ? doubleBottomLevel : nearestDoubleLevel)
else
nearestDoubleLevel := na // Reset to na if no pattern today
else
nearestDoubleLevel := na // Reset for historical bars
// New: Distance to Nearest Level (using ATR for normalization)
var float atr = ta.atr(atrLength)
var float distanceNormalizedATR = na
if not na(nearestDoubleLevel) and not na(atr) and atr > 0
distanceNormalizedATR := math.abs(close - nearestDoubleLevel) / atr
// Outputs
plot(patternSignal, title="Pattern Signal", color=patternSignal == 1 ? color.purple : na, style=plot.style_circles)
plot(nearestDoubleLevel, title="Nearest Double Level Price", color=color.orange)
plot(distanceNormalizedATR, title="Normalized Distance (ATR)", color=color.green)
bgcolor(patternSignal == 1 ? color.new(color.purple, 80) : na)
if patternSignal == 1 and barstate.isconfirmed
alert("Double Pattern detected on " + syminfo.ticker + " at " + str.tostring(close), alert.freq_once_per_bar_close)
if barstate.islast
var table infoTable = table.new(position.top_right, 1, 3, bgcolor=color.new(color.black, 50))
table.cell(infoTable, 0, 0, "Pattern: " + str.tostring(patternSignal), bgcolor=patternSignal == 1 ? color.purple : color.gray)
table.cell(infoTable, 0, 1, "Level: " + str.tostring(nearestDoubleLevel, "#.##"), bgcolor=color.orange)
table.cell(infoTable, 0, 2, "ATR Dist: " + str.tostring(distanceNormalizedATR, "#.##"), bgcolor=color.green)
RSI Signals Multi-Layer RSI System with Classical Divergence**DrFX RSI Signals Fixed** is an advanced RSI-based trading system that combines duration-filtered extreme conditions with classical divergence detection and momentum confirmation. This enhanced version addresses common RSI false signals through multi-layer filtering while adding proper divergence analysis for identifying high-probability reversal points.
**Core Innovation & Originality**
This indicator uniquely integrates five analytical layers:
1. **Duration-Validated Extreme Zones** - Confirms RSI has remained overbought/oversold for minimum bars within lookback period
2. **Classical Divergence Detection** - Proper implementation comparing swing highs/lows in both price and RSI
3. **Momentum Confirmation Signals** - RSI crossing 50-line after extreme conditions for trend confirmation
4. **Multi-Signal Classification** - Four distinct signal types (Buy, Sell, Strong Buy, Strong Sell, Momentum)
5. **Visual Zone Highlighting** - Background coloring for instant extreme zone identification
**Technical Implementation & Improvements**
**Enhanced Duration Filter:**
Unlike the previous version, this system uses a refined approach:
```
for i = 0 to lookback_bars - 1
if rsi > overbought
barsInOverbought := barsInOverbought + 1
```
This counts actual bars within the lookback period (default 20 bars) where RSI was extreme, requiring minimum duration (default 4 bars) for signal validation.
**Classical Divergence Detection:**
The system implements proper divergence analysis, a significant improvement over simple delta comparison:
**Bullish Divergence Logic:**
- Price makes lower low: `low < prevPriceLow`
- RSI makes higher low: `rsi > prevRsiLow`
- Indicates weakening downward momentum despite lower prices
**Bearish Divergence Logic:**
- Price makes higher high: `high > prevPriceHigh`
- RSI makes lower high: `rsi < prevRsiHigh`
- Indicates weakening upward momentum despite higher prices
**Signal Generation Framework:**
**Primary Signals:**
- **Buy Signal**: RSI crosses above oversold (30) after meeting duration requirements
- **Sell Signal**: RSI crosses below overbought (70) after meeting duration requirements
**Strong Signals:**
- **Strong Buy**: Buy signal + bullish divergence confirmation
- **Strong Sell**: Sell signal + bearish divergence confirmation
**Momentum Signals:**
- **Momentum Buy (M+)**: RSI crosses above 50 after recent oversold conditions
- **Momentum Sell (M-)**: RSI crosses below 50 after recent overbought conditions
**What Makes This Version Superior**
**Compared to Standard RSI:**
1. **Duration Requirement**: Prevents signals on brief RSI spikes
2. **Lookback Validation**: Ensures extreme conditions actually occurred recently
3. **Proper Divergence**: Uses swing high/low comparison, not just bar-to-bar deltas
4. **Momentum Layer**: Adds trend confirmation via 50-line crosses
**Compared to Previous Version:**
1. **Pine Script v5**: Modern syntax with improved performance
2. **Configurable Parameters**: All values adjustable via inputs
3. **Better Divergence**: Classical divergence logic replaces simplified delta method
4. **Additional Signals**: Momentum confirmations for trend following
5. **Visual Enhancements**: Background coloring and improved signal differentiation
6. **Alert System**: Built-in alert conditions for all signal types
**Parameter Configuration**
**Customizable Inputs:**
- **Overbought Level** (70): Upper threshold, range 50-90
- **Oversold Level** (30): Lower threshold, range 10-50
- **RSI Period** (14): Calculation period, range 2-50
- **Minimum Duration** (4): Required bars in extreme zone, range 1-20
- **Lookback Bars** (20): Period to check for extreme conditions, range 5-100
- **Divergence Lookback** (5): Period for divergence swing comparison, range 2-20
**Optimization Guidelines:**
- **Shorter Duration** (2-3): More frequent signals, higher noise
- **Longer Duration** (5-7): Fewer signals, better quality
- **Smaller Lookback** (10-15): Faster response, may miss context
- **Larger Lookback** (30-50): More context, potentially delayed signals
**Signal Interpretation Guide**
**Visual Signal Hierarchy:**
**Light Green Triangle (Buy):**
- RSI recovered from oversold
- Duration requirements met
- Entry on reversal from oversold territory
**Light Red Triangle (Sell):**
- RSI declined from overbought
- Duration requirements met
- Entry on reversal from overbought territory
**Blue Triangle (Strong Buy):**
- Buy signal with bullish divergence
- Highest probability long setup
- Price made lower low, RSI made higher low
**Magenta Triangle (Strong Sell):**
- Sell signal with bearish divergence
- Highest probability short setup
- Price made higher high, RSI made lower high
**Tiny Green Circle (M+):**
- RSI crossed above 50 after oversold
- Momentum confirmation for uptrend
- Secondary entry or trend confirmation
**Tiny Red Circle (M-):**
- RSI crossed below 50 after overbought
- Momentum confirmation for downtrend
- Secondary entry or trend confirmation
**Background Coloring:**
- **Light Red Background**: RSI > 70 (overbought zone)
- **Light Green Background**: RSI < 30 (oversold zone)
**Trading Strategy Application**
**Conservative Approach (Strong Signals Only):**
1. Wait for blue/magenta triangles (divergence confirmed)
2. Enter on signal bar close or next bar open
3. Stop loss beyond recent swing high/low
4. Target minimum 2:1 risk/reward ratio
**Aggressive Approach (All Signals):**
1. Take light green/red triangles for earlier entries
2. Use momentum circles as confirmation
3. Tighter stops with partial profit taking
4. Scale positions based on signal strength
**Momentum Trading:**
1. Use momentum signals (M+/M-) as trend filters
2. Take primary signals aligned with momentum direction
3. Avoid counter-momentum signals in strong trends
4. Exit when opposing momentum signal appears
**Multi-Timeframe Strategy:**
1. Check higher timeframe for strong signals
2. Execute on lower timeframe primary signals
3. Use momentum signals for position management
4. Align all timeframe signals for best probability
**Optimal Market Conditions**
**Best Performance:**
- Mean-reverting markets with clear RSI extremes
- Range-bound or consolidating conditions
- Markets respecting support/resistance levels
- Timeframes: 15min to 4H for active trading
**Strong Signal Advantages:**
- Divergence signals often mark major turning points
- Work well at market structure levels
- Effective in both trending and ranging markets
- Higher success rate justifies waiting for setup
**Momentum Signal Benefits:**
- Confirms trend direction after extreme readings
- Useful for adding to positions
- Helps avoid counter-trend trades
- Works well in trending markets where reversals fail
**Technical Advantages**
**Divergence Accuracy:**
The improved divergence detection uses proper swing analysis rather than simple bar-to-bar comparison. This identifies genuine momentum shifts where price action diverges from oscillator movement over a meaningful period.
**Duration Logic:**
The for-loop counting method ensures the system checks actual RSI values within the lookback period, not just whether RSI touched levels. This distinguishes between sustained conditions and brief spikes.
**Momentum Filter:**
The 50-line crosses after extreme conditions provide an additional confirmation layer, helping traders distinguish between failed reversals (no momentum follow-through) and sustained moves (momentum confirmation).
**Risk Management Integration**
**Signal Priority:**
1. **Highest**: Strong signals with divergence (blue/magenta triangles)
2. **Medium**: Primary signals without divergence (light green/red triangles)
3. **Confirmation**: Momentum signals (tiny circles)
**Position Sizing:**
- Larger positions on strong signals (divergence present)
- Standard positions on primary signals
- Smaller positions or adds on momentum signals
**Stop Placement:**
- Beyond recent swing structure
- Below/above divergence swing low/high for strong signals
- Trail stops when momentum signals align with position
**Alert System**
Built-in alert conditions for:
- Buy Signal: RSI buy without divergence
- Sell Signal: RSI sell without divergence
- Strong Buy Alert: Buy with bullish divergence
- Strong Sell Alert: Sell with bearish divergence
Configure alerts via TradingView's alert system to receive notifications for chosen signal types.
**Important Considerations**
**Strengths:**
- Multiple confirmation layers reduce false signals
- Classical divergence improves reversal detection
- Momentum signals add trend-following capability
- Highly customizable for different trading styles
- No repainting - all signals fixed at bar close
**Limitations:**
- Duration requirements may cause missed quick reversals
- Divergence lookback period affects sensitivity
- Not suitable as standalone system
- Requires understanding of RSI principles and divergence concepts
**Best Practices:**
- Combine with price action and support/resistance
- Use higher timeframe context for directional bias
- Respect overall market trend and structure
- Implement proper position sizing based on signal type
- Test parameters on your specific instrument and timeframe
**Comparison Summary**
This enhanced version represents a significant upgrade:
- Upgraded to Pine Script v5 modern standards
- Proper classical divergence detection (not simplified)
- Added momentum confirmation signals
- Fully customizable parameters via inputs
- Visual background zone highlighting
- Comprehensive alert system
- Better signal differentiation through color coding
The system transforms basic RSI analysis into a multi-dimensional trading tool suitable for various market conditions and trading styles.
**Disclaimer**: This indicator is designed for educational and analytical purposes. While the multi-layer filtering and classical divergence detection improve upon standard RSI implementations, no indicator guarantees profitable trades. The duration filtering reduces false signals but may delay entries. Divergence signals, while statistically favorable, can fail in strong trending conditions. Always use proper risk management, position sizing, and stop-loss orders. Consider multiple confirmation methods and market context before making trading decisions. Past performance does not guarantee future results.
Double Top/Bottom Screener - Today Only v2 //@version=6
indicator("Double Top/Bottom Screener - Today Only", overlay=true, max_lines_count=500)
// Inputs
leftBars = input.int(5, "Left Bars")
rightBars = input.int(5, "Right Bars")
tolerance = input.float(0.02, "Max Difference (e.g., 0.02 for 2 cents)", step=0.01)
atrLength = input.int(14, "ATR Length for Normalized Distance", minval=1)
requiredPeaks = input.int(3, "Required Identical Peaks", minval=2, maxval=5)
// Declarations of persistent variables and arrays
var array resistanceLevels = array.new(0)
var array resistanceCounts = array.new(0)
var array supportLevels = array.new(0)
var array supportCounts = array.new(0)
var array resLines = array.new(0)
var array supLines = array.new(0)
var bool hasDoubleTop = false
var bool hasDoubleBottom = false
var float doubleTopLevel = na
var float doubleBottomLevel = na
var int todayStart = na
// Step 1: Identify Swing Highs/Lows
swingHigh = ta.pivothigh(high, leftBars, rightBars)
swingLow = ta.pivotlow(low, leftBars, rightBars)
// Today's premarket start (04:00 AM ET)
todayStart := timestamp(syminfo.timezone, year, month, dayofmonth, 4, 0, 0)
// Clear arrays and delete lines on the first bar or new day
if barstate.isfirst or (dayofmonth != dayofmonth and time >= todayStart)
// Delete all existing lines only if arrays are not empty
if array.size(resLines) > 0
for i = array.size(resLines) - 1 to 0
line.delete(array.get(resLines, i))
if array.size(supLines) > 0
for i = array.size(supLines) - 1 to 0
line.delete(array.get(supLines, i))
// Clear arrays
array.clear(resistanceLevels)
array.clear(supportLevels)
array.clear(resistanceCounts)
array.clear(supportCounts)
array.clear(resLines)
array.clear(supLines)
// Reset flags
hasDoubleTop := false
hasDoubleBottom := false
doubleTopLevel := na
doubleBottomLevel := na
// Add new swings only if today and after premarket
if not na(swingHigh) and time >= todayStart and dayofmonth == dayofmonth
bool isEqualHigh = false
int peakIndex = -1
float prevLevel = na
if array.size(resistanceLevels) > 0
for i = 0 to array.size(resistanceLevels) - 1
prevLevel := array.get(resistanceLevels, i)
if math.abs(swingHigh - prevLevel) <= tolerance
isEqualHigh := true
peakIndex := i
break
if isEqualHigh and peakIndex >= 0
array.set(resistanceCounts, peakIndex, array.get(resistanceCounts, peakIndex) + 1)
if array.get(resistanceCounts, peakIndex) == requiredPeaks
hasDoubleTop := true
doubleTopLevel := prevLevel
else
array.push(resistanceLevels, swingHigh)
array.push(resistanceCounts, 1)
line newResLine = line.new(bar_index - rightBars, swingHigh, bar_index, swingHigh, color=color.red, width=2, extend=extend.none)
array.push(resLines, newResLine)
if not na(swingLow) and time >= todayStart and dayofmonth == dayofmonth
bool isEqualLow = false
int peakIndex = -1
float prevLevel = na
if array.size(supportLevels) > 0
for i = 0 to array.size(supportLevels) - 1
prevLevel := array.get(supportLevels, i)
if math.abs(swingLow - prevLevel) <= tolerance
isEqualLow := true
peakIndex := i
break
if isEqualLow and peakIndex >= 0
array.set(supportCounts, peakIndex, array.get(supportCounts, peakIndex) + 1)
if array.get(supportCounts, peakIndex) == requiredPeaks
hasDoubleBottom := true
doubleBottomLevel := prevLevel
else
array.push(supportLevels, swingLow)
array.push(supportCounts, 1)
line newSupLine = line.new(bar_index - rightBars, swingLow, bar_index, swingLow, color=color.green, width=2, extend=extend.none)
array.push(supLines, newSupLine)
// Monitor and remove broken levels/lines; reset pattern if the equal level breaks
if array.size(resistanceLevels) > 0
for i = array.size(resistanceLevels) - 1 to 0
float level = array.get(resistanceLevels, i)
if close > level
line.delete(array.get(resLines, i))
array.remove(resLines, i)
array.remove(resistanceLevels, i)
array.remove(resistanceCounts, i)
if level == doubleTopLevel
hasDoubleTop := false
doubleTopLevel := na
if array.size(supportLevels) > 0
for i = array.size(supportLevels) - 1 to 0
float level = array.get(supportLevels, i)
if close < level
line.delete(array.get(supLines, i))
array.remove(supLines, i)
array.remove(supportLevels, i)
array.remove(supportCounts, i)
if level == doubleBottomLevel
hasDoubleBottom := false
doubleBottomLevel := na
// Limit arrays (after removals)
if array.size(resistanceLevels) > 10
line oldLine = array.shift(resLines)
line.delete(oldLine)
array.shift(resistanceLevels)
array.shift(resistanceCounts)
if array.size(supportLevels) > 10
line oldLine = array.shift(supLines)
line.delete(oldLine)
array.shift(supportLevels)
array.shift(supportCounts)
// Pattern Signal: 1 only if the exact required number of peaks is met
patternSignal = (hasDoubleTop or hasDoubleBottom) ? 1 : 0
// New: Nearest Double Level Price
var float nearestDoubleLevel = na
if hasDoubleTop and not na(doubleTopLevel)
nearestDoubleLevel := doubleTopLevel
if hasDoubleBottom and not na(doubleBottomLevel)
nearestDoubleLevel := na(nearestDoubleLevel) ? doubleBottomLevel : (math.abs(close - doubleBottomLevel) < math.abs(close - nearestDoubleLevel) ? doubleBottomLevel : nearestDoubleLevel)
// New: Distance to Nearest Level (using ATR for normalization)
var float atr = ta.atr(atrLength)
var float distanceNormalizedATR = na
if not na(nearestDoubleLevel) and not na(atr) and atr > 0
distanceNormalizedATR := math.abs(close - nearestDoubleLevel) / atr
// Optional Bounce Signal (for reference)
bounceSignal = 0
if array.size(resistanceLevels) > 0
for i = 0 to array.size(resistanceLevels) - 1
float level = array.get(resistanceLevels, i)
if low <= level and high >= level and close < level
bounceSignal := 1
if array.size(supportLevels) > 0
for i = 0 to array.size(supportLevels) - 1
float level = array.get(supportLevels, i)
if high >= level and low <= level and close > level
bounceSignal := 1
// Outputs
plot(patternSignal, title="Pattern Signal", color=patternSignal == 1 ? color.purple : na, style=plot.style_circles)
plot(bounceSignal, title="Bounce Signal", color=bounceSignal == 1 ? color.yellow : na, style=plot.style_circles)
plot(nearestDoubleLevel, title="Nearest Double Level Price", color=color.orange)
plot(distanceNormalizedATR, title="Normalized Distance (ATR)", color=color.green)
bgcolor(patternSignal == 1 ? color.new(color.purple, 80) : na)
if patternSignal == 1 and barstate.isconfirmed
alert("Double Pattern detected on " + syminfo.ticker + " at " + str.tostring(close), alert.freq_once_per_bar_close)
if barstate.islast
var table infoTable = table.new(position.top_right, 1, 4, bgcolor=color.new(color.black, 50))
table.cell(infoTable, 0, 0, "Pattern: " + str.tostring(patternSignal), bgcolor=patternSignal == 1 ? color.purple : color.gray)
table.cell(infoTable, 0, 1, "Bounce: " + str.tostring(bounceSignal), bgcolor=bounceSignal == 1 ? color.yellow : color.gray)
table.cell(infoTable, 0, 2, "Level: " + str.tostring(nearestDoubleLevel, "#.##"), bgcolor=color.orange)
table.cell(infoTable, 0, 3, "ATR Dist: " + str.tostring(distanceNormalizedATR, "#.##"), bgcolor=color.green)
Double Top/Bottom Screener - Today Only//@version=6
indicator("Double Top/Bottom Screener - Today Only", overlay=true, max_lines_count=500)
// Inputs
leftBars = input.int(5, "Left Bars")
rightBars = input.int(5, "Right Bars")
tolerance = input.float(0.02, "Max Difference (e.g., 0.02 for 2 cents)", step=0.01)
atrLength = input.int(14, "ATR Length for Normalized Distance", minval=1)
requiredPeaks = input.int(3, "Required Identical Peaks", minval=2, maxval=5)
// Declarations of persistent variables and arrays
var array resistanceLevels = array.new(0)
var array resistanceCounts = array.new(0)
var array supportLevels = array.new(0)
var array supportCounts = array.new(0)
var array resLines = array.new(0)
var array supLines = array.new(0)
var bool hasDoubleTop = false
var bool hasDoubleBottom = false
var float doubleTopLevel = na
var float doubleBottomLevel = na
var int todayStart = na
// Step 1: Identify Swing Highs/Lows
swingHigh = ta.pivothigh(high, leftBars, rightBars)
swingLow = ta.pivotlow(low, leftBars, rightBars)
// Today's premarket start (04:00 AM ET)
todayStart := timestamp(syminfo.timezone, year, month, dayofmonth, 4, 0, 0)
// Clear arrays and delete lines on the first bar or new day
if barstate.isfirst or (dayofmonth != dayofmonth and time >= todayStart)
// Delete all existing lines
for i = array.size(resLines) - 1 to 0
line.delete(array.get(resLines, i))
for i = array.size(supLines) - 1 to 0
line.delete(array.get(supLines, i))
// Clear arrays
array.clear(resistanceLevels)
array.clear(supportLevels)
array.clear(resistanceCounts)
array.clear(supportCounts)
array.clear(resLines)
array.clear(supLines)
// Reset flags
hasDoubleTop := false
hasDoubleBottom := false
doubleTopLevel := na
doubleBottomLevel := na
// Add new swings only if today and after premarket
if not na(swingHigh) and time >= todayStart and dayofmonth == dayofmonth
bool isEqualHigh = false
int peakIndex = -1
float prevLevel = na
if array.size(resistanceLevels) > 0
for i = 0 to array.size(resistanceLevels) - 1
prevLevel := array.get(resistanceLevels, i)
if math.abs(swingHigh - prevLevel) <= tolerance
isEqualHigh := true
peakIndex := i
break
if isEqualHigh and peakIndex >= 0
array.set(resistanceCounts, peakIndex, array.get(resistanceCounts, peakIndex) + 1)
if array.get(resistanceCounts, peakIndex) == requiredPeaks
hasDoubleTop := true
doubleTopLevel := prevLevel
else
array.push(resistanceLevels, swingHigh)
array.push(resistanceCounts, 1)
line newResLine = line.new(bar_index - rightBars, swingHigh, bar_index, swingHigh, color=color.red, width=2, extend=extend.none)
array.push(resLines, newResLine)
if not na(swingLow) and time >= todayStart and dayofmonth == dayofmonth
bool isEqualLow = false
int peakIndex = -1
float prevLevel = na
if array.size(supportLevels) > 0
for i = 0 to array.size(supportLevels) - 1
prevLevel := array.get(supportLevels, i)
if math.abs(swingLow - prevLevel) <= tolerance
isEqualLow := true
peakIndex := i
break
if isEqualLow and peakIndex >= 0
array.set(supportCounts, peakIndex, array.get(supportCounts, peakIndex) + 1)
if array.get(supportCounts, peakIndex) == requiredPeaks
hasDoubleBottom := true
doubleBottomLevel := prevLevel
else
array.push(supportLevels, swingLow)
array.push(supportCounts, 1)
line newSupLine = line.new(bar_index - rightBars, swingLow, bar_index, swingLow, color=color.green, width=2, extend=extend.none)
array.push(supLines, newSupLine)
// Monitor and remove broken levels/lines; reset pattern if the equal level breaks
if array.size(resistanceLevels) > 0
for i = array.size(resistanceLevels) - 1 to 0
float level = array.get(resistanceLevels, i)
if close > level
line.delete(array.get(resLines, i))
array.remove(resLines, i)
array.remove(resistanceLevels, i)
array.remove(resistanceCounts, i)
if level == doubleTopLevel
hasDoubleTop := false
doubleTopLevel := na
if array.size(supportLevels) > 0
for i = array.size(supportLevels) - 1 to 0
float level = array.get(supportLevels, i)
if close < level
line.delete(array.get(supLines, i))
array.remove(supLines, i)
array.remove(supportLevels, i)
array.remove(supportCounts, i)
if level == doubleBottomLevel
hasDoubleBottom := false
doubleBottomLevel := na
// Limit arrays (after removals)
if array.size(resistanceLevels) > 10
line oldLine = array.shift(resLines)
line.delete(oldLine)
array.shift(resistanceLevels)
array.shift(resistanceCounts)
if array.size(supportLevels) > 10
line oldLine = array.shift(supLines)
line.delete(oldLine)
array.shift(supportLevels)
array.shift(supportCounts)
// Pattern Signal: 1 only if the exact required number of peaks is met
patternSignal = (hasDoubleTop or hasDoubleBottom) ? 1 : 0
// New: Nearest Double Level Price
var float nearestDoubleLevel = na
if hasDoubleTop and not na(doubleTopLevel)
nearestDoubleLevel := doubleTopLevel
if hasDoubleBottom and not na(doubleBottomLevel)
nearestDoubleLevel := na(nearestDoubleLevel) ? doubleBottomLevel : (math.abs(close - doubleBottomLevel) < math.abs(close - nearestDoubleLevel) ? doubleBottomLevel : nearestDoubleLevel)
// New: Distance to Nearest Level (using ATR for normalization)
var float atr = ta.atr(atrLength)
var float distanceNormalizedATR = na
if not na(nearestDoubleLevel) and not na(atr) and atr > 0
distanceNormalizedATR := math.abs(close - nearestDoubleLevel) / atr
// Optional Bounce Signal (for reference)
bounceSignal = 0
if array.size(resistanceLevels) > 0
for i = 0 to array.size(resistanceLevels) - 1
float level = array.get(resistanceLevels, i)
if low <= level and high >= level and close < level
bounceSignal := 1
if array.size(supportLevels) > 0
for i = 0 to array.size(supportLevels) - 1
float level = array.get(supportLevels, i)
if high >= level and low <= level and close > level
bounceSignal := 1
// Outputs
plot(patternSignal, title="Pattern Signal", color=patternSignal == 1 ? color.purple : na, style=plot.style_circles)
plot(bounceSignal, title="Bounce Signal", color=bounceSignal == 1 ? color.yellow : na, style=plot.style_circles)
plot(nearestDoubleLevel, title="Nearest Double Level Price", color=color.orange)
plot(distanceNormalizedATR, title="Normalized Distance (ATR)", color=color.green)
bgcolor(patternSignal == 1 ? color.new(color.purple, 80) : na)
if patternSignal == 1 and barstate.isconfirmed
alert("Double Pattern detected on " + syminfo.ticker + " at " + str.tostring(close), alert.freq_once_per_bar_close)
if barstate.islast
var table infoTable = table.new(position.top_right, 1, 4, bgcolor=color.new(color.black, 50))
table.cell(infoTable, 0, 0, "Pattern: " + str.tostring(patternSignal), bgcolor=patternSignal == 1 ? color.purple : color.gray)
table.cell(infoTable, 0, 1, "Bounce: " + str.tostring(bounceSignal), bgcolor=bounceSignal == 1 ? color.yellow : color.gray)
table.cell(infoTable, 0, 2, "Level: " + str.tostring(nearestDoubleLevel, "#.##"), bgcolor=color.orange)
table.cell(infoTable, 0, 3, "ATR Dist: " + str.tostring(distanceNormalizedATR, "#.##"), bgcolor=color.green)
Double Top/Bottom Screener V1//@version=6
indicator("Double Top/Bottom Screener", overlay=true, max_lines_count=500)
// Inputs
leftBars = input.int(5, "Left Bars")
rightBars = input.int(5, "Right Bars")
tolerance = input.float(0.02, "Max Difference (e.g., 0.02 for 2 cents)", step=0.01)
atrLength = input.int(14, "ATR Length for Normalized Distance", minval=1)
requiredPeaks = input.int(3, "Required Identical Peaks", minval=2, maxval=5)
// Declarations of persistent variables and arrays
var array resistanceLevels = array.new(0)
var array resistanceCounts = array.new(0)
var array supportLevels = array.new(0)
var array supportCounts = array.new(0)
var array resLines = array.new(0)
var array supLines = array.new(0)
var bool hasDoubleTop = false
var bool hasDoubleBottom = false
var float doubleTopLevel = na
var float doubleBottomLevel = na
var int todayStart = na
var bool isNewDay = false
// Step 1: Identify Swing Highs/Lows
swingHigh = ta.pivothigh(high, leftBars, rightBars)
swingLow = ta.pivotlow(low, leftBars, rightBars)
// Today's premarket start (04:00 AM ET)
if dayofmonth != dayofmonth
todayStart := timestamp(syminfo.timezone, year, month, dayofmonth, 4, 0, 0)
isNewDay := true
else
isNewDay := false
// Clear arrays and reset flags only once at premarket start
if isNewDay and time >= todayStart
array.clear(resistanceLevels)
array.clear(supportLevels)
array.clear(resistanceCounts)
array.clear(supportCounts)
array.clear(resLines)
array.clear(supLines)
hasDoubleTop := false
hasDoubleBottom := false
doubleTopLevel := na
doubleBottomLevel := na
// Add new swings and check for identical peaks
if not na(swingHigh) and time >= todayStart
bool isEqualHigh = false
int peakIndex = -1
float prevLevel = na
if array.size(resistanceLevels) > 0
for i = 0 to array.size(resistanceLevels) - 1
prevLevel := array.get(resistanceLevels, i)
if math.abs(swingHigh - prevLevel) <= tolerance
isEqualHigh := true
peakIndex := i
break
if isEqualHigh and peakIndex >= 0
array.set(resistanceCounts, peakIndex, array.get(resistanceCounts, peakIndex) + 1)
if array.get(resistanceCounts, peakIndex) == requiredPeaks
hasDoubleTop := true
doubleTopLevel := prevLevel
else
array.push(resistanceLevels, swingHigh)
array.push(resistanceCounts, 1)
line newResLine = line.new(bar_index - rightBars, swingHigh, bar_index, swingHigh, color=color.red, width=2, extend=extend.right)
array.push(resLines, newResLine)
if not na(swingLow) and time >= todayStart
bool isEqualLow = false
int peakIndex = -1
float prevLevel = na
if array.size(supportLevels) > 0
for i = 0 to array.size(supportLevels) - 1
prevLevel := array.get(supportLevels, i)
if math.abs(swingLow - prevLevel) <= tolerance
isEqualLow := true
peakIndex := i
break
if isEqualLow and peakIndex >= 0
array.set(supportCounts, peakIndex, array.get(supportCounts, peakIndex) + 1)
if array.get(supportCounts, peakIndex) == requiredPeaks
hasDoubleBottom := true
doubleBottomLevel := prevLevel
else
array.push(supportLevels, swingLow)
array.push(supportCounts, 1)
line newSupLine = line.new(bar_index - rightBars, swingLow, bar_index, swingLow, color=color.green, width=2, extend=extend.right)
array.push(supLines, newSupLine)
// Monitor and remove broken levels/lines; reset pattern if the equal level breaks
if array.size(resistanceLevels) > 0
for i = array.size(resistanceLevels) - 1 to 0
float level = array.get(resistanceLevels, i)
if close > level
line.delete(array.get(resLines, i))
array.remove(resLines, i)
array.remove(resistanceLevels, i)
array.remove(resistanceCounts, i)
if level == doubleTopLevel
hasDoubleTop := false
doubleTopLevel := na
if array.size(supportLevels) > 0
for i = array.size(supportLevels) - 1 to 0
float level = array.get(supportLevels, i)
if close < level
line.delete(array.get(supLines, i))
array.remove(supLines, i)
array.remove(supportLevels, i)
array.remove(supportCounts, i)
if level == doubleBottomLevel
hasDoubleBottom := false
doubleBottomLevel := na
// Limit arrays (after removals)
if array.size(resistanceLevels) > 10
line oldLine = array.shift(resLines)
line.delete(oldLine)
array.shift(resistanceLevels)
array.shift(resistanceCounts)
if array.size(supportLevels) > 10
line oldLine = array.shift(supLines)
line.delete(oldLine)
array.shift(supportLevels)
array.shift(supportCounts)
// Pattern Signal: 1 only if the exact required number of peaks is met
patternSignal = (hasDoubleTop or hasDoubleBottom) and (array.size(resistanceCounts) > 0 and array.get(resistanceCounts, array.size(resistanceCounts) - 1) == requiredPeaks or array.size(supportCounts) > 0 and array.get(supportCounts, array.size(supportCounts) - 1) == requiredPeaks) ? 1 : 0
// New: Nearest Double Level Price
var float nearestDoubleLevel = na
if hasDoubleTop and not na(doubleTopLevel)
nearestDoubleLevel := doubleTopLevel
if hasDoubleBottom and not na(doubleBottomLevel)
nearestDoubleLevel := na(nearestDoubleLevel) ? doubleBottomLevel : (math.abs(close - doubleBottomLevel) < math.abs(close - nearestDoubleLevel) ? doubleBottomLevel : nearestDoubleLevel)
// New: Distance to Nearest Level (using ATR for normalization)
var float atr = ta.atr(atrLength)
var float distanceNormalizedATR = na
if not na(nearestDoubleLevel) and not na(atr) and atr > 0
distanceNormalizedATR := math.abs(close - nearestDoubleLevel) / atr
// Optional Bounce Signal (for reference)
bounceSignal = 0
if array.size(resistanceLevels) > 0
for i = 0 to array.size(resistanceLevels) - 1
float level = array.get(resistanceLevels, i)
if low <= level and high >= level and close < level
bounceSignal := 1
if array.size(supportLevels) > 0
for i = 0 to array.size(supportLevels) - 1
float level = array.get(supportLevels, i)
if high >= level and low <= level and close > level
bounceSignal := 1
// Outputs
plot(patternSignal, title="Pattern Signal", color=patternSignal == 1 ? color.purple : na, style=plot.style_circles)
plot(bounceSignal, title="Bounce Signal", color=bounceSignal == 1 ? color.yellow : na, style=plot.style_circles)
plot(nearestDoubleLevel, title="Nearest Double Level Price", color=color.orange)
plot(distanceNormalizedATR, title="Normalized Distance (ATR)", color=color.green)
bgcolor(patternSignal == 1 ? color.new(color.purple, 80) : na)
if patternSignal == 1 and barstate.isconfirmed
alert("Double Pattern detected on " + syminfo.ticker + " at " + str.tostring(close), alert.freq_once_per_bar_close)
if barstate.islast
var table infoTable = table.new(position.top_right, 1, 4, bgcolor=color.new(color.black, 50))
table.cell(infoTable, 0, 0, "Pattern: " + str.tostring(patternSignal), bgcolor=patternSignal == 1 ? color.purple : color.gray)
table.cell(infoTable, 0, 1, "Bounce: " + str.tostring(bounceSignal), bgcolor=bounceSignal == 1 ? color.yellow : color.gray)
table.cell(infoTable, 0, 2, "Level: " + str.tostring(nearestDoubleLevel, "#.##"), bgcolor=color.orange)
table.cell(infoTable, 0, 3, "ATR Dist: " + str.tostring(distanceNormalizedATR, "#.##"), bgcolor=color.green)
Double Top/Bottom Screener 3-5 peaks //@version=6
indicator("Double Top/Bottom Screener", overlay=true, max_lines_count=500)
// Inputs
leftBars = input.int(5, "Left Bars")
rightBars = input.int(5, "Right Bars")
tolerance = input.float(0.02, "Max Difference (e.g., 0.02 for 2 cents)", step=0.01)
atrLength = input.int(14, "ATR Length for Normalized Distance", minval=1)
maxPeaks = input.int(5, "Max Identical Peaks", minval=2, maxval=5)
// Declarations of persistent variables and arrays
var array resistanceLevels = array.new(0)
var array resistanceCounts = array.new(0)
var array supportLevels = array.new(0)
var array supportCounts = array.new(0)
var array resLines = array.new(0)
var array supLines = array.new(0)
var bool hasDoubleTop = false
var bool hasDoubleBottom = false
var float doubleTopLevel = na
var float doubleBottomLevel = na
var int todayStart = na
var bool isNewDay = false
// Step 1: Identify Swing Highs/Lows
swingHigh = ta.pivothigh(high, leftBars, rightBars)
swingLow = ta.pivotlow(low, leftBars, rightBars)
// Today's premarket start (04:00 AM ET)
if dayofmonth != dayofmonth
todayStart := timestamp(syminfo.timezone, year, month, dayofmonth, 4, 0, 0)
isNewDay := true
else
isNewDay := false
// Clear arrays and reset flags only once at premarket start
if isNewDay and time >= todayStart
array.clear(resistanceLevels)
array.clear(supportLevels)
array.clear(resistanceCounts)
array.clear(supportCounts)
array.clear(resLines)
array.clear(supLines)
hasDoubleTop := false
hasDoubleBottom := false
doubleTopLevel := na
doubleBottomLevel := na
// Add new swings and check for identical peaks
if not na(swingHigh) and time >= todayStart
bool isEqualHigh = false
int peakIndex = -1
float prevLevel = na // Declare prevLevel with initial value
if array.size(resistanceLevels) > 0
for i = 0 to array.size(resistanceLevels) - 1
prevLevel := array.get(resistanceLevels, i)
if math.abs(swingHigh - prevLevel) <= tolerance
isEqualHigh := true
peakIndex := i
break
if isEqualHigh and peakIndex >= 0
array.set(resistanceCounts, peakIndex, array.get(resistanceCounts, peakIndex) + 1)
if array.get(resistanceCounts, peakIndex) >= maxPeaks
hasDoubleTop := true
doubleTopLevel := prevLevel
else
array.push(resistanceLevels, swingHigh)
array.push(resistanceCounts, 1)
line newResLine = line.new(bar_index - rightBars, swingHigh, bar_index, swingHigh, color=color.red, width=2, extend=extend.right)
array.push(resLines, newResLine)
if not na(swingLow) and time >= todayStart
bool isEqualLow = false
int peakIndex = -1
float prevLevel = na // Declare prevLevel with initial value
if array.size(supportLevels) > 0
for i = 0 to array.size(supportLevels) - 1
prevLevel := array.get(supportLevels, i)
if math.abs(swingLow - prevLevel) <= tolerance
isEqualLow := true
peakIndex := i
break
if isEqualLow and peakIndex >= 0
array.set(supportCounts, peakIndex, array.get(supportCounts, peakIndex) + 1)
if array.get(supportCounts, peakIndex) >= maxPeaks
hasDoubleBottom := true
doubleBottomLevel := prevLevel
else
array.push(supportLevels, swingLow)
array.push(supportCounts, 1)
line newSupLine = line.new(bar_index - rightBars, swingLow, bar_index, swingLow, color=color.green, width=2, extend=extend.right)
array.push(supLines, newSupLine)
// Monitor and remove broken levels/lines; reset pattern if the equal level breaks
if array.size(resistanceLevels) > 0
for i = array.size(resistanceLevels) - 1 to 0
float level = array.get(resistanceLevels, i)
if close > level
line.delete(array.get(resLines, i))
array.remove(resLines, i)
array.remove(resistanceLevels, i)
array.remove(resistanceCounts, i)
if level == doubleTopLevel
hasDoubleTop := false
doubleTopLevel := na
if array.size(supportLevels) > 0
for i = array.size(supportLevels) - 1 to 0
float level = array.get(supportLevels, i)
if close < level
line.delete(array.get(supLines, i))
array.remove(supLines, i)
array.remove(supportLevels, i)
array.remove(supportCounts, i)
if level == doubleBottomLevel
hasDoubleBottom := false
doubleBottomLevel := na
// Limit arrays (after removals)
if array.size(resistanceLevels) > 10
line oldLine = array.shift(resLines)
line.delete(oldLine)
array.shift(resistanceLevels)
array.shift(resistanceCounts)
if array.size(supportLevels) > 10
line oldLine = array.shift(supLines)
line.delete(oldLine)
array.shift(supportLevels)
array.shift(supportCounts)
// Pattern Signal: 1 if any pattern with maxPeaks is active and unbroken
patternSignal = (hasDoubleTop or hasDoubleBottom) ? 1 : 0
// New: Nearest Double Level Price
var float nearestDoubleLevel = na
if hasDoubleTop and not na(doubleTopLevel)
nearestDoubleLevel := doubleTopLevel
if hasDoubleBottom and not na(doubleBottomLevel)
nearestDoubleLevel := na(nearestDoubleLevel) ? doubleBottomLevel : (math.abs(close - doubleBottomLevel) < math.abs(close - nearestDoubleLevel) ? doubleBottomLevel : nearestDoubleLevel)
// New: Distance to Nearest Level (using ATR for normalization)
var float atr = ta.atr(atrLength)
var float distanceNormalizedATR = na
if not na(nearestDoubleLevel) and not na(atr) and atr > 0
distanceNormalizedATR := math.abs(close - nearestDoubleLevel) / atr
// Optional Bounce Signal (for reference)
bounceSignal = 0
if array.size(resistanceLevels) > 0
for i = 0 to array.size(resistanceLevels) - 1
float level = array.get(resistanceLevels, i)
if low <= level and high >= level and close < level
bounceSignal := 1
if array.size(supportLevels) > 0
for i = 0 to array.size(supportLevels) - 1
float level = array.get(supportLevels, i)
if high >= level and low <= level and close > level
bounceSignal := 1
// Outputs
plot(patternSignal, title="Pattern Signal", color=patternSignal == 1 ? color.purple : na, style=plot.style_circles)
plot(bounceSignal, title="Bounce Signal", color=bounceSignal == 1 ? color.yellow : na, style=plot.style_circles)
plot(nearestDoubleLevel, title="Nearest Double Level Price", color=color.orange)
plot(distanceNormalizedATR, title="Normalized Distance (ATR)", color=color.green)
bgcolor(patternSignal == 1 ? color.new(color.purple, 80) : na)
if patternSignal == 1 and barstate.isconfirmed
alert("Double Pattern detected on " + syminfo.ticker + " at " + str.tostring(close), alert.freq_once_per_bar_close)
if barstate.islast
var table infoTable = table.new(position.top_right, 1, 4, bgcolor=color.new(color.black, 50))
table.cell(infoTable, 0, 0, "Pattern: " + str.tostring(patternSignal), bgcolor=patternSignal == 1 ? color.purple : color.gray)
table.cell(infoTable, 0, 1, "Bounce: " + str.tostring(bounceSignal), bgcolor=bounceSignal == 1 ? color.yellow : color.gray)
table.cell(infoTable, 0, 2, "Level: " + str.tostring(nearestDoubleLevel, "#.##"), bgcolor=color.orange)
table.cell(infoTable, 0, 3, "ATR Dist: " + str.tostring(distanceNormalizedATR, "#.##"), bgcolor=color.green)
MA Pack + Cross Signals (Short vs Long)Overview
A flexible moving average pack that lets you switch between short-term trend detection and long-term trend confirmation .
Short-term mode: plots 5, 10, 20, and 50 MAs with early crossovers (10/50, 20/50).
Long-term mode: plots 50, 100, 200 MAs with Golden Cross and Death Cross signals.
Choice of SMA or EMA .
Alerts included for all crossovers.
Why Use It
Catch early trend shifts in short-term mode.
Confirm institutional trend levels in long-term mode.
Visual signals (triangles + labels) make spotting setups easy.
Alert-ready for automated trade monitoring.
Usage
Add to chart.
In settings, choose Short-term or Long-term .
Watch for markers:
Green triangles = bullish cross
Red triangles = bearish cross
Green label = Golden Cross
Red label = Death Cross
Optional: enable alerts for notifications.
Market Pressure Oscillator█ OVERVIEW
The Market Pressure Oscillator is an advanced technical indicator for TradingView, enabling traders to identify potential trend reversals and momentum shifts through candle-based pressure analysis and divergence detection. It combines a smoothed oscillator with moving average signals, overbought/oversold levels, and divergence visualization, enhanced by customizable gradients, dynamic band colors, and alerts for quick decision-making.
█ CONCEPT
The indicator measures buying or selling pressure based on candle body size (open-to-close difference) and direction, with optional smoothing for clarity and divergence detection between price action and the oscillator. It relies solely on candle data, offering insights into trend strength, overbought/oversold conditions, and potential reversals with a customizable visual presentation.
█ WHY USE IT?
- Divergence Detection: Identifies bullish and bearish divergences to reinforce signals, especially near overbought/oversold zones.
- Candle Pressure Analysis: Measures pressure based on candle body size, normalized to a ±100 scale.
- Signal Generation: Provides buy/sell signals via overbought/oversold crossovers, zero-line crossovers, moving average zero-line crossovers, and dynamic band color changes.
- Visual Clarity: Uses dynamic colors, gradients, and fill layers for intuitive chart analysis.
Flexibility: Extensive settings allow customization to individual trading preferences.
█ HOW IT WORKS?
- Candle Pressure Calculation: Computes candle body size as math.abs(close - open), normalized against the average body size over a lookback period (avgBody = ta.sma(body, len)). - Candle direction (bullish: +1, bearish: -1, neutral: 0) is multiplied by body weight to derive pressure.
- Cumulative Pressure: Sums pressure values over the lookback period (Lookback Length) and normalizes to ±100 relative to the maximum possible value.
- Smoothing: Optionally applies EMA (Smoothing Length) to normalized pressure.
- Moving Average: Calculates SMA (Moving Average Length) for trend confirmation (Moving Average (SMA)).
- Divergence Detection: Identifies bullish/bearish divergences by comparing price and oscillator pivot highs/lows within a specified range (Pivot Length). Divergence signals appear with a delay equal to the Pivot Length.
- Signals: Generates signals for:
Crossing oversold upward (buy) or overbought downward (sell).
Crossing the zero line by the oscillator or moving average (buy/sell).
Bullish/bearish divergences, marked with labels, enhancing signals, especially near overbought/oversold zones.
Dynamic band color changes when the moving average crosses MA overbought/oversold thresholds (green for oversold, red for overbought).
- Visualization: Plots the oscillator and moving average with dynamic colors, gradient fills, transparent bands, and labels, with customizable overbought/oversold levels.
Alerts: Built-in alerts for divergences, overbought/oversold crossovers, and zero-line crossovers (oscillator and moving average).
█ SETTINGS AND CUSTOMIZATION
- Lookback Length: Period for aggregating candle pressure (default: 14).
- Smoothing Length (EMA): EMA length for smoothing the oscillator (default: 1). Higher values smooth the signal but may reduce signal frequency; adjust overbought/oversold levels accordingly.
- Moving Average Length (SMA): SMA length for the moving average (default: 14, minval=1). Higher values make SMA a trend indicator, requiring adjusted MA overbought/oversold levels.
- Pivot Length (Left/Right): Candles for detecting pivot highs/lows in divergence calculations (default: 2, minval=1). Higher values reduce noise but add delay equal to the set value.
- Enable Divergence Detection: Enables divergence detection (default: true).
- Overbought/Oversold Levels: Thresholds for the oscillator (default: 30/-30) and moving average (default: 10/-10). For the moving average, no arrows appear; bands change color from gray to green (oversold) or red (overbought), reinforcing entry signals.
- Signal Type: Select signals to display: "None", "Overbought/Oversold", "Zero Line", "MA Zero Line", "All" (default: "Overbought/Oversold").
- Colors and Gradients: Customize colors for bullish/bearish oscillator, moving average, zero line, overbought/oversold levels, and divergence labels.
- Transparency: Adjust gradient fill transparency (default: 70, minval=0, maxval=100) and band/label transparency (default: 40, minval=0, maxval=100) for consistent visuals.
- Visualizations: Enable/disable moving average, gradients for zero/overbought/oversold levels, and gradient fills.
█ USAGE EXAMPLES
- Momentum Analysis: Observe the MPO Oscillator above 0 for bullish momentum or below 0 for bearish momentum. The SMA, being smoother, reacts slower and can confirm trend direction as a noise filter.
- Reversal Signals: Look for buy triangles when the oscillator crosses oversold upward, especially when the SMA is below the MA oversold threshold and the band turns green. Similarly, seek sell triangles when crossing overbought downward, with the SMA above the MA overbought threshold and the band turning red.
- Using Divergences: Treat bullish (green labels) and bearish (red labels) divergences as reinforcement for other signals, especially near overbought/oversold zones, indicating stronger potential trend reversals.
- Customization: Adjust lookback length, smoothing, and moving average length to specific instruments and timeframes to minimize false signals.
█ USER NOTES
Combine the indicator with tools like Fibonacci levels or pivot points to enhance accuracy.
Test different settings for lookback length, smoothing, and moving average length on your chosen instrument and timeframe to find optimal values.
TA█ TA Library
📊 OVERVIEW
TA is a Pine Script technical analysis library. This library provides 25+ moving averages and smoothing filters , from classic SMA/EMA to Kalman Filters and adaptive algorithms, implemented based on academic research.
🎯 Core Features
Academic Based - Algorithms follow original papers and formulas
Performance Optimized - Pre-calculated constants for faster response
Unified Interface - Consistent function design
Research Based - Integrates technical analysis research
🎯 CONCEPTS
Library Design Philosophy
This technical analysis library focuses on providing:
Academic Foundation
Algorithms based on published research papers and academic standards
Implementations that follow original mathematical formulations
Clear documentation with research references
Developer Experience
Unified interface design for consistent usage patterns
Pre-calculated constants for optimal performance
Comprehensive function collection to reduce development time
Single import statement for immediate access to all functions
Each indicator encapsulated as a simple function call - one line of code simplifies complexity
Technical Excellence
25+ carefully implemented moving averages and filters
Support for advanced algorithms like Kalman Filter and MAMA/FAMA
Optimized code structure for maintainability and reliability
Regular updates incorporating latest research developments
🚀 USING THIS LIBRARY
Import Library
//@version=6
import DCAUT/TA/1 as dta
indicator("Advanced Technical Analysis", overlay=true)
Basic Usage Example
// Classic moving average combination
ema20 = ta.ema(close, 20)
kama20 = dta.kama(close, 20)
plot(ema20, "EMA20", color.red, 2)
plot(kama20, "KAMA20", color.green, 2)
Advanced Trading System
// Adaptive moving average system
kama = dta.kama(close, 20, 2, 30)
= dta.mamaFama(close, 0.5, 0.05)
// Trend confirmation and entry signals
bullTrend = kama > kama and mamaValue > famaValue
bearTrend = kama < kama and mamaValue < famaValue
longSignal = ta.crossover(close, kama) and bullTrend
shortSignal = ta.crossunder(close, kama) and bearTrend
plot(kama, "KAMA", color.blue, 3)
plot(mamaValue, "MAMA", color.orange, 2)
plot(famaValue, "FAMA", color.purple, 2)
plotshape(longSignal, "Buy", shape.triangleup, location.belowbar, color.green)
plotshape(shortSignal, "Sell", shape.triangledown, location.abovebar, color.red)
📋 FUNCTIONS REFERENCE
ewma(source, alpha)
Calculates the Exponentially Weighted Moving Average with dynamic alpha parameter.
Parameters:
source (series float) : Series of values to process.
alpha (series float) : The smoothing parameter of the filter.
Returns: (float) The exponentially weighted moving average value.
dema(source, length)
Calculates the Double Exponential Moving Average (DEMA) of a given data series.
Parameters:
source (series float) : Series of values to process.
length (simple int) : Number of bars for the moving average calculation.
Returns: (float) The calculated Double Exponential Moving Average value.
tema(source, length)
Calculates the Triple Exponential Moving Average (TEMA) of a given data series.
Parameters:
source (series float) : Series of values to process.
length (simple int) : Number of bars for the moving average calculation.
Returns: (float) The calculated Triple Exponential Moving Average value.
zlema(source, length)
Calculates the Zero-Lag Exponential Moving Average (ZLEMA) of a given data series. This indicator attempts to eliminate the lag inherent in all moving averages.
Parameters:
source (series float) : Series of values to process.
length (simple int) : Number of bars for the moving average calculation.
Returns: (float) The calculated Zero-Lag Exponential Moving Average value.
tma(source, length)
Calculates the Triangular Moving Average (TMA) of a given data series. TMA is a double-smoothed simple moving average that reduces noise.
Parameters:
source (series float) : Series of values to process.
length (simple int) : Number of bars for the moving average calculation.
Returns: (float) The calculated Triangular Moving Average value.
frama(source, length)
Calculates the Fractal Adaptive Moving Average (FRAMA) of a given data series. FRAMA adapts its smoothing factor based on fractal geometry to reduce lag. Developed by John Ehlers.
Parameters:
source (series float) : Series of values to process.
length (simple int) : Number of bars for the moving average calculation.
Returns: (float) The calculated Fractal Adaptive Moving Average value.
kama(source, length, fastLength, slowLength)
Calculates Kaufman's Adaptive Moving Average (KAMA) of a given data series. KAMA adjusts its smoothing based on market efficiency ratio. Developed by Perry J. Kaufman.
Parameters:
source (series float) : Series of values to process.
length (simple int) : Number of bars for the efficiency calculation.
fastLength (simple int) : Fast EMA length for smoothing calculation. Optional. Default is 2.
slowLength (simple int) : Slow EMA length for smoothing calculation. Optional. Default is 30.
Returns: (float) The calculated Kaufman's Adaptive Moving Average value.
t3(source, length, volumeFactor)
Calculates the Tilson Moving Average (T3) of a given data series. T3 is a triple-smoothed exponential moving average with improved lag characteristics. Developed by Tim Tillson.
Parameters:
source (series float) : Series of values to process.
length (simple int) : Number of bars for the moving average calculation.
volumeFactor (simple float) : Volume factor affecting responsiveness. Optional. Default is 0.7.
Returns: (float) The calculated Tilson Moving Average value.
ultimateSmoother(source, length)
Calculates the Ultimate Smoother of a given data series. Uses advanced filtering techniques to reduce noise while maintaining responsiveness. Based on digital signal processing principles by John Ehlers.
Parameters:
source (series float) : Series of values to process.
length (simple int) : Number of bars for the smoothing calculation.
Returns: (float) The calculated Ultimate Smoother value.
kalmanFilter(source, processNoise, measurementNoise)
Calculates the Kalman Filter of a given data series. Optimal estimation algorithm that estimates true value from noisy observations. Based on the Kalman Filter algorithm developed by Rudolf Kalman (1960).
Parameters:
source (series float) : Series of values to process.
processNoise (simple float) : Process noise variance (Q). Controls adaptation speed. Optional. Default is 0.05.
measurementNoise (simple float) : Measurement noise variance (R). Controls smoothing. Optional. Default is 1.0.
Returns: (float) The calculated Kalman Filter value.
mcginleyDynamic(source, length)
Calculates the McGinley Dynamic of a given data series. McGinley Dynamic is an adaptive moving average that adjusts to market speed changes. Developed by John R. McGinley Jr.
Parameters:
source (series float) : Series of values to process.
length (simple int) : Number of bars for the dynamic calculation.
Returns: (float) The calculated McGinley Dynamic value.
mama(source, fastLimit, slowLimit)
Calculates the Mesa Adaptive Moving Average (MAMA) of a given data series. MAMA uses Hilbert Transform Discriminator to adapt to market cycles dynamically. Developed by John F. Ehlers.
Parameters:
source (series float) : Series of values to process.
fastLimit (simple float) : Maximum alpha (responsiveness). Optional. Default is 0.5.
slowLimit (simple float) : Minimum alpha (smoothing). Optional. Default is 0.05.
Returns: (float) The calculated Mesa Adaptive Moving Average value.
fama(source, fastLimit, slowLimit)
Calculates the Following Adaptive Moving Average (FAMA) of a given data series. FAMA follows MAMA with reduced responsiveness for crossover signals. Developed by John F. Ehlers.
Parameters:
source (series float) : Series of values to process.
fastLimit (simple float) : Maximum alpha (responsiveness). Optional. Default is 0.5.
slowLimit (simple float) : Minimum alpha (smoothing). Optional. Default is 0.05.
Returns: (float) The calculated Following Adaptive Moving Average value.
mamaFama(source, fastLimit, slowLimit)
Calculates Mesa Adaptive Moving Average (MAMA) and Following Adaptive Moving Average (FAMA).
Parameters:
source (series float) : Series of values to process.
fastLimit (simple float) : Maximum alpha (responsiveness). Optional. Default is 0.5.
slowLimit (simple float) : Minimum alpha (smoothing). Optional. Default is 0.05.
Returns: ( ) Tuple containing values.
laguerreFilter(source, length, gamma, order)
Calculates the standard N-order Laguerre Filter of a given data series. Standard Laguerre Filter uses uniform weighting across all polynomial terms. Developed by John F. Ehlers.
Parameters:
source (series float) : Series of values to process.
length (simple int) : Length for UltimateSmoother preprocessing.
gamma (simple float) : Feedback coefficient (0-1). Lower values reduce lag. Optional. Default is 0.8.
order (simple int) : The order of the Laguerre filter (1-10). Higher order increases lag. Optional. Default is 8.
Returns: (float) The calculated standard Laguerre Filter value.
laguerreBinomialFilter(source, length, gamma)
Calculates the Laguerre Binomial Filter of a given data series. Uses 6-pole feedback with binomial weighting coefficients. Developed by John F. Ehlers.
Parameters:
source (series float) : Series of values to process.
length (simple int) : Length for UltimateSmoother preprocessing.
gamma (simple float) : Feedback coefficient (0-1). Lower values reduce lag. Optional. Default is 0.5.
Returns: (float) The calculated Laguerre Binomial Filter value.
superSmoother(source, length)
Calculates the Super Smoother of a given data series. SuperSmoother is a second-order Butterworth filter from aerospace technology. Developed by John F. Ehlers.
Parameters:
source (series float) : Series of values to process.
length (simple int) : Period for the filter calculation.
Returns: (float) The calculated Super Smoother value.
rangeFilter(source, length, multiplier)
Calculates the Range Filter of a given data series. Range Filter reduces noise by filtering price movements within a dynamic range.
Parameters:
source (series float) : Series of values to process.
length (simple int) : Number of bars for the average range calculation.
multiplier (simple float) : Multiplier for the smooth range. Higher values increase filtering. Optional. Default is 2.618.
Returns: ( ) Tuple containing filtered value, trend direction, upper band, and lower band.
qqe(source, rsiLength, rsiSmooth, qqeFactor)
Calculates the Quantitative Qualitative Estimation (QQE) of a given data series. QQE is an improved RSI that reduces noise and provides smoother signals. Developed by Igor Livshin.
Parameters:
source (series float) : Series of values to process.
rsiLength (simple int) : Number of bars for the RSI calculation. Optional. Default is 14.
rsiSmooth (simple int) : Number of bars for smoothing the RSI. Optional. Default is 5.
qqeFactor (simple float) : QQE factor for volatility band width. Optional. Default is 4.236.
Returns: ( ) Tuple containing smoothed RSI and QQE trend line.
sslChannel(source, length)
Calculates the Semaphore Signal Level (SSL) Channel of a given data series. SSL Channel provides clear trend signals using moving averages of high and low prices.
Parameters:
source (series float) : Series of values to process.
length (simple int) : Number of bars for the moving average calculation.
Returns: ( ) Tuple containing SSL Up and SSL Down lines.
ma(source, length, maType)
Calculates a Moving Average based on the specified type. Universal interface supporting all moving average algorithms.
Parameters:
source (series float) : Series of values to process.
length (simple int) : Number of bars for the moving average calculation.
maType (simple MaType) : Type of moving average to calculate. Optional. Default is SMA.
Returns: (float) The calculated moving average value based on the specified type.
atr(length, maType)
Calculates the Average True Range (ATR) using the specified moving average type. Developed by J. Welles Wilder Jr.
Parameters:
length (simple int) : Number of bars for the ATR calculation.
maType (simple MaType) : Type of moving average to use for smoothing. Optional. Default is RMA.
Returns: (float) The calculated Average True Range value.
macd(source, fastLength, slowLength, signalLength, maType, signalMaType)
Calculates the Moving Average Convergence Divergence (MACD) with customizable MA types. Developed by Gerald Appel.
Parameters:
source (series float) : Series of values to process.
fastLength (simple int) : Period for the fast moving average.
slowLength (simple int) : Period for the slow moving average.
signalLength (simple int) : Period for the signal line moving average.
maType (simple MaType) : Type of moving average for main MACD calculation. Optional. Default is EMA.
signalMaType (simple MaType) : Type of moving average for signal line calculation. Optional. Default is EMA.
Returns: ( ) Tuple containing MACD line, signal line, and histogram values.
dmao(source, fastLength, slowLength, maType)
Calculates the Dual Moving Average Oscillator (DMAO) of a given data series. Uses the same algorithm as the Percentage Price Oscillator (PPO), but can be applied to any data series.
Parameters:
source (series float) : Series of values to process.
fastLength (simple int) : Period for the fast moving average.
slowLength (simple int) : Period for the slow moving average.
maType (simple MaType) : Type of moving average to use for both calculations. Optional. Default is EMA.
Returns: (float) The calculated Dual Moving Average Oscillator value as a percentage.
continuationIndex(source, length, gamma, order)
Calculates the Continuation Index of a given data series. The index represents the Inverse Fisher Transform of the normalized difference between an UltimateSmoother and an N-order Laguerre filter. Developed by John F. Ehlers, published in TASC 2025.09.
Parameters:
source (series float) : Series of values to process.
length (simple int) : The calculation length.
gamma (simple float) : Controls the phase response of the Laguerre filter. Optional. Default is 0.8.
order (simple int) : The order of the Laguerre filter (1-10). Optional. Default is 8.
Returns: (float) The calculated Continuation Index value.
📚 RELEASE NOTES
v1.0 (2025.09.24)
✅ 25+ technical analysis functions
✅ Complete adaptive moving average series (KAMA, FRAMA, MAMA/FAMA)
✅ Advanced signal processing filters (Kalman, Laguerre, SuperSmoother, UltimateSmoother)
✅ Performance optimized with pre-calculated constants and efficient algorithms
✅ Unified function interface design following TradingView best practices
✅ Comprehensive moving average collection (DEMA, TEMA, ZLEMA, T3, etc.)
✅ Volatility and trend detection tools (QQE, SSL Channel, Range Filter)
✅ Continuation Index - Latest research from TASC 2025.09
✅ MACD and ATR calculations supporting multiple moving average types
✅ Dual Moving Average Oscillator (DMAO) for arbitrary data series analysis
Simple Turnover (Enhanced v2)📊 Simple Turnover (Enhanced)
🔹 Overview
The Simple Turnover Indicator calculates a stock’s turnover by combining both price and volume, and then compares it against quarterly highs. This helps traders quickly gauge whether market participation in a move is strong enough to confirm a breakout, or weak and likely to be false.
Unlike volume alone, turnover considers both traded volume and price level, giving a truer reflection of capital flow in/out of a stock.
________________________________________
🔹 Formulae Used
1. Average Price (SMA)
AvgPrice=SMA(Close,n)
2. Average Volume (SMA)
AvgVol=SMA(Volume,n)
3. Turnover (Raw)
Turnover raw=AvgPrice × AvgVol
4. Unit Adjustment
• If Millions → Turnover = Turnover raw × 10^−6
• If Crores → Turnover = Turnover raw × 10^−7
• If Raw → Turnover = Turnover raw
5. Quarterly High Turnover (qHigh)
Within each calendar quarter (Jan–Mar, Apr–Jun, Jul–Sep, Oct–Dec), we track the maximum turnover seen:
qHigh=max (Turnover within current quarter)
________________________________________
🔹 Visualization
• Bars → Color follows price candle:
o Green if Close ≥ Open
o Red if Close < Open
• Blue Line → Rolling Quarterly High Turnover (qHigh)
________________________________________
🔹 Strategy Use Case
The Simple Turnover Indicator is most effective for confirming true vs false breakouts.
• A true breakout should be supported by increasing turnover, showing real capital backing the move.
• A false breakout often occurs with weak or declining turnover, suggesting lack of conviction.
📌 Example Strategy (3H timeframe):
1. Identify a demand zone using your preferred supply-demand indicator.
2. From this demand zone, monitor turnover bars.
3. A potential long entry is validated when:
o The current turnover bar is at least 20% higher than the previous one or two bars.
o Example setting: SMA length = 5 (i.e., turnover = 5-bar average close × 5-bar average volume).
4. This confirms strong participation in the move, increasing probability of a sustained breakout.
________________________________________
🔹 Disclaimer
⚠️ This indicator/strategy does not guarantee 100% accurate results.
It is intended to improve the probability of identifying true breakouts.
The actual success of the strategy will depend on price action, market momentum, and prevailing market conditions.
Always use this as a supporting tool along with broader trading analysis and risk management.
Irrationality Index by CRYPTO_ADA_BTC"The market can be irrational longer than you can stay solvent" ~ John Maynard Keynes
This indicator, the Irrationality Index, measures how far the current market price has deviated from a smoothed estimate of its "fair value," normalized for recent volatility. It provides traders with a visual sense of when the market may be behaving irrationally, without giving direct buy or sell signals.
How it works:
1. Fair Value Calculation
The indicator estimates a "fair value" for the asset using a combination of a long-term EMA (exponential moving average) and a linear regression trend over a configurable period. This fair value serves as a smoothed baseline for price, balancing trend-following and mean-reversion.
2. Volatility-Adjusted Z-Score
The deviation between price and fair value is measured in standard deviations of recent log returns:
Z = (log(price) - log(fairValue)) / volatility
This standardization accounts for different volatility environments, allowing comparison across assets.
3. Irrationality Score (0–100)
The Z-score is transformed using a logistic mapping into a 0–100 scale:
- 50 → price near fair value (rational zone)
- >75 → high irrationality, price stretched above fair value
- >90 → extreme irrationality, unsustainable extremes
- <25 → high irrationality, price stretched below fair value
- <10 → extreme bearish irrationality
4. Price vs Fair Value (% deviation)
The indicator plots the percentage difference between price and fair value:
pctDiff = (price - fairValue) / fairValue * 100
- Positive values → Percentage above fair value (optimistic / overvalued)
- Negative values → Percentage below fair value (pessimistic / undervalued)
Visuals:
- Irrationality (%) Line (0–100) shows irrationality level.
- Background Colors: Yellow= high bullish irrationality, Green= extreme bullish irrationality, Orange= high bearish irrationality, Red= extreme bearish irrationality.
- Price - FairValue (%) plot: price deviation vs fair value (%), Colored green above 0 and red below 0.
- Label: display actual price, estimated fair value, and Z-score for the latest bar.
- Alerts: configurable thresholds for high and extreme irrationality.
How to read it:
- 50 → Market trading near fair value.
- >75 / >90 → Price may be irrationally high; risk of pullback increases.
- <25 / <10 → Price may be irrationally low; potential rebound zones, but trends can continue.
- Price - FairValue (%) plot → visual guide for % price stretch relative to fair value.
Notes / Warnings:
- Measures relative deviation, not fundamental value!
- High irrationality scores do not automatically indicate trades; markets can remain can be irrational longer than you can stay solvent .
- Best used with other tools: momentum, volume, divergence, and multi-timeframe analysis.
Supertrend DashboardOverview
This dashboard is a multi-timeframe technical indicator dashboard based on Supertrend. It combines:
Trend detection via Supertrend
Momentum via RSI and OBV (volume)
Volatility via a basic candle-based metric (bs)
Trend strength via ADX
Multi-timeframe analysis to see whether the trend is bullish across different timeframes
It then displays this info in a table on the chart with colors for quick visual interpretation.
2️⃣ Inputs
Dashboard settings:
enableDashboard: Toggle the dashboard on/off
locationDashboard: Where the table appears (Top right, Bottom left, etc.)
sizeDashboard: Text size in the table
strategyName: Custom name for the strategy
Indicator settings:
factor (Supertrend factor): Controls how far the Supertrend lines are from price
atrLength: ATR period for Supertrend calculation
rsiLength: Period for RSI calculation
Visual settings:
colorBackground, colorFrame, colorBorder: Control dashboard style
3️⃣ Core Calculations
a) Supertrend
Supertrend is a trend-following indicator that generates bullish or bearish signals.
Logic:
Compute ATR (atr = ta.atr(atrLength))
Compute preliminary bands:
upperBand = src + factor * atr
lowerBand = src - factor * atr
Smooth bands to avoid false flips:
lowerBand := lowerBand > prevLower or close < prevLower ? lowerBand : prevLower
upperBand := upperBand < prevUpper or close > prevUpper ? upperBand : prevUpper
Determine direction (bullish / bearish):
dir = 1 → bullish
dir = -1 → bearish
Supertrend line = lowerBand if bullish, upperBand if bearish
Output:
st → line to plot
bull → boolean (true = bullish)
b) Buy / Sell Trigger
Logic:
bull = ta.crossover(close, supertrend) → close crosses above Supertrend → buy signal
bear = ta.crossunder(close, supertrend) → close crosses below Supertrend → sell signal
trigger → checks which signal was most recent:
trigger = ta.barssince(bull) < ta.barssince(bear) ? 1 : 0
1 → Buy
0 → Sell
c) RSI (Momentum)
rsi = ta.rsi(close, rsiLength)
Logic:
RSI > 50 → bullish
RSI < 50 → bearish
d) OBV / Volume Trend (vosc)
OBV tracks whether volume is pushing price up or down.
Manual calculation (safe for all Pine versions):
obv = ta.cum( math.sign( nz(ta.change(close), 0) ) * volume )
vosc = obv - ta.ema(obv, 20)
Logic:
vosc > 0 → bullish
vosc < 0 → bearish
e) Volatility (bs)
Measures how “volatile” the current candle is:
bs = ta.ema(math.abs((open - close) / math.max(high - low, syminfo.mintick) * 100), 3)
Higher % → stronger candle moves
Displayed on dashboard as a number
f) ADX (Trend Strength)
= ta.dmi(14, 14)
Logic:
adx > 20 → Trending
adx < 20 → Ranging
g) Multi-Timeframe Supertrend
Timeframes: 1m, 3m, 5m, 10m, 15m, 30m, 1H, 2H, 4H, 12H, 1D
Logic:
for tf in timeframes
= request.security(syminfo.tickerid, tf, f_supertrend(ohlc4, factor, atrLength))
array.push(tf_bulls, bull_tf ? 1.0 : 0.0)
bull_tf ? 1.0 : 0.0 → converts boolean to number
Then we calculate user rating:
userRating = (sum of bullish timeframes / total timeframes) * 10
0 → Strong Sell, 10 → Strong Buy
4️⃣ Dashboard Table Layout
Row Column 0 (Label) Column 1 (Value)
0 Strategy strategyName
1 Technical Rating textFromRating(userRating) (color-coded)
2 Current Signal Buy / Sell (based on last Supertrend crossover)
3 Current Trend Bullish / Bearish (based on Supertrend)
4 Trend Strength bs %
5 Volume vosc → Bullish/Bearish
6 Volatility adx → Trending/Ranging
7 Momentum RSI → Bullish/Bearish
8 Timeframe Trends 📶 Merged cell
9-19 1m → Daily Bullish/Bearish for each timeframe (green/red)
5️⃣ Color Logic
Green shades → bullish / trending / buy
Red / orange → bearish / weak / sell
Yellow → neutral / ranging
Example:
dashboard_cell_bg(1, 1, colorFromRating(userRating))
dashboard_cell_bg(1, 2, trigger ? color.green : color.red)
dashboard_cell_bg(1, 3, superBull ? color.green : color.red)
Makes the dashboard visually intuitive
6️⃣ Key Logic Flow
Calculate Supertrend on current timeframe
Detect buy/sell triggers based on crossover
Calculate RSI, OBV, Volatility, ADX
Request Supertrend on multiple timeframes → convert to 1/0
Compute user rating (percentage of bullish timeframes)
Populate dashboard table with colors and values
✅ The result: You get a compact, fast, multi-timeframe trend dashboard that shows:
Current signal (Buy/Sell)
Current trend (Bullish/Bearish)
Momentum, volatility, and volume cues
Trend across multiple timeframes
Overall technical rating
It’s essentially a full trend-strength scanner directly on your chart.
Mongoose Global Conflict Risk Index v1Overview
The Mongoose Global Conflict Risk Index v1 is a multi-asset composite indicator designed to track the early pricing of geopolitical stress and potential conflict risk across global markets. By combining signals from safe havens, volatility indices, energy markets, and emerging market equities, the index provides a normalized 0–10 score with clear bias classifications (Neutral, Caution, Elevated, High, Shock).
This tool is not predictive of headlines but captures when markets are clustering around conflict-sensitive assets before events are widely recognized.
Methodology
The indicator calculates rolling rate-of-change z-scores for eight conflict-sensitive assets:
Gold (XAUUSD) – classic safe haven
US Dollar Index (DXY) – global reserve currency flows
VIX (Equity Volatility) – S&P 500 implied volatility
OVX (Crude Oil Volatility Index) – energy stress gauge
Crude Oil (CL1!) – WTI front contract
Natural Gas (NG1!) – energy security proxy, especially Europe
EEM (Emerging Markets ETF) – global risk capital flight
FXI (China ETF) – Asia/China proxy risk
Rules:
Safe havens and vol indices trigger when z-score > threshold.
Energy triggers when z-score > threshold.
Risk assets trigger when z-score < –threshold.
Each trigger is assigned a weight, summed, normalized, and scaled 0–10.
Bias classification:
0–2: Neutral
2–4: Caution
4–6: Elevated
6–8: High
8–10: Conflict Risk-On
How to Use
Timeframes:
Daily (1D) for strategic signals and early warnings.
4H for event shocks (missiles, sanctions, sudden escalations).
Weekly (1W) for sustained trends and macro build-ups.
What to Look For:
A single trigger (for example, Gold ON) may be noise.
A cluster of 2–3 triggers across Gold, USD, VIX, and Energy often marks early stress pricing.
Elevated readings (>4) = caution; High (>6) = rotation into havens; Shock (>8) = market conviction of conflict risk.
Practical Application:
Monitor as a heatmap of global stress.
Combine with fundamental or headline tracking.
Use alert conditions at ≥4, ≥6, ≥8 for systematic monitoring.
Notes
This indicator is for informational and educational purposes only.
It is not financial advice and should be used in conjunction with other analysis methods.