Strategy · Pine Script v4 · On the chart

Trendsignal Strategy

by DaniilOkrug· code credited to icewalk

The Trendsignal Strategy identifies trend flips using dynamic channel boundaries derived from high and low price ranges over a set lookback period.

View on GitHub

GitHub stars2on the repository
Pine versionv4older, still runs
Lines of code86
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 strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

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

trendsignal strategy.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
strategy("trendsignal strategy", overlay=true, margin_long=100, margin_short=100, default_qty_type=strategy.percent_of_equity, default_qty_value=50)

//---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

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)

//---trendsignal END---

if isBuy == true
    strategy.entry("long", strategy.long)
    alert("BUY", alert.freq_once_per_bar)
if isBuy == false
    strategy.entry("short", strategy.short)
    alert("SELL", alert.freq_once_per_bar)

Overview

Trendsignal Strategy calculates upper and lower thresholds based on a customizable risk setting. When price closes above the upper boundary, the strategy signals an uptrend and enters a long position. When price closes below the lower boundary, it enters a short position. Positions exit only upon opposite trend signals, with no built-in stop loss.

Details

Published by

DaniilOkrug on GitHub

Code credit

icewalk, as written in the script's header

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Trend, Breakout

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

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

This trend-following strategy executes a classic Donchian channel breakout system designed to cross-validate backtest results against external framework benchmarks. It triggers a long entry when the closing price breaks above the highest high of the prior entr

Strategy v6 BreakoutTrend
Updated today · AGPL-3.0 GitHub repository of Forven S01509 - Simple Donchian 20/10 Breakout
257 stars

This strategy plots running pivot highs as red R circles and pivot lows as blue S circles directly on the price chart. It computes an EMA 3 and a Cto trend line from close prices, then generates long signals on upward EMA-Cto crossovers combined with price pos

Strategy v6 TrendMoving averages Repaints
Updated 6 weeks ago · None stated GitHub repository of Best Chart 1m Strategy Candle Bar

12/26-IT Strategy

by hasnocool
106 stars

This strategy executes trades based on crossovers between a 12-period and a 26-period exponential moving average (EMA). Long positions can be filtered by pivot resistance breakouts and RSI boundary ranges. For trade management, it provides two configurable par

Strategy v5 TrendMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of 12/26-IT Strategy

均线突破交易系统

by tangly1024
76 stars

This strategy trades long breakouts of a fast and a slow moving average on the price chart. It opens a long position when price crosses above either average, using a percentage of equity as size. It reduces the position by a set share when the high reaches the

Strategy v5 TrendMoving averages
Updated 4 months ago · None stated GitHub repository of 均线突破交易系统
53 stars

This strategy enters long or short on the price chart when price is on the correct side of a 200-period EMA, MACD agrees, RSI is not at the opposing extreme, ADX exceeds a threshold, volume beats a 20-bar average, and close breaks the recent high or low. A tim

Strategy v6 TrendOscillators & momentum
Updated 2 months ago · MPL-2.0 GitHub repository of BTCUSD 5M Optimized Strategy

More strategys

Trade Your Charts With a Regulated Broker

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

Compare brokers