0% found this document useful (0 votes)
10 views

FTL

The document contains a collection of Pine Script code snippets for various technical analysis indicators used in trading. It includes implementations for a Fast Trend Line (FTL), HalfTrend, Dynamic Structure Indicator (DSI), and a candle plotting feature, each with customizable parameters for user input. The scripts are designed to analyze price movements, identify trends, and generate alerts based on specific conditions.

Uploaded by

Atul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

FTL

The document contains a collection of Pine Script code snippets for various technical analysis indicators used in trading. It includes implementations for a Fast Trend Line (FTL), HalfTrend, Dynamic Structure Indicator (DSI), and a candle plotting feature, each with customizable parameters for user input. The scripts are designed to analyze price movements, identify trends, and generate alerts based on specific conditions.

Uploaded by

Atul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

//@version=4

study("FTL", overlay=true)
// INPUTS:
lenFast = input(1, title="Length of Fast ", type=input.integer, minval=1)
lenSlow = input(5, title="Length of Slow ", type=input.integer, minval=1)
lenC = input(10, title="Length of Curve", type=input.integer, minval=1)

co(sFast, sSlow, lFast, lSlow, lC)=>


fastC = sma(sFast, lFast)
slowC = sma(sSlow, lSlow)
cC = fastC + slowC
sma(cC, lC)

closeC = co(close, close, lenFast, lenSlow, lenC)


// PLOTTING:
lineColor = closeC > closeC[1] ? color.green : color.red

c = plot(closeC/2, title=" Curve", color=lineColor, linewidth=2, transp=0)

//@version=4
///study(title="Candles", shorttitle="Candles", format=format.price, precision=4,
overlay=false)

signal_length = input(title="Soft", type=input.integer, minval = 1, maxval = 200,


defval = 25)
sma_signal = input(title="Strong", type=input.bool, defval=true)

lin_reg = input(title="Soft1", type=input.bool, defval=true)


linreg_length = input(title="Strong1", type=input.integer, minval = 1, maxval =
200, defval = 50)

bopen = lin_reg ? linreg(open, linreg_length, 0) : open


bhigh = lin_reg ? linreg(high, linreg_length, 0) : high
blow = lin_reg ? linreg(low, linreg_length, 0) : low
bclose = lin_reg ? linreg(close, linreg_length, 0) : close

r = bopen < bclose

signal = sma_signal ? sma(bclose, signal_length) : ema(bclose, signal_length)

plotcandle(r ? bopen : na, r ? bhigh : na, r ? blow: na, r ? bclose : na,


title="Candles", color= color.green, wickcolor=color.green,
bordercolor=color.green, editable= true)
plotcandle(r ? na : bopen, r ? na : bhigh, r ? na : blow, r ? na : bclose,
title="Candles", color=color.red, wickcolor=color.red, bordercolor=color.red,
editable= true)

plot(signal, color=color.orange)

//@version=4
// Copyright (c) 2021-present, Alex Orekhov (everget)
///study("HalfTrend", overlay=true)

amplitude = input(title="Amplitude", defval=1)


channelDeviation = input(title="Channel Deviation", defval=2)
showArrows = input(title="Show Arrows", defval=true)
showChannels = input(title="Show Channels", defval=true)
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

var color buyColor = color.blue


var color sellColor = color.red

htColor = trend == 0 ? buyColor : sellColor


htPlot = plot(ht, title="HalfTrend", linewidth=2, color=htColor)

atrHighPlot = plot(showChannels ? atrHigh : na, title="ATR High",


style=plot.style_circles, color=sellColor)
atrLowPlot = plot(showChannels ? atrLow : na, title="ATR Low",
style=plot.style_circles, color=buyColor)

fill(htPlot, atrHighPlot, title="ATR High Ribbon", color=sellColor)


fill(htPlot, atrLowPlot, title="ATR Low Ribbon", color=buyColor)

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


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

plotshape(showArrows and buySignal ? atrLow : na, title="Arrow Up",


style=shape.triangleup, location=location.absolute, size=size.tiny, color=buyColor)
plotshape(showArrows and sellSignal ? atrHigh : na, title="Arrow Down",
style=shape.triangledown, location=location.absolute, size=size.tiny,
color=sellColor)

