0% found this document useful (0 votes)
60 views4 pages

2

The document is a Pine Script code for a trading indicator that provides signals and overlays based on various moving average and Average True Range (ATR) calculations. It includes customizable parameters for sensitivity, trend calculation types, and multi-timeframe settings. The script also features signal detection for buy and sell opportunities, along with visual indicators on a trading chart.

Uploaded by

h.ermenkov
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)
60 views4 pages

2

The document is a Pine Script code for a trading indicator that provides signals and overlays based on various moving average and Average True Range (ATR) calculations. It includes customizable parameters for sensitivity, trend calculation types, and multi-timeframe settings. The script also features signal detection for buy and sell opportunities, along with visual indicators on a trading chart.

Uploaded by

h.ermenkov
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/ 4

//@version=5

indicator('Signals & Overlay Similar', overlay=true, max_labels_count =500)


atrMulti = input.float(3.5, 'Signal Sensitivity', minval=0.1,
step=0.2,group='Sensitivity')

//sensitivity
atrPeriod = input.int (100, 'Smoothing', minval=1, group='Deep Sensitivity')
maPeriod = input.int (6, 'Reactivity', minval=1, group='Deep Sensitivity')
strongest = input(200, title = 'Strong Signal Strength', group='DeepSensitivity')
trendType = input.string('Trailing', 'Trend Calculation Type',options=['Flexible',
'Trailing'], group='Deep Sensitivity')
maType = input.string('SMA', 'Signals Calculation Type', options=['SMA','EMA',
'SMMA', 'LWMA', 'DEMA', 'TEMA', 'HMA', 'LSMA', 'RMA', 'T3'],
group='DeepSensitivity')

sigs = input(true, 'Signal', group='Overlay Future')


lines = input(false, 'Signal Line', group='Overlay Future')
extend = input(false, 'Reverse Signal Count', group='Overlay Future')

confalert = input.string("Off", "Alert Connect", ["Active", "Off"],group="Alert")


