Strategy · Pine Script v5 · On the chart

ITI

by darkshloser· code credited to Author: dkovache

A Pine strategy script that overlays three SuperTrend lines with different periods and multipliers, plus a 100-period EMA, and computes the same SuperTrends on a higher timeframe set in minutes.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code113
Settings8inputs
LicenceApache-2.0
Last update2 years ago15 Jul 2024

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

113 lines of Pine Script v5 from ITI.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

ITI.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Author: dkovache

//@version=5
strategy("ITI", overlay=true)
import TradingView/ta/5
import mentalRock19315/Slope_TK/1 as TK

// Input period and multiplier
st1_period = input(defval = 12, title = "Period of the first ST")
st1_multiplier = input(defval = 3, title = "Multiplier of the first ST")

st2_period = input(defval = 10, title = "Period of the second ST")
st2_multiplier = input(defval = 1, title = "Multiplier of the second ST")

st3_period = input(defval = 11, title = "Period of the third ST")
st3_multiplier = input(defval = 2, title = "Multiplier of the third ST")


// Setting the three timeframes for analytica
deep_tf = input(defval=60, title="First layer of depth (minutes)", tooltip = "Strong trend timeframe")

// main indicators on curent TF
[trend1, direction1] = ta.supertrend(st1_multiplier, st1_period)
[trend2, direction2] = ta.supertrend(st2_multiplier, st2_period)
[trend3, direction3] = ta.supertrend(st3_multiplier, st3_period)

// main indicators on strong TF
[trend1_strong, direction1_strong] = request.security(syminfo.tickerid, str.tostring(deep_tf), ta.supertrend(st1_multiplier, st1_period))
[trend2_strong, direction2_strong] = request.security(syminfo.tickerid, str.tostring(deep_tf), ta.supertrend(st2_multiplier, st2_period))
[trend3_strong, direction3_strong] = request.security(syminfo.tickerid, str.tostring(deep_tf), ta.supertrend(st3_multiplier, st3_period))

// High level trend
ema_long_term = ta.ema(close, 100)


// Plot Super Trends
plot(direction1 < 0 ? trend1 : na, "Up direction", color.green, style = plot.style_linebr, linewidth = 2)  // 1
plot(direction1 > 0 ? trend1 : na, "Down direction", color.red, style = plot.style_linebr, linewidth = 2)

plot(direction2 < 0 ? trend2 : na, "Up direction", color.green, style = plot.style_linebr, linewidth = 2)  // 2
plot(direction2 > 0 ? trend2 : na, "Down direction", color.red, style = plot.style_linebr, linewidth = 2)

plot(direction3 < 0 ? trend3 : na, "Up direction", color.green, style = plot.style_linebr, linewidth = 2)  // 3
plot(direction3 > 0 ? trend3 : na, "Down direction", color.red, style = plot.style_linebr, linewidth = 2)

// Plot EMA long term
plot(ema_long_term, color = color.yellow)


// Calculate the average slope of the SuperTrend 
nr_of_bars = input.int(2, "Number of bars to calculate the slope", minval=1, step=1)
slope = TK.slope(trend3, nr_of_bars)
log.info(str.tostring(slope))


sellColor = #e4a256
buyColor = #9ce0cc


// ===========================================  MAIN timeframe analyze =======================
var activePosition = false
var activeColor = color.blue
var activeColorPrevState = color.blue

var isOpenPosition = false
var isPositionLong = false

activeColorPrevState := activeColor

if direction1 > 0 and direction2 > 0 and direction3 > 0
    activeColor := color.red
    activePosition := true
else if direction1 < 0 and direction2 < 0 and direction3 < 0
    activeColor := color.green
    activePosition := true
else
    activeColor := color.blue
    activePosition := false
 
plot( slope, title = "Slope", color=activeColor, linewidth = 3)
bgcolor(activePosition == true and activeColor == color.green ? color.new(color.green,80) : na )
bgcolor(activePosition == true and activeColor == color.red ? color.new(color.red,80) : na )


