Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
13 views3 pages

NTS

The document is a Pine Script code for a trading indicator called 'NTS (NewStrategy)', which utilizes various technical analysis methods including ATR (Average True Range) and Fibonacci levels. It includes functions for calculating true range, trend detection, and generating alerts based on price movements relative to Fibonacci levels. The script also features a user interface for displaying relevant information such as chart time and ATR parameters.

Uploaded by

abolfazlhosini42
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)
13 views3 pages

NTS

The document is a Pine Script code for a trading indicator called 'NTS (NewStrategy)', which utilizes various technical analysis methods including ATR (Average True Range) and Fibonacci levels. It includes functions for calculating true range, trend detection, and generating alerts based on price movements relative to Fibonacci levels. The script also features a user interface for displaying relevant information such as chart time and ATR parameters.

Uploaded by

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

//@version=5

indicator('NTS (NewStrategy) ',overlay = true)

//---------------------- Engulfing ------------------------------


//barcolor(open[1] > close[1] ? close > open ? close >= open[1] ? close[1] >=
open ? close - open > open[1] - close[1] ? color.yellow :na :na : na : na : na)
//-----------------------------------------------------------------

var timeF = timeframe.period


getResolution(tf) =>
switch tf
'1' => '3'
'3' => '5'
'5' => '15'
'15'=> '30'
'30'=> '45'
'45'=> '60'
'60'=> '120'
'120'=> '180'
'180'=> '240'
'240'=> 'D'
'D'=> 'W'
'W'=> 'M'

var atrP = 10
var atrF = 5

res = getResolution(timeF)

trailType = input.string('modified', 'Trailtype', options=['modified',


'unmodified'])

var int ATRPer = 0


var int ATRFac = 0

if timeF == '45'
ATRPer := 12
ATRFac := 12
else if timeF == '15'
ATRPer := 10
ATRFac := 4
else
ATRPer := 10
ATRFac := 5

manualFts = input.bool(false, title = 'use manual FTS')


ATRPeriod = manualFts ? input.int(15, title = 'ATRPeriod') : ATRPer
ATRFactor = manualFts ? input.int(15, title = 'ATRFactor') : ATRFac

var testTable = table.new(position=position.bottom_left, columns=2, rows=4,


bgcolor=color.new(color.gray,50), border_width=2, border_color=color.black)

if barstate.islast
table.cell(testTable, 0, 0, 'Chart Time',text_color = color.red,text_size =
size.small)
table.cell(testTable, 1, 0, timeF,text_color = color.green,text_size =
size.small)
table.cell(testTable, 0, 1, 'NTS Time',text_color = color.red,text_size =
size.small)
table.cell(testTable, 1, 1, res,text_color = color.green,text_size =
size.small)

table.cell(testTable, 0, 2, 'ATRPeriod',text_color = color.red,text_size =


size.small)
table.cell(testTable, 1, 2, str.tostring(ATRPeriod),text_color =
color.green,text_size = size.small)

table.cell(testTable, 0, 3, 'ATRFactor',text_color = color.red,text_size =


size.small)
table.cell(testTable, 1, 3, str.tostring(ATRFactor),text_color =
color.green,text_size = size.small)

norm_o = request.security(ticker.new(syminfo.prefix, syminfo.ticker), res, open)


norm_h = request.security(ticker.new(syminfo.prefix, syminfo.ticker), res, high)
norm_l = request.security(ticker.new(syminfo.prefix, syminfo.ticker), res, low)
norm_c = request.security(ticker.new(syminfo.prefix, syminfo.ticker), res, close)

Wild_ma(_src, _malength) =>


_wild = 0.0
_wild := nz(_wild[1]) + (_src - nz(_wild[1])) / _malength
_wild

/////////// TRUE RANGE CALCULATIONS /////////////////


HiLo = math.min(norm_h - norm_l, 1.5 * nz(ta.sma(norm_h - norm_l, ATRPeriod)))