alert2 = input.string("Buy Signal", "Signals Alert", ["Buy Signal", "Sell
Signal"],group = "Alert")

// Multi Time Frame Input


mtfResolution = input.timeframe('240', title='Multi-Timeframe
Resolution',group='MTF Settings')

// Main Sensitivity
atrMultiq = input.float(3.5, 'MTF Signal Sensitivity', minval=0.1,
step=0.2,group='MTF Sensitivity')

// Sensitivity
atrPeriodq = input.int (100, 'MTF Smoothing', minval=1, group='MTF
DeepSensitivity')
maPeriodq = input.int (6, 'MTF Reactivity', minval=1, group='MTF DeepSensitivity')
trendTypeq = input.string('Trailing', 'MTF Trend Calculation
Type',options=['Flexible', 'Trailing'], group='MTF Deep Sensitivity')
maTypeq = input.string('SMA', 'Signals Calculation Type', options=['SMA','EMA',
'SMMA', 'LWMA', 'DEMA', 'TEMA', 'HMA', 'LSMA', 'RMA', 'T3'], group='MTF
DeepSensitivity')

// Overlay
sigsq = input(true, 'Multi-Timeframe Signal', group='MTF Overlay Future')
linesq = input(false, 'Multi-Timeframe Signal Line', group='MTF OverlayFuture')

// Helper Functions
ma2(t, sourceq, lengthq) =>maTypeq == 'HMA' ? ta.hma(sourceq, lengthq) :maTypeq
=='EMA' ? ta.ema(sourceq, lengthq) :maTypeq == 'RMA' ?
ta.rma(sourceq,lengthq) :maTypeq == 'SMA' ? ta.sma(sourceq, lengthq) :na
// Moving Averages and ATR Calculations
[maHighq, maLowq] = request.security(syminfo.tickerid, mtfResolution,
[ma2(maTypeq,high, maPeriodq), ma2(maTypeq, low, maPeriodq)])

atrq = request.security(syminfo.tickerid, mtfResolution, ta.atr(atrPeriodq))


*atrMultiq

// Trend Calculations
minLowq = maLowq - atrq
var float upTrendq = na
upTrendq := trendTypeq == 'Flexible' ? minLowq : close[1] > nz(upTrendq[1],minLowq)
? math.max(minLowq, nz(upTrendq[1], minLowq)) : minLowq
plusHighq = maHighq + atrq
var float downTrendq = na
downTrendq := trendTypeq == 'Flexible' ? plusHighq : close[1] <
nz(downTrendq[1],plusHighq) ? math.min(plusHighq, nz(downTrendq[1], plusHighq)) :
plusHighq

var upq = 1
upq := upq != 1 and close > (downTrendq) ? 1 : upq == 1 and close < upTrendq ? -
1 :upq
var downq = 1
downq := downq != 1 and close < (upTrendq) ? 1 : downq == 1 and close >downTrendq ?
-1 : downq

plotSource = plot(close, editable=false, display=display.none)

// Signal Detection
startUpq = upq != upq[1] and upq == 1
plotUpq = plot(upq == 1 and linesq ? upTrendq : na, 'Up', #00ff2a,
1,plot.style_linebr)

startDownq = downq != downq[1] and downq == 1


plotDownq = plot(downq == 1 and linesq ? downTrendq : na, 'Down', #ff0303,
1,plot.style_linebr)
plotshape(startDownq and sigsq ? downTrendq : na,
text='Strong',style=shape.labeldown, location=location.abovebar,
color=color.red,textcolor=color.white, size=size.normal)
plotshape(startUpq and sigsq ? upTrendq : na, text='Strong',
style=shape.labelup,location=location.belowbar, color=color.green,
textcolor=color.white,size=size.normal)
//
//Inputs and Parameters
//Main Sensitivity
// Helper Functions
randwatermark = math.round(math.random(1,3,6))
smma(source, length) =>
var float smma = na
smma := na(smma[1]) ? ta.sma(source, length) : (smma[1] * (length - 1) +
source) / length
smma

lwma(source, length) =>


norm = length * (length + 1) / 2
sum = 0.0
for i = 0 to length - 1
sum := sum + source[i] * (length - i)
sum / norm

dema(source, length) =>


ema1 = ta.ema(source, length)
ema2 = ta.ema(ema1, length)
2 * ema1 - ema2

tema(source, length) =>


ema1 = ta.ema(source, length)
ema2 = ta.ema(ema1, length)
ema3 = ta.ema(ema2, length)
3 * (ema1 - ema2) + ema3

t3(source, length) =>


e1 = ta.ema(source, length)
e2 = ta.ema(e1, length)
e3 = ta.ema(e2, length)
e4 = ta.ema(e3, length)
e5 = ta.ema(e4, length)
e6 = ta.ema(e5, length)
c1 = -0.7 * 0.7 * 0.7
c2 = 3 * 0.7 * 0.7 + 3 * 0.7 * 0.7 * 0.7
c3 = -6 * 0.7 * 0.7 - 3 * 0.7 - 3 * 0.7 * 0.7 * 0.7
c4 = 1 + 3 * 0.7 + 3 * 0.7 * 0.7 + 0.7 * 0.7 * 0.7
t3 = c1 * e6 + c2 * e5 + c3 * e4 + c4 * e3
t3

ma(t, source, length) =>


maType == 'HMA' ? ta.sma(source, length) : maType == 'EMA' ?
ta.ema(source,length) : maType == 'HMA' ? ta.hma(source, length) : maType ==
'RMA' ?ta.rma(source, length) : maType == 'SMA' ? ta.sma(source, length) : maType
=='SMMA' ? smma(source, length) : maType == 'LWMA' ? lwma(source, length) : maType
=='DEMA' ? dema(source, length) : maType == 'TEMA' ? tema(source, length) : maType
=='LSMA' ? ta.linreg(source, length, 0) : maType == 'T3' ? t3(source, length) : na

// Moving Averages and ATR Calculations


maHigh = ma(maType, high, maPeriod)
maLow = ma(maType, low, maPeriod)
atr = ta.atr(atrPeriod) * atrMulti

// Trend Calculations
minLow = maLow - atr
var float upTrend = na
upTrend := trendType == 'Flexible' ? minLow : close[1] > nz(upTrend[1], minLow) ?
math.max(minLow, nz(upTrend[1], minLow)) : minLow

minHigh = maHigh - atr


var float upRange = na
upRange := trendType == 'Flexible' ? minHigh : close[1] > nz(upRange[1], minHigh) ?
math.max(minHigh, nz(upRange[1], minHigh)) : minHigh

plusHigh = maHigh + atr

var float downTrend = na


downTrend := trendType == 'Flexible' ? plusHigh : close[1] <
nz(downTrend[1],plusHigh) ? math.min(plusHigh, nz(downTrend[1], plusHigh)) :
plusHigh

plusLow = maLow + atr


var float downRange = na
downRange := trendType == 'Flexible' ? plusLow : close[1] <
nz(downRange[1],plusLow) ? math.min(plusLow, nz(downRange[1], plusLow)) : plusLow

var up = 1
up := up != 1 and close > (downTrend) ? 1 : up == 1 and close < upTrend ? -1 : up

var down = 1
down := down != 1 and close < (upTrend) ? 1 : down == 1 and close > downTrend ? -
1 : down

// Signal Detection
startUp = up != up[1] and up == 1
plotUp = plot(up == 1 and lines ? upTrend : na, 'Up', #00ff2a, 1,plot.style_linebr)

startDown = down != down[1] and down == 1


plotDown = plot(down == 1 and lines ? downTrend : na, 'Down', #ff0303,
1,plot.style_linebr)

label upLabel = na
var label downLabel = na

if (up)
if (not na(upLabel))
label.delete(upLabel)
upLabel := label.new(bar_index, up == 1 and extend ? upTrend : na, "Reversal
ToSell: " + str.tostring(upTrend, "#.##"),
color=color.red,style=label.style_label_left, textcolor=#ffffff)
if (down)
if (not na(downLabel))
label.delete(downLabel)
downLabel := label.new(bar_index, down == 1 and extend ? downTrend :
na,"Reversal To Buy: " + str.tostring(downTrend, "#.##"),
color=color.green,style=label.style_label_left, textcolor=#ffffff)
// EMA 200 for Signal Differentiation
ema200 = ta.ema(close, strongest)

plotshape(startDown and sigs and close < ema200 ? downTrend : na,


text='S+',style=shape.labeldown, location=location.abovebar,
color=color.red,textcolor=#ffffff, size=size.normal)

plotshape(startDown and sigs and close >= ema200 ? downTrend : na,


text='S',style=shape.labeldown, location=location.abovebar,
color=color.red,textcolor=#ffffff, size=size.normal)

plotshape(startUp and sigs and close > ema200 ? upTrend : na,


text='B+',style=shape.labelup, location=location.belowbar,
color=color.green,textcolor=#ffffff, size=size.normal)

plotshape(startUp and sigs and close <= ema200 ? upTrend : na,


text='B',style=shape.labelup, location=location.belowbar,
color=color.green,textcolor=#ffffff, size=size.normal)

// Bar color based on strong signal conditionsbarcolor(upq == 1 ? #00ff08 : na)


barcolor(downq ? #ff0000 : na)

You might also like