// Alerts
if activePosition == false and activeColor != activeColorPrevState and activeColorPrevState == color.red
    isOpenPosition := false    
    alert("Close SHORT position on MAIN TIMEFRAME", alert.freq_once_per_bar)
if activePosition == false and activeColor != activeColorPrevState and activeColorPrevState == color.green
    isOpenPosition := false
    alert("Close LONG position on MAIN TIMEFRAME", alert.freq_once_per_bar)
if activePosition == true and activeColor != activeColorPrevState and activeColor == color.red
    isOpenPosition := true
    isPositionLong := false
    alert("Open SHORT position on MAIN TIMEFRAME", alert.freq_once_per_bar)
if activePosition == true and activeColor != activeColorPrevState and activeColor == color.green
    isOpenPosition := true
    isPositionLong := true
    alert("Open LONG position on MAIN TIMEFRAME", alert.freq_once_per_bar)

// ============================================ Secondary timeframe analyze ===============================

if isOpenPosition
    if isPositionLong == false and direction1_strong <= 0 and direction2_strong > 0 and direction3_strong > 0
        alert("Light underlying indication to close opned SHORT position")
    else if isPositionLong == false and direction1_strong <= 0 and direction2_strong <= 0 and direction3_strong > 0
        alert("Stronger underlying indication to close SHORT position")

    if isPositionLong == true and direction1_strong >= 0 and direction2_strong < 0 and direction3_strong < 0
        alert("Light underlying indication to close opned LONG position")
    else if isPositionLong == true and direction1_strong >= 0 and direction2_strong >= 0 and direction3_strong < 0
        alert("Stronger underlying indication to close LONG position")

Overview

A slope of the third SuperTrend is plotted over a bar-count input. Backgrounds turn green or red when all three SuperTrends agree on direction, and alerts fire when that agreement ends. The visible code shows no explicit order, stop loss or take profit rules.

Details

Published by

darkshloser on GitHub

Code credit

Author: dkovache, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

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

SettingTypeDefaultVariable
Period of the first STint12st1_period
Multiplier of the first STint3st1_multiplier
Period of the second STint10st2_period
Multiplier of the second STint1st2_multiplier
Period of the third STint11st3_period
Multiplier of the third STint2st3_multiplier
First layer of depth (minutes)int60deep_tf
Number of bars to calculate the slopeint2nr_of_bars
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

Doge SMA

by hackingthemarkets
474 stars

Doge SMA is a long-only moving-average crossover strategy drawn on the price chart. It calculates a fast and a slow simple moving average of close and enters a long position when the fast average crosses above the slow average, but only inside a user-defined s

Strategy v4 TrendMoving averages
Updated 4 years ago · None stated GitHub repository of Doge SMA

This strategy calculates and plots a fast Exponential Moving Average (EMA) and a slow EMA directly on the main price chart. It enters long trades when the fast EMA crosses above the slow EMA and exits when the fast EMA crosses below the slow EMA. Inputs allow

Strategy v6 TrendMoving averages
Updated yesterday · AGPL-3.0 GitHub repository of Forven S01508 — Simple EMA20/50 Cross
330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy
285 stars

Mean Reversion Strategy is an overlay strategy that identifies pullbacks using a long-term EMA, RSI, and candlestick patterns. It generates long signals when a bullish engulfing candle forms below the EMA while RSI is oversold, and short signals when a bearish

Strategy v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Strategy
257 stars

This strategy calculates dynamic support and resistance levels using pivot highs and lows alongside a custom smoothed trend filter and a 3-period EMA. It identifies entry opportunities when price breaks out relative to the trend filter and short-term EMA cross

Strategy v5 TrendSupport & resistance Repaints
Updated 6 weeks ago · None stated GitHub repository of 30s - ES 1m Strategy Candle Bar

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