Trend and Trendline DetectorTrend and Trendline Detector
Overview
The Trend and Trendline Detector indicator provides both major and minor trend analysis using Simple Moving Averages (SMA) and automatically plots dynamic support and resistance trendlines based on pivot highs and lows.
Key Features
Major Trend Detection: Uses a configurable SMA to determine primary market direction.
Minor Trend Visualization: Optional minor SMA with color-coded line segments to mark smaller trend fluctuations.
Dynamic Pivot Trendlines: Automatically detects pivot highs/lows and draws major (solid) and minor (dashed) trendlines, with user-controlled extension modes.
Customizable Inputs: User can adjust SMA lengths, pivot look back/look forward periods, line extend mode, and toggle features on/off.
Cari dalam skrip untuk "trend"
Trend Detection with AlertsPurpose of the Script
The script identifies trends on a chart (uptrend, downtrend, or sideways trend) and provides both visual cues and alerts when a trend changes. It uses two methods for trend detection:
Moving Averages (MA): It compares a short-term moving average (fast) with a long-term moving average (slow).
An uptrend occurs when the short-term MA is above the long-term MA.
A downtrend occurs when the short-term MA is below the long-term MA.
Price Action:
Higher highs (HH) indicate bullish momentum.
Lower lows (LL) indicate bearish momentum.
When these methods align, the script determines the trend and notifies the user of any trend changes.
Key Features
Moving Average Calculation:
A short-term moving average and a long-term moving average are calculated to determine the overall trend direction.
Trend Determination:
An uptrend is detected when the short-term MA is above the long-term MA and higher highs are present.
A downtrend is detected when the short-term MA is below the long-term MA and lower lows are present.
Otherwise, the trend is classified as sideways.
Alerts for Trend Changes:
Alerts are triggered when the trend changes from one state to another (e.g., sideways to uptrend).
Custom messages indicate the type of trend detected.
Background Colors:
The script changes the chart’s background color based on the current trend:
Green for uptrends.
Red for downtrends.
Gray for sideways trends.
Visualization of Moving Averages:
The moving averages are plotted on the chart for visual reference.
How It Works
Inputs for Flexibility:
The user can configure the lengths of the short-term and long-term moving averages.
A lookback period is used to determine higher highs or lower lows for additional confirmation.
Trend Logic:
The script checks the relationship between the moving averages to identify general trends.
It also evaluates price action to confirm trend strength (e.g., whether a higher high or lower low occurred).
Alert System:
When the detected trend changes (e.g., from sideways to uptrend), an alert is triggered. This ensures the user is notified of important market movements.
Dynamic Background Coloring:
The background color of the chart changes to reflect the current trend, making it easy to interpret the trend visually.
Use Cases
Trend Identification: Helps traders quickly identify market trends for decision-making.
Alerts for Trend Changes: Notifies traders when a new trend begins, ensuring they don’t miss key opportunities.
Visual Assistance: Makes it easier to interpret trends through color-coded backgrounds and moving average overlays.
Customization Options
Adjust Moving Average Lengths: Users can modify the short-term and long-term moving averages to suit their trading strategies.
Change Lookback Period: The sensitivity of higher highs and lower lows can be adjusted.
Personalized Alerts: Alerts can be customized for different trading scenarios.
Summary
This script provides an intuitive way to detect and visualize market trends while offering real-time alerts for trend changes. It’s an excellent tool for traders who want to stay informed about market conditions and make data-driven decisions.
Trend Lines [AstroHub]1. Understand the basics of technical analysis: to fully utilize this system, you need to understand the fundamentals of technical analysis, such as identifying high and low prices, trendlines, etc. This will help you effectively use indicators and make more informed trading decisions.
2. Study the internal parameters: the system has input parameters, such as "Period," etc. Study their values and understand how they impact the indicator's performance. This will allow you to customize the system to fit your needs and trading strategies.
3. Pay attention to bars of different colors: the system marks bars with different colors depending on the price's position relative to trendlines. Pay close attention to these color changes as they can serve as entry or exit signals.
4. Be ready to adapt: the market is constantly changing, and the system may not always provide accurate signals. Be prepared to adapt and make decisions based on other factors, such as trading volume, news, etc.
5. Practice on historical data: before using this system in real-time, conduct some tests on historical data. This will help you understand how the system works and what results it can produce in different market conditions.
6. Be patient: the system may not always provide instant entry or exit signals. Be patient and wait for signal confirmation before entering or closing a trade.
7. Learn and discuss: trading knowledge and the use of this system are continuous learning processes. Be open to learning new strategies and discussing your experiences with other traders. This will help you improve your skills and better utilize this system.
Supertrend - Ladder ATRThis is a supertrend with slight twisted concept which can be very benefecial in strong trending markets to reduce stop loss distance and exit slightly quicker.
⬜ Concept
▶ When the instrument is trending up, regular ATR shows high values if there are big green candles. This affect the stoploss distance in regular supertrend which leads to wide stops or delayed lagging. When you are in long trade, what matters for stoploss is how much a negative candle can move within bar. Hence, using ATR derived only based on red candles is more beneficial for trailing stops on long signals. Same applies to short trades where using ATR derived from only green candles is more efficient than overall ATR.
▶ ATR will be minimal when the volatility is less and ATR will increase with volatility. That means, once you are in trade, the trailing of stoploss also will vary based on ATR (or volatility). With regular ATR and supertrend, chances of stop loss distance widening is high with increased volatility even though stoploss levels will not move down. This again poses the risk of higher drawdown during trade closure and also keeps in the trade during ranging market. To avoid this, the second trick we are using here is only to reduce the atr stoploss difference when in trade. That is, when in long trade and negative candles ATR is increasing, we will not consider that. We will consider the new ATR only if it is lesser than previous bar ATR.
Effect of these changes on the trending market is quite visual. Lets take example of USDTRY
Settings are quite simple and does not vary much from regular supertrend settings.
Cumulative Pivot HighLowThis indicator counts number of higher highs/lows and number of lower highs/lows and calculates trend based on that.
Indicator line shows (sum of higher highs/lows - sum of lower highs/lows) derived from last loopback periods. Indicator is green if last two consecutive highs/lows formed are on higher side. Red if on lower side. (Consecutive numbers can be controlled by parameter direction_threshold )
combineHighsAndLows if unselected shows not cumulative version but last consecutive highs and lows marked in red or green according to the trend.
Trendlines - JD This script draws trendlines from the pivot points in the price chart.
The input for the function that draws the trendlines is any calculation or function (eg. pivot points),
that most of the time and occasionally produces a 'non n/a' value.
The trendline function then connects the non n/a values and axtends the connections of those points in a trendline.
There is an option to draw the lines from the wicks or from the 'real bodies' of the candles.
The trendlines can either extend infinitely or only run for an adjustable amount of bars.
JD.
Trend Structure Shift By BCB ElevateTrend Structure Shift by BCB Elevate
This indicator helps traders identify trend structure shifts by detecting Higher Highs (HH) and Lower Lows (LL) to determine bullish, bearish, or neutral market conditions. It provides real-time trend classification to help traders align with market direction.
How It Works:
📌 Bullish Trend: A new Higher High (HH) is detected, signaling potential uptrend continuation.
📌 Bearish Trend: A new Lower Low (LL) is detected, indicating potential downtrend continuation.
📌 Neutral: No significant trend shift is detected.
Key Features:
✅ Dynamic Trend Detection – Identifies key trend structure shifts using swing highs and lows.
✅ Customizable Settings – Adjust the swing length to fine-tune trend detection.
✅ Trend Table Display – Shows current trend as Bullish, Bearish, or Neutral in a convenient on-chart table.
✅ Table Position Selection – Choose where the trend table appears on the chart (Top/Bottom Left or Right).
✅ Works on All Markets & Timeframes – Use it for Crypto, Forex, Stocks, Commodities, and Indices.
How to Use:
1️⃣ Apply the indicator to your chart.
2️⃣ Observe the Trend Table to determine the market condition.
3️⃣ Use it with support/resistance, moving averages, or other indicators for better trade decisions.
Trend Signals with TP & SL [UAlgo]The "Trend Signals with TP & SL " indicator is a versatile tool designed to assist traders in identifying potential trend continuation opportunities within financial markets Utilizing a combination of technical indicators and user-defined parameters, this indicator aims to provide clear and actionable signals to aid traders in making informed trading decisions.
🔶 Features:
Trend Continuation Signals : The indicator generates signals to identify potential trend continuation points based on the input parameters such as sensitivity, ATR length, and cloud moving average length.
Take-Profit and Stop-Loss Levels: It calculates and plots three levels of take-profit (1R, 2R, 3R) and stop-loss levels based on the entry price of the trade.
Short Position Example:
Long Position Example:
Visualization: The script visualizes the trend signals, entry points, take-profit levels, and stop-loss levels on the price chart, making it easier for traders to interpret the signals.
Alert System: The indicator includes an alert system that notifies the user when there is a change in trend direction or when a buy/sell signal is generated. The alerts provide essential information such as entry price, take-profit levels, and stop-loss levels.
🔶 Calculations :
Trend Calculation: Trend signals are determined based on the comparison between the current closing price and the upper and lower bounds calculated using the Average True Range (ATR) multiplied by a sensitivity factor. A trend is considered bullish if the closing price is above the upper bound and bearish if it's below the lower bound.
Entry, Stop Loss, and Take Profit Calculation: Entry points for long and short positions are identified when there's a change in trend direction.
Stop-loss levels are calculated as a percentage of the entry price, where users can define the percentage based on their risk tolerance.
Take-profit levels are calculated as multiples of the stop-loss level (1R, 2R, 3R).
Cloud Moving Averages: Simple moving averages (SMAs) are calculated for high and low prices over a specified period to create a "cloud" visualization on the chart.
MACD Clouds: Moving Average Convergence Divergence (MACD) indicator is used to determine the market's momentum and trend direction. Positive and negative clouds are plotted based on the MACD line and its signal line, indicating potential bullish or bearish trends.
Signal Generation: Buy and sell signals are generated based on specific conditions such as RSI, CMO (Chande Momentum Oscillator), and pivot points.
Signals are triggered when certain criteria are met, indicating potential opportunities for entering or exiting trades.
🔶 Disclaimer:
Use at Your Own Risk: Trading involves significant risk, and this script is provided for educational and informational purposes only. It does not guarantee profitable trades, and users should exercise caution and perform their own analysis before making trading decisions.
Parameter Sensitivity: The effectiveness of the indicator may vary depending on the chosen parameters, market conditions, and timeframe. Users are encouraged to backtest the script thoroughly and adjust the parameters according to their trading preferences.
Not Financial Advice: The information provided by this script should not be considered as financial advice. Users are solely responsible for their trading decisions and should consult with a qualified financial advisor if needed.
Backtesting and Validation: Before implementing this indicator in live trading, users are strongly encouraged to conduct rigorous backtesting and validation to assess its performance under various market conditions. Past performance is not indicative of future results, and users should carefully evaluate the effectiveness of the indicator based on their individual trading preferences and risk tolerance.
Trend Bar Dow Theory V-1.0The indicator is designed to signal the presence of a trend bar with reduced profit-taking the following day. Below, I explain the logic that I have defined for this first version.
The guidelines I provided are as follows: We identify a trend bar, if it sets a market change, between opening and closing, equal to or greater than 50 pips . This first guideline is used to find a day with good liquidity , which usually leads to a trend bar.
If the first guideline is met, the indicator should change the bar color to white . This way, we can proceed to the second guideline, to detect the presence of reduced profit-taking.
The second guideline should indicate the presence of reduced profit-taking, as explained by Dow Theory, to find a trend context with potential to exploit. Therefore, the second guideline involves coloring the bars near the trend bars in grey, if they have a range equal to or less than 30 pips.
Dow Theory states that a market in trend measures reduced profit-taking, within 33%, up to a maximum of 50% compared to the previous trend bar, but I have not yet been able to make Pine Script calculate the percentage value. If you have any suggestions, I would be grateful.
Trend Volume Indicator by [VanHelsing]Trend Volume and Momentum based indicator
How it works:
The principle of the volume zone oscillator was used here,
but instead of closes > closes (price momentum) was used RSI,
if RSI > 50 it is a positive momentum and we get + volume value, otherwise - volume
Instead of ema's here is a Volume-Weighted Average Price (VWAP) which gives us such shape of TVI line that in general less sensitive to the pullbacks inside a trend.
This indicator is good for catching and following trends.
You can use alerts as well for take values of trend (-1,1) from 1-10D timeframes
Here how to read it
TrendsThe Trends indicator is created for trend trading and (Bitsgap) crypto bots of crypto assets over longer time periods.
Works best for 4h, Daily and Weekly candles (even Monthly), but unsuitable for hourly candles and day trading.
This indicator shows you if a crypto pair is in a Bear, Bull or Sideways market.
The idea is to simplify decision making when to sell or buy, or what pairs to use with trading bots.
Stick to the rule of not having bots in a Bear trend!
- Blue = Bull trend
- Red = Bear trend
- Green = Sideways trend - which can be profitable with trading bots
Divergence-Support/ResistenceAnother script based on zigzag, divergence, and to yield support and resistence levels.
This idea started with below two concepts:
▶ Support and resistence are simply levels where price has rejected to go further down or up. Usually, we can derive this based on pivots. But, if we start looking at every pivot, there will be many of them and may be confusing to understand which one to consider.
▶ Lot of people asked about one of my previous script on divergence detector on how to use it. I believe divergence should be considered as area of support and resistence because, they only amount to temporary weakness in momentum and nothing more. As per my understanding
Trend > Hidden Divergence > Divergence > Oscillator Levels of Overbought and Oversold
⬜ Process
▶ Now combining the above two concepts - what we are trying to do here is draw support resistence lines only on pivots which has observed either divergence or hidden divergence. Continuation and indecision pivots are ignored.
▶ Input requires only few parameters.
Zigzag lengths and oscillator to be used. Oscillator periods are automatically calculated based on zigzag length. Hence no other information required. You can also chose custom oscillator via external source.
▶ Display include horizontal lines of support/resistence which are drawn from the candle from where divergence or hidden divergence is detected.
▶ Support resistence lines are colored based on divergence. Green shades for bullish divergence and bullish hidden divergence whereas red shades for bearish divervence and bearish hidden divergence. Please note, red and green lines does not mean they only provide resistence or support. Any lines which are below the price should be treated as support and any line which are above the price should be treated as resistence.
▶ Divergence symbols are also printed on the bar from where divergence/hidden divergence is detected.
↗ - Bullish Hidden Divergence
↘ - Bearish Hidden Divergence
⤴ - Bullish Divergence
⤵ - Bearish Divergence
▶ Script also demonstrates usage of libraries effectively. I have used following libraries in this code.
import HeWhoMustNotBeNamed/ zigzag /2 as zg
import HeWhoMustNotBeNamed/enhanced_ta/8 as eta
import HeWhoMustNotBeNamed/ supertrend /4 as st
Can be good combination to use it with harmonic patterns.
Zigzag CandlesCan't deny that I am obsessed with zigzags. Been doing some crazy experiments with it and have many more in pipeline. I believe zigzag can be used to derive better trend following methods. Here is an attempt to visualize zigzag as candlesticks. Next steps probably to derive moving average, atr (although there was an attempt of AZR made earlier) and probably supertrend too ;)
Input parameters include ZigzagLength (to calculate zigzag) and CandleSize (number of zigzag pivots in each candle)
CandleSize can be 3 or more. Every time we collect pivots which are equal to CandleSize, we derive one candle. And when we derive a candle, we remove all old pivots except the last one. Becauase, the last pivot acts as open to the next bar and is required.
Body of the candle tells the start and end zigzag pivot in the range. And Wicks signify highest and lowest pivots in the range. High and Low wicks are placed at the pivot where high and lows are formed. Hence, you can see them at different positions each time.
Thanks to @RicardoSantos for suggesting boxes for candles - while I was trying to achieve this with plotbar
Trendlines StrategyUsing the clever calculations and code by BacktestRookies, here is a strategy that buys
when the price breaks above the trend line and sells (or shorts) when it crosses below.
This logic can be reversed, which seems to work better with recent market conditions.
Elliot Wave - ImpulseLets dabble a bit into Elliot Waves.
This is a simple script which tries to identify Wave 1 and 2 of Elliot Impulese Wave and then projects for Wave 3.
Ratios are taken from below link: elliottwave-forecast.com - Section 3.1 Impulse
Wave 2 is 50%, 61.8%, 76.4%, or 85.4% of wave 1 - used for identifying the pattern.
Wave 3 is 161.8%, 200%, 261.8%, or 323.6% of wave 1-2 - used for setting the targets
Important input parameters
Length : Zigzag Length. Keep the numbers low if you are looking for smaller and shorter trades. Keep the numbers high if you are looking for longer and bigger trades.
Error Percent : Adjustments for ratios as it is not always possible to find exactly equal retracement ratio.
Entry Percent : Once Wave 2 is formed, entry is set after reversing 30% of wave 2. This number can be increased or decreased. Caution: Keeping the number too low may result in false signals.
Ignore Trend Direction : If unchecked, it will only look for pattern if Wave 1 has made a higher high. If not, it will ignore Wave 1 condition and only look at wave 1 to 2 ratio.
Handle Duplicates : Since, the labels are generated upon crossover of entry price, this crossover may happen multiple times. Or sometimes wave 2 can further extend and generate new signal with same wave 1. This parameter says how to handle such cases. Keep Last is set to default and is most preferred option.
ShowRatios and ShowWaves lets you display wave line and retracement ratios for each pivots
Previous High/Low MTFIndicator to plot higher time frame previous candle highs and lows.
One of the key factor in understanding the trend is to look at higher time-frames chart.
Parameters are explained below:
resolution : Chose resolution of higher timeframe. If set to same as symbol, it will consider next parameter HTFMultiplier for calculation of higher timeframe
HTFMultiplier : Multiply symbol timeframe to by HTFMultiplier to derive higher time-frame
Offset : Number of higher timeframe candles before to be plotted. 1 means - it will show highs/lows of previous higher timeframe candle.
Trend Direction Force Index v2 - TDFI [wm]TDFI can range from -1 to 1 and thus indicate the direction of the trend.
In periods of consolidation ratios take very low values close to zero as a rule, do not exceed the value of 0.05 (and -0.05), which have set arbitrarily as horizontal signal lines. Rate accelerates rapidly to higher values when the consolidation ends and is a good chance of becoming a permanent trend.
As an extension, the trader can assume that as long as the pointer moves above the signal line and does not come down to the low value of less than 0.05 for at least two bars the trend continues. So the descent below signal line and a return to higher values should be interpreted as a temporary weakening trend. Not before rate remains below 0.05 for at least 2 bars, can we consider that the market is likely to begin to consolidate
In addition, we can assess the strength of the trend, depending on the value of the index – the index reaches 1 trend is strong (-1 is a strong downward trend) and generally values above 0.6 should be so interpreted. Less than in decline should be considered that the trend is losing its momentum.
Change Log:
* Refactored tdfi implementation. Functionally exactly the same
* Added selectable smoothers
* Added finer grained inputs fora each smoother
Trend Lines+++scripts taken from
Nothing here is mine , just put it as I like the combination of those script together when I analyse data
so it make life easy to draw line automode
I suggest 4 hours or daily chart with MACD and RSI
Thanks to autors in scripts
trend hybridThis indicator based on two part
first part is the lower of the famous Darvas top
the upper part is made from EMA trend as replacement for th ethe top of the Darvas box
By similar logic we can decide to go long or short as the Darvas box but herfe by using the Ema trend line which is MTF type we can find better optimum for shorting or longing
So it a simple indicator but can ce very usefull to see trends if properly done
Trend Setter Max BarsThis script allows you to visualize trends. It counts continuous bars in the same direction, then makes an average of the maximum count in the look back period. If Green is above Red, its strength is upward and vice versa. This doesn't use returns or measure price moves.
*Positive Gray is current up bars count. Negative Gray down current down bars count
*Green and Red are average max counts.
This info could possibly be used to gauge trends or momentum.
Note: I finally figured out how to use loops and mutable variables in V3.
Trend Degree Dashboard (Table)📈 Trend Degree Dashboard (Table) — v1.0
This indicator calculates and displays the trend angle (in degrees) based on the linear regression of the selected source (default: close) over a user-defined lookback period (default: 21 bars).
The trend angle gives a quick visual reference of the current market slope — positive (uptrend) or negative (downtrend).
A dashboard table shows the trend angle directly on the chart, with a background color:
🟩 Green background for positive angles (uptrend)
🟥 Red background for negative angles (downtrend)
🔧 Features:
Customizable Lookback Period: Set the number of candles to consider for trend calculation.
Source Selection: Apply the analysis to close, open, high, low, or any other price series.
Dashboard Positioning: Choose where the dashboard appears (Top Left, Top Right, Bottom Left, Bottom Right).
Clean Table Design: Minimalistic and easy-to-read dashboard with automatic background color highlighting based on trend direction.
⚙️ How It Works:
It uses Linear Regression to measure the slope between two consecutive points.
Converts the slope into degrees using the arctangent function (atan) for a geometric interpretation of trend strength and direction.
Updates the dashboard table live with the latest angle value.
✅ Script Highlights:
Non-repainting: Once a bar closes, its value is fixed.
Efficient performance: Lightweight table visualization with no heavy calculations.
Clear trading signals: Positive angles suggest bullish momentum, negative angles suggest bearish momentum.
⚠️ Disclaimer:
This script is a technical analysis tool designed to assist in decision-making but does not guarantee results.
Please use it alongside other tools and practice proper risk management. Always test any indicator on demo accounts before applying it to live trading.
Trend with Mathematical Approach GOLD [AstroHub]
Welcome to the Trend with Mathematical Approach! 🚀
This tool uses a unique mathematical approach to help you spot potential trend beginnings in the market.
By analyzing the derivative of closing prices and applying a specialized moving average, SmartTrend identifies
key points where a new trend might be starting.
🟢 Green arrows show potential BUY opportunities when a new uptrend begins.
🔴 Red arrows indicate potential SELL opportunities when a new downtrend starts.
Additionally, the indicator provides easy-to-read colored backgrounds to highlight potential trend zones.
Green means a potential uptrend, and red suggests a potential downtrend.
To make it even more user-friendly, SmartTrend adds clear labels for BUY and SELL signals directly on the chart,
making it easy for you to spot opportunities at a glance.
💡 Pro Tip: Use the built-in alerts to get notified when SmartTrend identifies a potential trade opportunity.
Enjoy using SmartTrend and happy trading! 📈💰