Indicator · Pine Script v4 · On the chart

Trendsignal

by DaniilOkrug· code credited to icewalk

Trendsignal plots buy and sell markers on the price chart when a short-term trend flips.

View on GitHub

Repaints

GitHub stars2on the repository
Pine versionv4older, still runs
Lines of code85
Settings3inputs
LicenceMIT
Last update4 years ago15 Dec 2021

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

85 lines of Pine Script v4 from trendsignal indicator.txt, published under MIT. Keep the author's credit and licence lines when you reuse it.

trendsignal indicator.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © icewalk

//@version=4
study("trendsignal", overlay=true)

//---INPUT---

RISK = input(3, title="RISK", type=input.integer)
Alert_Delay_In_Seconds = input(0, title="Alert_Delay_In_Seconds", type=input.integer)
alertsOn = input(false, title="Включить оповещения?", type=input.bool)

//---INPUT END---

bool isBuy = na

int SSP = 9
var int PrevAlertTime = 0
var float alertBar = 0

var int K = na
float Range = 0
float AvgRange = 0
var float smin = na
var float smax = na
var float SsMax = na
var float SsMin = na
var float price = na
var bool uptrend = na
var bool old = false

// var int limit = bar_index - counted_bars
// if counted_bars == 0
int limit = 1 + SSP

K := 33 - RISK
for shift = limit to 0
    for i = shift to (shift + SSP)
        AvgRange += high[i] - low[i]
        
    Range := AvgRange / (SSP + 1)
    
    SsMax := high[shift]
    SsMin := low[shift]
    for i = shift to (shift + SSP - 1)
        price := high[i]
        if SsMax < price
            SsMax := price
        price := low[i]
        if SsMin > price
            SsMin := price
            
    smin := SsMin + (SsMax - SsMin)*K/100
    smax := SsMax - (SsMax - SsMin)*K/100
    
    if close[shift] < smin
        uptrend := false
    
    if close[shift] > smax
        uptrend := true
    
    if uptrend != old and uptrend == true
        
        if bar_index > alertBar and shift == 0
            isBuy := true
            alertBar := bar_index
            PrevAlertTime := time
    
    if uptrend != old and uptrend == false and (time - PrevAlertTime > 1 * Alert_Delay_In_Seconds)
        
        if bar_index > alertBar and shift == 0  and (time - PrevAlertTime > 1 * Alert_Delay_In_Seconds)
            isBuy := false
            alertBar := bar_index
            PrevAlertTime := time
    
    old := uptrend

plotshape(isBuy == true, title="Buy", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(isBuy == false, title="Sell", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)

if alertsOn
    if isBuy == true
        alert("BUY", alert.freq_once_per_bar)
    if isBuy == false
        alert("SELL", alert.freq_once_per_bar)

Overview

Trendsignal measures the average high-low range and the highest and lowest prices over a fixed nine-bar window, then builds inner thresholds from the RISK setting. A close above the upper threshold turns the trend up and draws a green triangle; a close below the lower threshold turns it down and draws a red triangle. Optional alerts can wait a set number of seconds between signals. Markers can change while the current bar is still forming.

Details

Published by

DaniilOkrug on GitHub

Code credit

icewalk, as written in the script's header

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Trend, Breakout

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
RISKint3RISK
Alert_Delay_In_Secondsint0Alert_Delay_In_Seconds
Включить оповещения?boolfalsealertsOn
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Sideway Zones Live

by dearvn
257 stars

Sideway Zones Live is an overlay indicator that estimates inner and outer sideways bands from recent highs and lows with a rational quadratic kernel. It tracks swing pivots over a loopback period and counts bars that remain between the outer high and low. Afte

Indicator v5 TrendSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of Sideway Zones Live
114 stars

This indicator adapts Michael Chalek's Dual Thrust trading concept to plot breakout levels and overlay bands directly on the price chart. It calculates lookback ranges based on historical price action and provides two algorithmic variations along with multiple

Indicator v4 TrendBreakout Repaints
Updated 1 year ago · None stated GitHub repository of Dual Thrust Trading Algorithm
56 stars

This indicator calculates dynamic upper and lower trendlines from pivot highs and pivot lows across a specified bar length. Trendline slopes are derived using ATR, standard deviation, or linear regression methods. It plots trendlines and breakout signal labels

Indicator v5 TrendSupport & resistance Repaints
Updated 2 months ago · None stated GitHub repository of Trendlines With Breaks [LUX]

Reversal Breakout System

by TamaraKGreen
46 stars

This indicator detects inside candles inside larger parent candles on the price chart. It plots colored boxes around inside and parent candles, fills them with user-adjustable transparency, draws Fibonacci retracement lines and mother candle range lines, and d

Indicator v6 Candlestick patternsBreakout
Updated 7 weeks ago · None stated GitHub repository of Reversal Breakout System

RSC Trend Trading Study

by readysetcryptocodes
43 stars

This indicator plots Donchian Channels alongside fast and slow simple moving averages directly on the price chart. It generates bullish breakout signals when the high reaches the upper channel while the close is above the 50 SMA (and optionally the 200 SMA). B

Indicator v4 TrendBreakout
Updated 2 years ago · None stated GitHub repository of RSC Trend Trading Study

Candle Stage Analysis

by ChartsLector
41 stars

This indicator classifies market trends into structured stages based on moving average alignments, compression, and ATR distance from the 50-period SMA. It tracks multiple exponential moving averages against the 50 SMA to detect basing phases, breakouts, trend

Indicator v6 TrendMoving averages
Updated 2 days ago · None stated GitHub repository of Candle Stage Analysis

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers