Indicator · Pine Script v4 · On the chart

Five-in-one Strategy

by capissimo

Five-in-one Strategy combines five analytical tools into a single price chart overlay: the Dual Thrust Trading Algorithm (DTTA), Semafore, HalfTrend, Nick Rypock Trailing Reverse, and Tweezer or Kangaroo Tail candlestick patterns.

View on GitHub

Repaints

GitHub stars114on the repository
Pine versionv4older, still runs
Lines of code404
Settings29inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago7 Nov 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 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

404 lines of Pine Script v4 from banned-scripts/Five-in-one-Strategy.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Five-in-one-Strategy.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © capissimo

//@version=4
study("Five-in-one Strategy", '', true)

// Description:

// This is a five-in-one strategy using:
//     Dual Thrust Trading Algorithm © capissimo
//     Semafore                      © DevLucem 
//     Halftrend                     © everget 
//     Nick Rypock Trailing Reverse  © everget 
//     Tweezer and Kangaroo Tail     © LonesomeTheBlue

// Anyone of the indicators can be switched off.

//-------------------- Inputs

ftype = input('None', 'Filter Signals by', options=['Volatility','Volume','Both','None'])

dtta  = input(true,  '===Dual Thrust Trading Algo===')
ds    = input(close, "Dataset")
algo  = input(2,     "Use DTTA algorithm #:",        options=[1, 2])
mlen  = input(4,     "DTTA Lag M",                   minval=1) 
nlen  = input(20,    "DTTA Lag N",                   minval=1) 
k     = input(0.5,   "DTTA Coeff",                   minval=0.01, step=0.01) // .7, .9
disc  = input(0.5,   "DTTA Coeff Trending Discount", minval=0.01, step=0.01) // . 5, .6

//-------------------- System Variables

var BUY  =  1
var SELL = -1
var HOLD =  0

//-------------------- Dynamic Arrays

var signal = 0

//-------------------- Custom Functions

volumeBreak(thres) =>  
    rsivol   = rsi(volume, 14)  
    osc      = hma(rsivol, 10)  
    osc > thres                     

volatilityBreak(volmin, volmax) => atr(volmin) > atr(volmax)

dtta1_algo(k1, k2, len) =>
    hh = highest(high, len)[1]
    hc = highest(ds, len)[1]
    lc = lowest(ds, len)[1]
    ll = lowest(low, len)[1]
    
    // The range is calculated based on the close, high and low over the most recent N-periods.  
    // Trade is made when the market moves a certain range from the opening price. 
    range = max(hh - lc, hc - ll)
    [open + k1 * range, open - k2 * range] 
    
dtta2_algo(k1, k2, ml, nl) =>
    hh = 0.0, ll = 0.0, hc = 0.0, lc = 0.0

    hh := highest(high, ml)[1]
    hc := highest(ds, ml)[1]
    lc := lowest(ds, ml)[1]
    ll := lowest(low, ml)[1]
    
    sellRange = (hh - lc) >= (hc - ll) ? hh - lc : hc - ll
    
    hh := highest(high, nl)[1]
    hc := highest(ds, nl)[1]
    lc := lowest(ds, nl)[1]
    ll := lowest(low, nl)[1]
    
    buyRange = (hh - lc) >= (hc - ll) ? hh - lc : hc - ll
    [open + k1 * buyRange, open - k2 * sellRange] 
    
//-------------------- Logic

tbase   = (time - time[1]) / 1000
tcurr   = (timenow - time_close[1]) / 1000
barlife = tcurr / tbase

filter =   ftype=='Volatility' ? volatilityBreak(1, 10) 
         : ftype=='Volume'     ? volumeBreak(49) 
         : ftype=='Both'       ? volatilityBreak(1, 10) and volumeBreak(49)
         :                       true

// Bullish/Bearish Identification
rng     = close - open
doji    = rng == 0 
uptrend = rng > 0 or doji and rng[1] > 0
dntrend = rng < 0 or doji and rng[1] < 0

k1 = k, k2 = k
if uptrend  // Assigned empirically. To be optimized separately
    k1 := k1 * disc  //.2
    k2 := k2 * (1 + disc)
if dntrend
    k1 := k1 * (1 + disc)
    k2 := k2 * disc //.2

[bt1, st1] = dtta1_algo(k1, k2, mlen)
[bt2, st2] = dtta2_algo(k1, k2, mlen, nlen)

buyTrigger = 0.0, sellTrigger = 0.0
if algo == 1 
    buyTrigger := bt1, sellTrigger := st1
else    
    buyTrigger := bt2, sellTrigger := st2

signal := ds >= buyTrigger and uptrend and filter ? BUY : ds <= sellTrigger and dntrend and filter ? SELL : nz(signal[1])  

startLongTrade  = change(signal) and signal==BUY  
startShortTrade = change(signal) and signal==SELL 
endLongTrade    = change(signal) and signal==SELL
endShortTrade   = change(signal) and signal==BUY 

//------------------ Rendering

plotshape(dtta and startLongTrade  ? low   : na, 'Buy',  shape.labelup,   location.belowbar, color.blue, 30, size=size.tiny)
plotshape(dtta and startShortTrade ? high  : na, 'Sell', shape.labeldown, location.abovebar, color.red,  30, size=size.tiny)
plot(dtta and endLongTrade         ? ohlc4 : na, 'StopBuy',  color.blue, 2, plot.style_cross)
plot(dtta and endShortTrade        ? ohlc4 : na, 'StopSell', color.red,  2, plot.style_cross)

//================== Semafore © DevLucem 

semafore = input(true,  '===Semafore===')
repaint  = input(false, "Allow Drawing of an Unconfirmed Signal")

zigzag(Depth, Deviation, Size) =>
    var lw = 1, var hg = 1
    lw := lw + 1, hg := hg + 1
    p_lw = -lowestbars(Depth), p_hg = -highestbars(Depth)
    lowing = lw == p_lw or low - low[p_lw] > Deviation*syminfo.mintick
    highing = hg == p_hg or high[p_hg] - high > Deviation*syminfo.mintick
    lh = barssince(not highing), ll = barssince(not lowing)
    down = lh > ll, lower = low[lw] > low[p_lw], higher = high[hg] < high[p_hg]
    if lw != p_lw and (not down[1] or lower)
        lw := p_lw < hg ? p_lw : 0
    if hg != p_hg and (down[1] or higher)
        hg := p_hg < lw ? p_hg : 0
    x1  = down ? lw : hg
    y1  = down ? low[lw] : high[hg]
    label point = na
    if semafore and repaint and filter
        point := label.new(bar_index-x1, y1, color=down ? color.green : color.red, style=down ? label.style_label_up : label.style_label_down, size=Size)
        if down == down[1]
            label.delete(point[1])
    if semafore and not repaint and down != down[1] and filter
        nx = down ? hg : lw
        point := label.new(bar_index-nx, down ? high[nx] : low[nx], color=down ? color.red : color.green, style=down ? label.style_label_down : label.style_label_up, size=Size)
    down != down[1]

var switch = false
switch := zigzag(input(14, "Depth"), input(3.0, "Deviation"), size.small) or switch

//================== HalfTrend © everget 

halftrend        = input(true, '===HalfTrend===')
amplitude        = input(2,    "Amplitude")
channelDeviation = input(2,    "Channel Deviation")

var int trend     = 0
var int nextTrend = 0
var float maxLowPrice  = nz(low[1], low)
var float minHighPrice = nz(high[1], high)

var float up    = 0.0
var float down  = 0.0
float atrHigh   = 0.0
float atrLow    = 0.0
float arrowUp   = na
float arrowDown = na

atr2 = atr(100) / 2
dev = channelDeviation * atr2

highPrice = high[abs(highestbars(amplitude))]
lowPrice  = low[abs(lowestbars(amplitude))]
highma    = sma(high, amplitude)
lowma     = sma(low, amplitude)

if nextTrend == 1
    maxLowPrice := max(lowPrice, maxLowPrice)
    if highma < maxLowPrice and close < nz(low[1], low)
        trend := 1
        nextTrend := 0
        minHighPrice := highPrice
else
    minHighPrice := min(highPrice, minHighPrice)
    if lowma > minHighPrice and close > nz(high[1], high)
        trend := 0
        nextTrend := 1
        maxLowPrice := lowPrice

if trend == 0
    if not na(trend[1]) and trend[1] != 0
        up := na(down[1]) ? down : down[1]
        arrowUp := up - atr2
    else
        up := na(up[1]) ? maxLowPrice : max(maxLowPrice, up[1])
    atrHigh := up + dev
    atrLow := up - dev