HRef = norm_l <= norm_h[1] ? norm_h - norm_c[1] : norm_h - norm_c[1] - 0.5 *


(norm_l - norm_h[1])

LRef = norm_h >= norm_l[1] ? norm_c[1] - norm_l : norm_c[1] - norm_l - 0.5 *


(norm_l[1] - norm_h)

trueRange = trailType == 'modified' ? math.max(HiLo, HRef, LRef) : math.max(norm_h


- norm_l, math.abs(norm_h - norm_c[1]), math.abs(norm_l - norm_c[1]))

loss = ATRFactor * Wild_ma(trueRange, ATRPeriod)

Up = norm_c - loss
Dn = norm_c + loss

TrendUp = Up
TrendDown = Dn
Trend = 1

TrendUp := norm_c[1] > TrendUp[1] ? math.max(Up, TrendUp[1]) : Up


TrendDown := norm_c[1] < TrendDown[1] ? math.min(Dn, TrendDown[1]) : Dn

Trend := norm_c > TrendDown[1] ? 1 : norm_c < TrendUp[1] ? -1 : nz(Trend[1], 1)


trail = Trend == 1 ? TrendUp : TrendDown

ex = 0.0
ex := ta.crossover(Trend, 0) ? norm_h : ta.crossunder(Trend, 0) ? norm_l : Trend ==
1 ? math.max(ex[1], norm_h) : Trend == -1 ? math.min(ex[1], norm_l) : ex[1]

state = Trend == 1 ? 'long' : 'short'


fib1Level = 61.8
fib2Level = 78.6
fib3Level = 88.6

f1 = ex + (trail - ex) * fib1Level / 100


f2 = ex + (trail - ex) * fib2Level / 100
f3 = ex + (trail - ex) * fib3Level / 100
l100 = trail + 0

Fib1 = plot(f1, 'Fib 1', style=plot.style_line, color=color.new(color.gray, 0))


Fib2 = plot(f2, 'Fib 2', style=plot.style_line, color=color.new(color.gray, 0))
Fib3 = plot(f3, 'Fib 3', style=plot.style_line, color=color.new(color.lime, 0))
L100 = plot(l100, 'l100', style=plot.style_line, color=color.rgb(120, 123, 134))

fill(Fib3, L100, color=state == 'long' ? color.new(#00eaff, 12) : state ==


'short' ? #ff5280e9 : na)

changcDir = ta.cross(f3,l100)
alertcondition(changcDir, title="Alert: FTS Direction Change", message="FTS has
changed direction!")

l1 = state[1] == "long" and ta.crossunder(norm_c, f1[1])


l2 = state[1] == "long" and ta.crossunder(norm_c, f2[1])
l3 = state[1] == "long" and ta.crossunder(norm_c, f3[1])
s1 = state[1] == "short" and ta.crossover(norm_c, f1[1])
s2 = state[1] == "short" and ta.crossover(norm_c, f2[1])
s3 = state[1] == "short" and ta.crossover(norm_c, f3[1])

atr = ta.sma(trueRange, 14)

//////////// FIB ALERTS /////////////////////

alertcondition(l1, title = "cross over Fib1", message = "Price crossed below Fib1
level in long trend")
alertcondition(l2, title = "cross over Fib2", message = "Price crossed below Fib2
level in long trend")
alertcondition(l3, title = "cross over Fib3", message = "Price crossed below Fib3
level in long trend")
alertcondition(s1, title = "cross under Fib1", message = "Price crossed above Fib1
level in short trend")
alertcondition(s2, title = "cross under Fib2", message = "Price crossed above Fib2
level in short trend")
alertcondition(s3, title = "cross under Fib3", message = "Price crossed above Fib3
level in short trend")

alertcondition(fixnan(f1)!=fixnan(f1[1]), title = "Stop Line Change", message =


"Stop Line Change")

You might also like