PROTECTED SOURCE SCRIPT
Aggiornato Swing Trade Indicator

This is a Swing Trade Indicator that combines several technical indicators to analyze market conditions and generate trade signals. I've included two tables that provide real-time information to help you analyze the market and track trades: the Market Status Table and the Trade Tracking Table. These tables are overlaid on the TradingView chart and are customizable in terms of position and visibility.
Simple Moving Averages (SMAs):
Determines trend direction (e.g., bullish if fastMA > slowMA).
Calculates the average closing price over a set period:
fastMA: 21-period SMA (short-term trend).
slowMA: 50-period SMA (medium-term trend).
ultraSlowMA: 200-period SMA (long-term trend).
How:
ta.sma(close, fastLength) computes the SMA of the closing price over fastLength bars (similarly for slowLength and ultraSlowLength).
Volume Analysis:
Identifies potential liquidity spikes.
Measures trading volume to detect high activity.
Average volume over liquidityPeriod (20 bars).
Standard deviation of volume to set a dynamic threshold.
How:
avgVolume = ta.sma(volume, liquidityPeriod): Average volume.
volumeStdDev = ta.stdev(volume, liquidityPeriod): Volatility of volume.
highVolume = volume > avgVolume + volumeStdDev * volumeThresholdMultiplier: Flags high volume if it exceeds the average plus a multiplier (default 1.0) times the standard deviation.
Relative Strength Index (RSI):
Filters entries to avoid overextended markets.
Measures momentum and overbought/oversold conditions.
14-period RSI with thresholds at 60 (overbought) and 40 (oversold).
How:
rsiValue = ta.rsi(close, rsiLength) calculates RSI based on price changes over 14 bars.
Average Directional Index (ADX):
Gauges whether the trend is strong enough to trade.
Assesses trend strength.
14-period ADX.
How:
Calculates True Range (tr), Plus Directional Movement (plusDM), and Minus Directional Movement (minusDM).
Smooths these with ta.rma (Running Moving Average) over adxLength (14).
Computes plusDI and minusDI (directional indicators), then dx (difference), and finally adxValue = ta.rma(dx, adxLength) for trend strength.
Classifies as "Strong" (≥40), "Moderate" (≥20), or "Weak" (<20).
Moving Average Convergence Divergence (MACD) (Optional):
Optional filter for entry conditions if useMacdFilter is enabled.
Tracks momentum and trend changes.
Fast EMA (12), Slow EMA (26), Signal Line (9).
How:
[macdLine, signalLine, hist] = ta.macd(close, macdFastLength, macdSlowLength, macdSignalLength) computes the MACD components.
macdBullish = macdLine > signalLine: Bullish signal.
macdBearish = macdLine < signalLine: Bearish signal.
Liquidity Zones:
Confirms entries near key levels and suggests next trade setups.
Identifies support and resistance levels based on recent price extremes.
Dynamic levels over 20 bars (if useDynamicLevels is true).
How:
highLiquidityLevel1 = ta.highest(high, 20): Highest high in last 20 bars.
highLiquidityLevel2 = ta.highest(high[20], 20): Highest high from 20 to 40 bars ago.
highLiquidityLevel3 = ta.lowest(low, 20): Lowest low in last 20 bars.
highLiquidityLevel4 = ta.lowest(low[20], 20): Lowest low from 20 to 40 bars ago.
Upper and lower zones are derived (upperLevel, lowerLevel), with a midpoint between them.
How It Calculates Entries and Exits
Long Entry:
Basic Conditions (longEntry):
close > fastMA: Price is above the 21-period SMA.
fastMA > slowMA: Short-term trend is above medium-term trend (bullish).
rsiValue < rsiOverbought: RSI below 60 (not overbought).
(not useMacdFilter or macdBullish): If MACD filter is off, ignore it; if on, MACD must be bullish.
Confirmed Entry (confirmedLongEntry):
longEntry is true.
close >= highLiquidityLevel3 * 0.95 and close <= highLiquidityLevel3 * 1.05: Price is within 5% of the lower liquidity level (support).
Action: Sets currentPosition = 'long', records entry price and bar, plots a green triangle below the bar.
Short Entry:
Basic Conditions (shortEntry):
close < fastMA: Price is below the 21-period SMA.
fastMA < slowMA: Short-term trend is below medium-term trend (bearish).
rsiValue > rsiOversold: RSI above 40 (not oversold).
(not useMacdFilter or macdBearish): If MACD filter is off, ignore it; if on, MACD must be bearish.
Confirmed Entry (confirmedShortEntry):
shortEntry is true.
close <= highLiquidityLevel1 * 1.05 and close >= highLiquidityLevel1 * 0.95: Price is within 5% of the upper liquidity level (resistance).
Action: Sets currentPosition = 'short', records entry price and bar, plots a red triangle above the bar.
Exit Conditions
Note: The exit logic is defined but commented out in the script (//longExit and //shortExit), meaning it doesn’t automatically exit positions. It calculates stop-loss and take-profit levels for manual use:
Long Exit (if uncommented):
close < stopLossLevelLong: Price falls below stop-loss (entry price × (1 - 1.5%)).
close > takeProfitLevelLong: Price exceeds take-profit (entry price × (1 + 1.5% × 2.0)).
Short Exit (if uncommented):
close > stopLossLevelShort: Price rises above stop-loss (entry price × (1 + 1.5%)).
close < takeProfitLevelShort: Price falls below take-profit (entry price × (1 - 1.5% × 2.0)).
Suggested Levels: The script provides suggestedLongSL, suggestedLongTP, suggestedShortSL, and suggestedShortTP in the Market Status Table, based on liquidity levels rather than entry price, for manual exits.
Users Can Edit Settings:
Market Status Table Position: Dropdown (e.g., "top_right" to "bottom_left").
Trade Tracking Table Position: Dropdown (e.g., "bottom_right" to "middle_center").
Visibility Toggles (checkboxes):
Show Tables: Enable/disable tables (default: true).
Show Liquidity Zones: Not plotted but affects logic (default: true).
Show Entry Points: Show/hide entry triangles (default: true).
Use Dynamic Levels: Enable/disable liquidity zones (default: true).
Use MACD for Entry Filter: Add MACD to entry conditions (default: false).
Show MACD on Chart: Not implemented but reserved (default: false).
Indicator Periods:
Fast MA Length: Integer (default: 21, e.g., change to 10).
Slow MA Length: Integer (default: 50, e.g., change to 30).
Ultra Slow MA Length: Integer (default: 200, e.g., change to 100).
Liquidity Detection Period: Integer (default: 20, e.g., change to 10).
RSI Length: Integer (default: 14, e.g., change to 7).
ADX Length: Integer (default: 14, e.g., change to 20).
MACD Fast/Slow/Signal Length: Integers (default: 12/26/9, e.g., 9/21/5).
Thresholds:
Volume Threshold Multiplier: Float (default: 1.0, e.g., 1.5 for stricter high volume).
RSI Overbought: Integer (default: 60, e.g., 70).
RSI Oversold: Integer (default: 40, e.g., 30).
Stop Loss %: Float (default: 1.5, e.g., 2.0, range 0.1-10).
Take Profit Ratio: Float (default: 2.0, e.g., 3.0, range 1.0-5.0).
Liquidity Threshold (%): Float (default: 2.0, e.g., 1.5, range 0.5-5.0).
Simple Moving Averages (SMAs):
Determines trend direction (e.g., bullish if fastMA > slowMA).
Calculates the average closing price over a set period:
fastMA: 21-period SMA (short-term trend).
slowMA: 50-period SMA (medium-term trend).
ultraSlowMA: 200-period SMA (long-term trend).
How:
ta.sma(close, fastLength) computes the SMA of the closing price over fastLength bars (similarly for slowLength and ultraSlowLength).
Volume Analysis:
Identifies potential liquidity spikes.
Measures trading volume to detect high activity.
Average volume over liquidityPeriod (20 bars).
Standard deviation of volume to set a dynamic threshold.
How:
avgVolume = ta.sma(volume, liquidityPeriod): Average volume.
volumeStdDev = ta.stdev(volume, liquidityPeriod): Volatility of volume.
highVolume = volume > avgVolume + volumeStdDev * volumeThresholdMultiplier: Flags high volume if it exceeds the average plus a multiplier (default 1.0) times the standard deviation.
Relative Strength Index (RSI):
Filters entries to avoid overextended markets.
Measures momentum and overbought/oversold conditions.
14-period RSI with thresholds at 60 (overbought) and 40 (oversold).
How:
rsiValue = ta.rsi(close, rsiLength) calculates RSI based on price changes over 14 bars.
Average Directional Index (ADX):
Gauges whether the trend is strong enough to trade.
Assesses trend strength.
14-period ADX.
How:
Calculates True Range (tr), Plus Directional Movement (plusDM), and Minus Directional Movement (minusDM).
Smooths these with ta.rma (Running Moving Average) over adxLength (14).
Computes plusDI and minusDI (directional indicators), then dx (difference), and finally adxValue = ta.rma(dx, adxLength) for trend strength.
Classifies as "Strong" (≥40), "Moderate" (≥20), or "Weak" (<20).
Moving Average Convergence Divergence (MACD) (Optional):
Optional filter for entry conditions if useMacdFilter is enabled.
Tracks momentum and trend changes.
Fast EMA (12), Slow EMA (26), Signal Line (9).
How:
[macdLine, signalLine, hist] = ta.macd(close, macdFastLength, macdSlowLength, macdSignalLength) computes the MACD components.
macdBullish = macdLine > signalLine: Bullish signal.
macdBearish = macdLine < signalLine: Bearish signal.
Liquidity Zones:
Confirms entries near key levels and suggests next trade setups.
Identifies support and resistance levels based on recent price extremes.
Dynamic levels over 20 bars (if useDynamicLevels is true).
How:
highLiquidityLevel1 = ta.highest(high, 20): Highest high in last 20 bars.
highLiquidityLevel2 = ta.highest(high[20], 20): Highest high from 20 to 40 bars ago.
highLiquidityLevel3 = ta.lowest(low, 20): Lowest low in last 20 bars.
highLiquidityLevel4 = ta.lowest(low[20], 20): Lowest low from 20 to 40 bars ago.
Upper and lower zones are derived (upperLevel, lowerLevel), with a midpoint between them.
How It Calculates Entries and Exits
Long Entry:
Basic Conditions (longEntry):
close > fastMA: Price is above the 21-period SMA.
fastMA > slowMA: Short-term trend is above medium-term trend (bullish).
rsiValue < rsiOverbought: RSI below 60 (not overbought).
(not useMacdFilter or macdBullish): If MACD filter is off, ignore it; if on, MACD must be bullish.
Confirmed Entry (confirmedLongEntry):
longEntry is true.
close >= highLiquidityLevel3 * 0.95 and close <= highLiquidityLevel3 * 1.05: Price is within 5% of the lower liquidity level (support).
Action: Sets currentPosition = 'long', records entry price and bar, plots a green triangle below the bar.
Short Entry:
Basic Conditions (shortEntry):
close < fastMA: Price is below the 21-period SMA.
fastMA < slowMA: Short-term trend is below medium-term trend (bearish).
rsiValue > rsiOversold: RSI above 40 (not oversold).
(not useMacdFilter or macdBearish): If MACD filter is off, ignore it; if on, MACD must be bearish.
Confirmed Entry (confirmedShortEntry):
shortEntry is true.
close <= highLiquidityLevel1 * 1.05 and close >= highLiquidityLevel1 * 0.95: Price is within 5% of the upper liquidity level (resistance).
Action: Sets currentPosition = 'short', records entry price and bar, plots a red triangle above the bar.
Exit Conditions
Note: The exit logic is defined but commented out in the script (//longExit and //shortExit), meaning it doesn’t automatically exit positions. It calculates stop-loss and take-profit levels for manual use:
Long Exit (if uncommented):
close < stopLossLevelLong: Price falls below stop-loss (entry price × (1 - 1.5%)).
close > takeProfitLevelLong: Price exceeds take-profit (entry price × (1 + 1.5% × 2.0)).
Short Exit (if uncommented):
close > stopLossLevelShort: Price rises above stop-loss (entry price × (1 + 1.5%)).
close < takeProfitLevelShort: Price falls below take-profit (entry price × (1 - 1.5% × 2.0)).
Suggested Levels: The script provides suggestedLongSL, suggestedLongTP, suggestedShortSL, and suggestedShortTP in the Market Status Table, based on liquidity levels rather than entry price, for manual exits.
Users Can Edit Settings:
Market Status Table Position: Dropdown (e.g., "top_right" to "bottom_left").
Trade Tracking Table Position: Dropdown (e.g., "bottom_right" to "middle_center").
Visibility Toggles (checkboxes):
Show Tables: Enable/disable tables (default: true).
Show Liquidity Zones: Not plotted but affects logic (default: true).
Show Entry Points: Show/hide entry triangles (default: true).
Use Dynamic Levels: Enable/disable liquidity zones (default: true).
Use MACD for Entry Filter: Add MACD to entry conditions (default: false).
Show MACD on Chart: Not implemented but reserved (default: false).
Indicator Periods:
Fast MA Length: Integer (default: 21, e.g., change to 10).
Slow MA Length: Integer (default: 50, e.g., change to 30).
Ultra Slow MA Length: Integer (default: 200, e.g., change to 100).
Liquidity Detection Period: Integer (default: 20, e.g., change to 10).
RSI Length: Integer (default: 14, e.g., change to 7).
ADX Length: Integer (default: 14, e.g., change to 20).
MACD Fast/Slow/Signal Length: Integers (default: 12/26/9, e.g., 9/21/5).
Thresholds:
Volume Threshold Multiplier: Float (default: 1.0, e.g., 1.5 for stricter high volume).
RSI Overbought: Integer (default: 60, e.g., 70).
RSI Oversold: Integer (default: 40, e.g., 30).
Stop Loss %: Float (default: 1.5, e.g., 2.0, range 0.1-10).
Take Profit Ratio: Float (default: 2.0, e.g., 3.0, range 1.0-5.0).
Liquidity Threshold (%): Float (default: 2.0, e.g., 1.5, range 0.5-5.0).
Note di rilascio
This is a Swing Trade Indicator that combines several technical indicators to analyze market conditions and generate trade signals. I've included two tables that provide real-time information to help you analyze the market and track trades: the Market Status Table and the Trade Tracking Table. These tables are overlaid on the TradingView chart and are customizable in terms of position and visibility.Simple Moving Averages (SMAs):
Determines trend direction (e.g., bullish if fastMA > slowMA).
Calculates the average closing price over a set period:
fastMA: 21-period SMA (short-term trend).
slowMA: 100-period SMA (medium-term trend).
ultraSlowMA: 200-period SMA (long-term trend).
How:
ta.sma(close, fastLength) computes the SMA of the closing price over fastLength bars (similarly for slowLength and ultraSlowLength).
Volume Analysis:
Identifies potential liquidity spikes.
Measures trading volume to detect high activity.
Average volume over liquidityPeriod (20 bars).
Standard deviation of volume to set a dynamic threshold.
How:
avgVolume = ta.sma(volume, liquidityPeriod): Average volume.
volumeStdDev = ta.stdev(volume, liquidityPeriod): Volatility of volume.
highVolume = volume > avgVolume + volumeStdDev * volumeThresholdMultiplier: Flags high volume if it exceeds the average plus a multiplier (default 1.0) times the standard deviation.
Relative Strength Index (RSI):
Filters entries to avoid overextended markets.
Measures momentum and overbought/oversold conditions.
14-period RSI with thresholds at 60 (overbought) and 40 (oversold).
How:
rsiValue = ta.rsi(close, rsiLength) calculates RSI based on price changes over 14 bars.
Average Directional Index (ADX):
Gauges whether the trend is strong enough to trade.
Assesses trend strength.
14-period ADX.
How:
Calculates True Range (tr), Plus Directional Movement (plusDM), and Minus Directional Movement (minusDM).
Smooths these with ta.rma (Running Moving Average) over adxLength (14).
Computes plusDI and minusDI (directional indicators), then dx (difference), and finally adxValue = ta.rma(dx, adxLength) for trend strength.
Classifies as "Strong" (≥40), "Moderate" (≥20), or "Weak" (<20).
Moving Average Convergence Divergence (MACD) (Optional):
Optional filter for entry conditions if useMacdFilter is enabled.
Tracks momentum and trend changes.
Fast EMA (12), Slow EMA (26), Signal Line (9).
How:
[macdLine, signalLine, hist] = ta.macd(close, macdFastLength, macdSlowLength, macdSignalLength) computes the MACD components.
macdBullish = macdLine > signalLine: Bullish signal.
macdBearish = macdLine < signalLine: Bearish signal.
Liquidity Zones:
Confirms entries near key levels and suggests next trade setups.
Identifies support and resistance levels based on recent price extremes.
Dynamic levels over 20 bars (if useDynamicLevels is true).
How:
highLiquidityLevel1 = ta.highest(high, 20): Highest high in last 20 bars.
highLiquidityLevel2 = ta.highest(high[20], 20): Highest high from 20 to 40 bars ago.
highLiquidityLevel3 = ta.lowest(low, 20): Lowest low in last 20 bars.
highLiquidityLevel4 = ta.lowest(low[20], 20): Lowest low from 20 to 40 bars ago.
Upper and lower zones are derived (upperLevel, lowerLevel), with a midpoint between them.
How It Calculates Entries and Exits
Long Entry:
Basic Conditions (longEntry):
close > fastMA: Price is above the 21-period SMA.
fastMA > slowMA: Short-term trend is above medium-term trend (bullish).
rsiValue < rsiOverbought: RSI below 60 (not overbought).
(not useMacdFilter or macdBullish): If MACD filter is off, ignore it; if on, MACD must be bullish.
Confirmed Entry (confirmedLongEntry):
longEntry is true.
close >= highLiquidityLevel3 * 0.95 and close <= highLiquidityLevel3 * 1.05: Price is within 5% of the lower liquidity level (support).
Action: Sets currentPosition = 'long', records entry price and bar, plots a green triangle below the bar.
Short Entry:
Basic Conditions (shortEntry):
close < fastMA: Price is below the 21-period SMA.
fastMA < slowMA: Short-term trend is below medium-term trend (bearish).
rsiValue > rsiOversold: RSI above 40 (not oversold).
(not useMacdFilter or macdBearish): If MACD filter is off, ignore it; if on, MACD must be bearish.
Confirmed Entry (confirmedShortEntry):
shortEntry is true.
close <= highLiquidityLevel1 * 1.05 and close >= highLiquidityLevel1 * 0.95: Price is within 5% of the upper liquidity level (resistance).
Action: Sets currentPosition = 'short', records entry price and bar, plots a red triangle above the bar.
Exit Conditions
Note: The exit logic is defined but commented out in the script (//longExit and //shortExit), meaning it doesn’t automatically exit positions. It calculates stop-loss and take-profit levels for manual use:
Long Exit (if uncommented):
close < stopLossLevelLong: Price falls below stop-loss (entry price × (1 - 1.5%)).
close > takeProfitLevelLong: Price exceeds take-profit (entry price × (1 + 1.5% × 2.0)).
Short Exit (if uncommented):
close > stopLossLevelShort: Price rises above stop-loss (entry price × (1 + 1.5%)).
close < takeProfitLevelShort: Price falls below take-profit (entry price × (1 - 1.5% × 2.0)).
Suggested Levels: The script provides suggestedLongSL, suggestedLongTP, suggestedShortSL, and suggestedShortTP in the Market Status Table, based on liquidity levels rather than entry price, for manual exits.
Users Can Edit Settings:
Market Status Table Position: Dropdown (e.g., "top_right" to "bottom_left").
Trade Tracking Table Position: Dropdown (e.g., "bottom_right" to "middle_center").
Visibility Toggles (checkboxes):
Show Tables: Enable/disable tables (default: true).
Show Liquidity Zones: Not plotted but affects logic (default: true).
Show Entry Points: Show/hide entry triangles (default: true).
Use Dynamic Levels: Enable/disable liquidity zones (default: true).
Use MACD for Entry Filter: Add MACD to entry conditions (default: false).
Show MACD on Chart: Not implemented but reserved (default: false).
Indicator Periods:
Fast MA Length: Integer (default: 21, e.g., change to 10).
Slow MA Length: Integer (default: 100, e.g., change to 30).
Ultra Slow MA Length: Integer (default: 200, e.g., change to 100).
Liquidity Detection Period: Integer (default: 20, e.g., change to 10).
RSI Length: Integer (default: 14, e.g., change to 7).
ADX Length: Integer (default: 14, e.g., change to 20).
MACD Fast/Slow/Signal Length: Integers (default: 12/26/9, e.g., 9/21/5).
Thresholds:
Volume Threshold Multiplier: Float (default: 1.0, e.g., 1.5 for stricter high volume).
RSI Overbought: Integer (default: 60, e.g., 70).
RSI Oversold: Integer (default: 40, e.g., 30).
Stop Loss %: Float (default: 1.5, e.g., 2.0, range 0.1-10).
Take Profit Ratio: Float (default: 2.0, e.g., 3.0, range 1.0-5.0).
Liquidity Threshold (%): Float (default: 2.0, e.g., 1.5, range 0.5-5.0).
-added Trade Gain/Loss tracker
Script protetto
Questo script è pubblicato come codice protetto. Tuttavia, è possibile utilizzarlo liberamente e senza alcuna limitazione – per saperne di più clicca qui.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.
Script protetto
Questo script è pubblicato come codice protetto. Tuttavia, è possibile utilizzarlo liberamente e senza alcuna limitazione – per saperne di più clicca qui.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.