else
    if not na(trend[1]) and trend[1] != 1 
        down := na(up[1]) ? up : up[1]
        arrowDown := down + atr2
    else
        down := na(down[1]) ? minHighPrice : min(minHighPrice, down[1])
    atrHigh := down + dev
    atrLow := down - dev

ht = trend == 0 ? up : down

buySignal  = not na(arrowUp)   and (trend == 0 and trend[1] == 1) and filter 
sellSignal = not na(arrowDown) and (trend == 1 and trend[1] == 0) and filter 

plotshape(halftrend and buySignal  ? low  : na, "Arrow Up",   shape.triangleup,   location.absolute, color.blue, size=size.tiny)
plotshape(halftrend and sellSignal ? high : na, "Arrow Down", shape.triangledown, location.absolute, color.red,  size=size.tiny)

//==================== Nick Rypock Trailing Reverse © everget

nrypock    = input(true, "===Nick Rypock Trailing Reverse===")
percentage = input(0.1, "Coefficient of Correction (%)", minval=0, maxval=100, step=0.1) * 0.01

var int trend2 = 0
var float hp = close
var float lp = close
float nrtr = close

if trend2 >= 0
    if close > hp
        hp := close
        hp
    nrtr := hp * (1 - percentage)
    if close <= nrtr
        trend2 := -1
        lp := close
        nrtr := lp * (1 + percentage)
        nrtr
else
    if close < lp
        lp := close
        lp
    nrtr := lp * (1 + percentage)
    if close > nrtr
        trend2 := 1
        hp := close
        nrtr := hp * (1 - percentage)
        nrtr

buySignal2  = trend2 ==  1 and trend2[1] == -1 and filter 
sellSignal2 = trend2 == -1 and trend2[1] ==  1 and filter 

plotshape(nrypock and buySignal2  ? low  : na, "Buy Label",  shape.labelup,   location.absolute, color.blue, size=size.tiny, text="B", textcolor=color.white, transp=0)
plotshape(nrypock and sellSignal2 ? high : na, "Sell Label", shape.labeldown, location.absolute, color.red,  size=size.tiny, text="S", textcolor=color.white, transp=0)

//==================== Tweezer and Kangaroo Tail © LonesomeTheBlue

enable_tk   = input(false, "===Tweezer and Kangaroo Tail===")
maxrate     = input(150.,  "Max Rate % Between Wick Sizes") / 100.
leveldiff   = input(20.,   "Max Difference in level %") / 100.
prd         = input(5,     "Highest/Lowest Period")
apartprd    = input(12,    "Max Distance between Tweezers", minval=1)

prd1        = input(20,    "Period for Room",            minval=2, maxval=50)
prd2        = input(8,     "Minimum Period for Room",    minval=2, maxval=50)
atrmult     = input(5,     "ATR Factor for Room Height", minval=2, maxval=30)
wickmult    = input(3.,    "Wick/Body Rate",             minval = 1)
wickmultavg = input(2.,    "Wick/Average_Wick Rate",     minval=1)

topwick    = high - max(close, open)
bottomwick = min(close, open) - low
body = abs(close - open)
ishb = highestbars(prd) == 0
islb = lowestbars(prd) == 0

aparttweezers_top(len) =>
    ret = 0
    if topwick > 0
        for x = 1 to apartprd
            if nz(topwick[x]) == 0
                break
            if (max(topwick, topwick[x]) / min(topwick, topwick[x])) <= maxrate and abs(high - high[x]) < max(topwick, topwick[x]) * leveldiff and ishb[x]
                ret := x
                break
            else 
                if high[x] >= high
                    ret := 0
                    break
    ret
    
aparttweezers_bottom(len) =>
    ret = 0
    if bottomwick > 0
        for x = 1 to apartprd
            if nz(bottomwick[x]) == 0
                break
            if (max(bottomwick, bottomwick[x]) / min(bottomwick, bottomwick[x])) <= maxrate and abs(low - low[x]) < max(bottomwick, bottomwick[x]) * leveldiff and islb[x]
                ret := x
                break
            else 
                if low[x] <= low
                    ret := 0
                    break
    ret

top_tweezer    = enable_tk and aparttweezers_top(apartprd) and filter 
bottom_tweezer = enable_tk and aparttweezers_bottom(apartprd) and filter 

// KANGAROO TAIL 
float ph = highestbars(high, prd1) == 0 ? high : na
float pl = lowestbars(low, prd1) == 0 ? low : na
var dir = 0
dir := iff(ph and na(pl), 1, iff(pl and na(ph), -1, dir))
var max_array_size = 4
var tk_zigzag = array.new_float(4, 0.)

add_to_zigzag(value, bindex) =>
    array.unshift(tk_zigzag, bindex)
    array.unshift(tk_zigzag, value)
    array.pop(tk_zigzag)
    array.pop(tk_zigzag)
    
update_zigzag(value, bindex) =>
    if array.size(tk_zigzag) == 0
        add_to_zigzag(value, bindex)
    else
        if (dir == 1 and value > array.get(tk_zigzag, 0)) or (dir == -1 and value < array.get(tk_zigzag, 0))
            array.set(tk_zigzag, 0, value)
            array.set(tk_zigzag, 1, bindex)
        0.

dirchanged = change(dir)
if ph or pl
    if dirchanged
        add_to_zigzag(dir == 1 ? ph : pl, bar_index)
    else
        update_zigzag(dir == 1 ? ph : pl, bar_index)

averagetopwicksize = sma(topwick, 50)

topkangaroo = enable_tk and dir == 1  and topwick >= body * wickmult and close <= low + (high - low) / 3 and open <= low + (high - low) / 3 and 
  open < high[1] and open > low[1] and close < high[1] and close > low[1] and topwick >= wickmultavg * averagetopwicksize and body > 0 and
  ph and array.get(tk_zigzag, 0) == high and array.get(tk_zigzag, 0) - array.get(tk_zigzag, 2) > atr(50) * atrmult and array.get(tk_zigzag, 1) - array.get(tk_zigzag, 3) > prd2 and filter 

bottomkangaroo = enable_tk and dir == -1  and bottomwick >= body * wickmult and close >= high - (high - low) / 3 and open >= high - (high - low) / 3 and 
  open < high[1] and open > low[1] and close < high[1] and close > low[1] and bottomwick >= wickmultavg * averagetopwicksize and body > 0 and
  pl and array.get(tk_zigzag, 0) == low and array.get(tk_zigzag, 2) - array.get(tk_zigzag, 0) > atr(50) * atrmult and array.get(tk_zigzag, 1) - array.get(tk_zigzag, 3) > prd2 and filter 

plotshape(top_tweezer,    '', shape.labeldown, location.abovebar, color.red,  text="T", textcolor = color.white)
plotshape(bottom_tweezer, '', shape.labelup,   location.belowbar, color.lime, text="T", textcolor = color.black)
plotshape(topkangaroo,    '', shape.labeldown, location.abovebar, color.red,  text="K", textcolor = color.white)
plotshape(bottomkangaroo, '', shape.labelup,   location.belowbar, color.lime, text="K", textcolor = color.black)

//-------------------- Backtesting

show_info = input(true, '===Information for DTTA only===')
lot_size  = input(0.01,  'Lot Size', options=[0.01,0.1,0.2,0.3,0.5,1,2,3,5,10,20,30,50,100,1000]) 

bidask = (open+high+low)/3

var float start_long_trade  = bidask  
var float long_trades       = 0.
var float start_short_trade = bidask  
var float short_trades      = 0.
var int   wins              = 0
var int   trade_count       = 0

if startLongTrade 
    start_long_trade := bidask 
if endLongTrade
    ldiff         = (bidask - start_long_trade)
    wins         := ldiff > 0 ? 1 : 0
    long_trades  := ldiff * lot_size   
    trade_count  := 1
if startShortTrade 
    start_short_trade := bidask
if endShortTrade
    sdiff         = (start_short_trade - bidask)
    wins         := sdiff > 0 ? 1 : 0
    short_trades := sdiff * lot_size 
    trade_count  := 1
    
cumreturn   = cum(long_trades) + cum(short_trades)  //-- cumulative return 
totaltrades = cum(trade_count)
totalwins   = cum(wins)  
totallosses = totaltrades - totalwins == 0 ? 1 : totaltrades - totalwins

//------------------- Information

var label lbl = na