alertcondition(buySignal, title="Alert: HalfTrend Buy", message="HalfTrend Buy")


alertcondition(sellSignal, title="Alert: HalfTrend Sell", message="HalfTrend Sell")

// @version=4
////study("Dynamic Structure Indicator v2.0", shorttitle="DSI", overlay=true)

// Get user input


atrMovement = input(title="ATR Movement Required", type=input.float, defval=1.0)
lookback = input(title="High/Low Lookback", type=input.integer, defval=25, step=5)
maxZoneSize = input(title="Max Zone Size (Compared to ATR)", type=input.float,
defval=2.5, step=0.5)
newStructureReset = input(title="Zone Update Count Before Reset",
type=input.integer, defval=25, step=5)
drawPreviousStructure = input(title="Draw Previous Structure", type=input.bool,
defval=true)

// Get current ATR value


atr = atr(14)

// Get highest body and lowest body for the current candle
highestBody = open > close ? open : close
lowestBody = open > close ? close : open

// Set up our persistent S&R variables (1 = the wick and 2 = the body)
var res1 = 0.0
var res2 = 0.0
var sup1 = 0.0
var sup2 = 0.0
var lookForNewResistance = true
var lookForNewSupport = true

// Set up our *previous* support & resistance variables (for drawing support-
turned-resistance etc)
var previousRes1 = 0.0
var previousRes2 = 0.0
var previousSup1 = 0.0
var previousSup2 = 0.0

// Set up our ATR variables (for identifying significant declines/rallies to


validate S&R zones)
var atrSaved = 0.0
var potentialR1 = 0.0
var potentialR2 = 0.0
var potentialS1 = 0.0
var potentialS2 = 0.0

// Detect fractal swing highs for resistance


// We're looking for this pattern: .|.
if high[1] == highest(high, lookback) and high < high[1] and lookForNewResistance
r1 = high[1]
r2 = highestBody[2] > highestBody[1] ? highestBody[2] : highestBody >
highestBody[1] ? highestBody : highestBody[1]
if (r1 - r2) / atr <= maxZoneSize
lookForNewResistance := false
potentialR1 := r1
potentialR2 := r2
atrSaved := atr

// Detect fractal swing lows for support


// We're looking for this pattern: *|*
if low[1] == lowest(low, lookback) and low > low[1] and lookForNewSupport
s1 = low[1]
s2 = lowestBody[2] < lowestBody[1] ? lowestBody[2] : lowestBody < lowestBody[1]
? lowestBody : lowestBody[1]
if (s2 - s1) / atr <= maxZoneSize
lookForNewSupport := false
potentialS1 := s1
potentialS2 := s2
atrSaved := atr

// Check if potential resistance zone has already been violated. If it has, reset
our potential R1 & R2
if close > potentialR1 and barstate.isconfirmed
potentialR1 := na
potentialR2 := na

// Check if potential support zone has already been violated. If it has, reset our
potential S1 & S2
if close < potentialS1 and barstate.isconfirmed
potentialS1 := na
potentialS2 := na

// Check if we've had a significant decline since detecting swing high


if potentialR1 - low >= (atrSaved * atrMovement)
previousRes1 := na(previousRes1) ? potentialR1 : previousRes1 // Store previous
resistance if we're not already drawing it
previousRes2 := na(previousRes2) ? potentialR2 : previousRes2
res1 := potentialR1
res2 := potentialR2
potentialR1 := na
potentialR2 := na

// Check if we've had a significant rally since detecting swing low


if high - potentialS1 >= (atrSaved * atrMovement)
previousSup1 := na(previousSup1) ? potentialS1 : previousSup1 // Store previous
support if we're not already drawing it
previousSup2 := na(previousSup2) ? potentialS2 : previousSup2
sup1 := potentialS1
sup2 := potentialS2
potentialS1 := na
potentialS2 := na

// Declare support & resistance update counters


// This is used for forcing a zone reset if a zone is not violated within a
reasonable period of time
var supCount = 0
var resCount = 0

// If the previous resistance high has been violated then begin searching for a new
resistance zone
if close >= res1 and barstate.isconfirmed
lookForNewResistance := true
lookForNewSupport := true
resCount := resCount + 1

// If the previous support low has been violated then begin searching for a new
support zone
if close <= sup1 and barstate.isconfirmed
lookForNewSupport := true
lookForNewResistance := true
supCount := supCount + 1

// If our current resistance zone has been violated, store its values to draw new
*potential* support zone
// The idea being that once a major resistance zone is violated it often becomes
future support
// But we only save previous S&R if we don't already have one saved (or our zone
update count exceeds newStructureReset)
if (close > res1 and na(previousRes1) and barstate.isconfirmed) or previousRes1 ==
0.0 or supCount >= newStructureReset
previousRes1 := res1
previousRes2 := res2
supCount := 0

// If our current support zone has been violated, store its values to draw new
*potential* resistance zone
// The idea being that once a major support zone is violated it often becomes
future resistance
// But we only save previous S&R if we don't already have one saved (or our zone
update count exceeds newStructureReset)
if (close < sup1 and na(previousSup1) and barstate.isconfirmed) or previousSup1 ==
0.0 or resCount >= newStructureReset
previousSup1 := sup1
previousSup2 := sup2
resCount := 0

// If our resistance-turned-support zone has been violated, reset our saved


resistance variables
if close < previousRes2 and barstate.isconfirmed
previousRes1 := na
previousRes2 := na

// If our support-turned-resistance zone has been violated, reset our saved support
variables
if close > previousSup2 and barstate.isconfirmed
previousSup1 := na
previousSup2 := na
// Draw our current resistance zone
r1 = plot(res1 == res1[1] ? res1 : na, color=close >= res1 ? color.green :
color.red, style=plot.style_linebr, title="R1")
r2 = plot(res1 == res1[1] ? res2 : na, color=close >= res1 ? color.green :
color.red, style=plot.style_linebr, title="R2")
fill(r1, r2, color=close > res1 ? color.green : color.red, transp=50,
title="Resistance Zone")

// Draw our current support zone


s1 = plot(sup1 == sup1[1] ? sup1 : na, color=close < sup1 ? color.red :
color.green, style=plot.style_linebr, title="S1")
s2 = plot(sup1 == sup1[1] ? sup2 : na, color=close < sup1 ? color.red :
color.green, style=plot.style_linebr, title="S2")
fill(s1, s2, color=close < sup1 ? color.red : color.green, transp=50,
title="Support Zone")

// Draw our previous support zone (turned potential resistance)


ps1 = plot(previousSup1 == previousSup1[1] and previousSup1 != sup1 and
drawPreviousStructure ? previousSup1 : na, color=color.red,
style=plot.style_linebr, title="PS1")
ps2 = plot(previousSup1 == previousSup1[1] and previousSup1 != sup1 and
drawPreviousStructure ? previousSup2 : na, color=color.red,
style=plot.style_linebr, title="PS2")
fill(ps1, ps2, color=color.red, transp=10, title="Previous Support Zone")

// Draw our previous resistance zone (turned potential support)


pr1 = plot(previousRes1 == previousRes1[1] and previousRes1 != res1 and
drawPreviousStructure ? previousRes1 : na, color=color.green,
style=plot.style_linebr, title="PR1")
pr2 = plot(previousRes1 == previousRes1[1] and previousRes1 != res1 and
drawPreviousStructure ? previousRes2 : na, color=color.green,
style=plot.style_linebr, title="PR2")
fill(pr1, pr2, color=color.green, transp=10, title="Previous Resistance Zone")

// Check alert conditions


alertResistance = high >= res2
alertSupport = low <= sup2
alertResistanceBO = close >= res1
alertSupportBO = close <= sup1

// Trigger alerts
alertcondition(alertResistance or alertSupport or alertResistanceBO or
alertSupportBO, title="[DSI] Alert!", message="DSI alert for {{ticker}}")
alertcondition(alertResistance, title="[DSI] Resistance Alert", message="Price has
entered current potential resistance zone for {{ticker}}")
alertcondition(alertSupport, title="[DSI] Support Alert", message="Price has
entered current potential support zone for {{ticker}}")
alertcondition(alertResistanceBO, title="[DSI] Resistance Breakout", message="Price
has broken past potential resistance zone for {{ticker}}")
alertcondition(alertSupportBO, title="[DSI] Support Breakout", message="Price has
broken past potential support zone for {{ticker}}")

You might also like