info =  'CR='          + tostring(cumreturn,             '#.#') 
      + '\nTrades: '   + tostring(totaltrades,           '#')
      + '\nWin/Loss: ' + tostring(totalwins/totallosses, '#.##') 
      + '\nWinrate: '  + tostring(totalwins/totaltrades, '#.#%')       
      + '\nBar Time: ' + tostring(barlife,               '#.#%')

if show_info and barstate.islast  
    lbl := label.new(bar_index, ohlc4, info, xloc.bar_index, yloc.price, 
                     color.new(color.blue, 100), label.style_label_left, color.black, size.small, text.align_left)
    label.delete(lbl[1])

Overview

Five-in-one Strategy generates trade signals using price breakout triggers adapted to bullish or bearish trends, which can be filtered by volume or volatility thresholds. Users can independently toggle each indicator, adjust DTTA lag lengths and coefficients, and configure pattern sensitivity. Signals can be set to allow unconfirmed drawings, which may repaint prior to bar closure.

Details

Published by

capissimo on GitHub

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Trend, Breakout, Volatility & bands, Candlestick patterns

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
Filter Signals bystringNoneftype
===Dual Thrust Trading Algo===booltruedtta
Datasetsourcecloseds
Use DTTA algorithm #:int2algo
DTTA Lag Mint4mlen
DTTA Lag Nint20nlen
DTTA Coefffloat0.5k
DTTA Coeff Trending Discountfloat0.5disc
===Semafore===booltruesemafore
Allow Drawing of an Unconfirmed Signalboolfalserepaint
Depthint14Depth
Deviationfloat3.0Deviation
Show all 29 settings
SettingTypeDefaultVariable
===HalfTrend===booltruehalftrend
Amplitudeint2amplitude
Channel Deviationint2channelDeviation
===Nick Rypock Trailing Reverse===booltruenrypock
Coefficient of Correction (%)float0.1percentage
===Tweezer and Kangaroo Tail===boolfalseenable_tk
Max Rate % Between Wick Sizesinput150.maxrate
Max Difference in level %input20.leveldiff
Highest/Lowest Periodint5prd
Max Distance between Tweezersint12apartprd
Period for Roomint20prd1
Minimum Period for Roomint8prd2
ATR Factor for Room Heightint5atrmult
Wick/Body Rateinput3.wickmult
Wick/Average_Wick Rateinput2.wickmultavg
===Information for DTTA only===booltrueshow_info
Lot Sizefloat0.01lot_size
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

Raschke Patterns

by TradersPost
218 stars

This overlay indicator marks Linda Raschke short-term bar setups on the price chart. It flags Turtle Soup and Turtle Soup plus one false breakouts of a prior extreme, 80-20 bars, inside bars, failed inside-bar breakouts, outside up and down bars, NR4 and NR7 c

Indicator v6 Candlestick patternsBreakout Repaints
Updated 3 months ago · None stated GitHub repository of Raschke Patterns

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
32 stars

Ghost Channels fits dynamic parallel trend channels over a configurable lookback window using linear regression or pivot swing methods. It layers confirmation signals onto the channel geometry, detecting candlestick pattern reactions at the rails, volume-confi

Indicator v6 TrendBreakout
Updated 2 days ago · MIT GitHub repository of Ghost Channels [mph1nance]

Zen Z Bars V1

by Zen-Tim
29 stars

Zen Z Bars V1 analyzes bar-by-bar price action, candle range expansion, and internal bar strength (IBS). It identifies breakouts, inside and outside bars, climax candles based on range expansion factors, and tiered range multiple bars. The indicator draws brea

Indicator v5 Candlestick patternsBreakout
Updated 2 weeks ago · MIT GitHub repository of Zen Z Bars V1
15 stars

This indicator plots Bollinger Bands and smoothed HAMA candles on the price chart. It builds each candle from separate moving averages of open, high, low and close, using selectable EMA, SMA or WMA lengths. A simple moving average forms the band basis, and an

Indicator v5 Candlestick patternsMoving averages
Updated 4 months ago · Apache-2.0 GitHub repository of NSDT HAMA Candles with Bollinger Bands

Calculates adaptive arithmetic candles by blending price data with Kaufman Efficiency Ratio smoothing and a linear regression anchor. It measures trend health using a zero-to-hundred Quality Score derived from market efficiency, regression slope, and normalize

Indicator v6 TrendCandlestick patterns
Updated yesterday · MIT GitHub repository of Adaptive Arithmetic Candles + Quality Score [WavesUnchained]

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