NSDT 2
NSDT 2
0
at https://mozilla.org/MPL/2.0/
// � peppetrombetta
//@version=6
indicator('GOLD', overlay = true)
// == FILTERING ==
// Inputs
useMaFilter = input.bool(title = 'Use MA for Filtering?', defval = true, tooltip =
'Signals will be ignored when price is under this moving average. The intent is to
keep you out of bear periods and only buying when price is showing strength.',
group = 'Breakout Trend Follower')
maType = input.string(defval = 'SMA', options = ['EMA', 'SMA'], title = 'MA Type
For Filtering', group = 'Breakout Trend Follower')
maLength = input.int(defval = 50, title = 'MA Period for Filtering', minval = 1,
group = 'Breakout Trend Follower')
// Check to see if the useMaFilter check box is checked, this then inputs this
conditional "maFilterCheck" variable into the strategy entry
maFilterCheck = if useMaFilter == true
maFilter
else
0
// === PLOT SWING HIGH/LOW AND MOST RECENT LOW TO USE AS STOP LOSS EXIT POINT ===
// Change these values to adjust the look back and look forward periods for your
swing high/low calculations
pvtLenL = 3
pvtLenR = 3
// Count How many candles for current Pivot Level, If new reset.
counthi = ta.barssince(not na(pvthi))
countlo = ta.barssince(not na(pvtlo))
pvthis = fixnan(pvthi)
pvtlos = fixnan(pvtlo)
hipc = ta.change(pvthis) != 0 ? na : color.maroon
lopc = ta.change(pvtlos) != 0 ? na : color.green
// Stop Levels
stopLevel = ta.valuewhen(bool(pvtlo_), low[pvtLenR], 0) //Stop Level at Swing Low
plot(stopLevel, style = plot.style_line, color = color.new(color.orange, 50),
show_last = 1, linewidth = 1, trackprice = true)
buyLevel = ta.valuewhen(bool(pvthi_), high[pvtLenR], 0) //Buy level at Swing High
plot(buyLevel, style = plot.style_line, color = color.new(color.blue, 50),
show_last = 1, linewidth = 1, trackprice = true)
// // Color background when trade active (for easier visual on what charts are OK
to enter on)
// tradeBackground = input(title="Color Background for Trades?", type=input.bool,
defval=true)
// tradeBackgroundColor = tradeBackground and inPosition ? #00FF00 : na
// bgcolor(tradeBackgroundColor, transp=95)
// noTradeBackgroundColor = tradeBackground and flat ? #FF0000 : na
// bgcolor(noTradeBackgroundColor, transp=90)
// // A switch to control background coloring of the test period - Use for easy
visualization of backtest range and manual calculation of
// // buy and hold (via measurement) if doing prior periods since value in Strategy
Tester extends to current date by default
// testPeriodBackground = input(title="Color Background - Test Period?",
type=input.bool, defval=false)
// testPeriodBackgroundColor = testPeriodBackground and (time >= Start) and (time
<= Finish) ? #00FF00 : na
// bgcolor(testPeriodBackgroundColor, transp=95)
di = 25 + DIPlus - DIMinus
//vam=sma(1.2*(ADX-ADX[len]),3)+25
//vad=(vam+2*vam[1]+2*vam[2]+vam[3])/6
cy = di >= 25
// //plot(DIPlus, color=lime,linewidth=2, title="DI+")
// //plot(DIMinus, color=red, linewidth=2,title="DI-")
// plot(ADX, color=color.orange, linewidth=1, transp=0, title="ADX")
// //plot(vam,title="velocita",linewidth=1,transp=50,color=lime)
// plot(di, style=plot.style_histogram, linewidth=4, color=cy, transp=50,
histbase=25, title="DI")
// hline(th, color=color.gray)
//HAMA
//The follow gradient code is taken from the Pinecoders Gradient Framework example.
//https://www.tradingview.com/script/hqH4YIFa-Color-Gradient-Framework-PineCoders/
//Pro Advance/Decline Gradient
////////////////////
//GRADIENT AREA
////////////////////
f_c_gradientAdvDecPro(_source, _center, _steps, _c_bearWeak, _c_bearStrong,
_c_bullWeak, _c_bullStrong) =>
var float _qtyAdvDec = 0.
var float _maxSteps = math.max(1, _steps)
bool _xUp = ta.crossover(_source, _center)
bool _xDn = ta.crossunder(_source, _center)
float _chg = ta.change(_source)
bool _up = _chg > 0
bool _dn = _chg < 0
bool _srcBull = _source > _center
bool _srcBear = _source < _center
_qtyAdvDec := _srcBull ? _xUp ? 1 : _up ? math.min(_maxSteps, _qtyAdvDec + 1) :
_dn ? math.max(1, _qtyAdvDec - 1) : _qtyAdvDec : _srcBear ? _xDn ? 1 : _dn ?
math.min(_maxSteps, _qtyAdvDec + 1) : _up ? math.max(1, _qtyAdvDec - 1) :
_qtyAdvDec : _qtyAdvDec
var color _return = na
_return := _srcBull ? color.from_gradient(_qtyAdvDec, 1, _maxSteps,
_c_bullWeak, _c_bullStrong) : _srcBear ? color.from_gradient(_qtyAdvDec, 1,
_maxSteps, _c_bearWeak, _c_bearStrong) : _return
_return
//MA TYPES
mat(source, length, type) =>
type == 'SMA' ? ta.sma(source, length) : type == 'EMA' ? ta.ema(source, length)
: type == 'RMA' ? ta.rma(source, length) : type == 'WMA' ? ta.wma(source, length) :
type == 'VWMA' ? ta.vwma(source, length) : type == 'HMA' ? ta.hma(source, length) :
type == 'TMA' ? ta.sma(ta.sma(source, length), length) : na
//INPUTS
bull =color.rgb(0, 255, 0) //input(color.rgb(0, 255, 0), title='Bull Color')
bear = color.rgb(255, 0, 0)//input(color.rgb(255, 0, 0), title='Bear Color')
neutral = color.rgb(255, 255, 0, 0)//input(, title='Neutral Color')
show_ma = true
ma_type = 'WMA'
ma_source = close
ma_length = 55
UseGradient =true// input(true, title='Use Gradient Colors')
stepn =5// input(5, title='Max Gradient Steps')
ma = mat(ma_source, ma_length, ma_type)
col = f_c_gradientAdvDecPro(ma, ta.ema(ma, 3), stepn, neutral, bear, neutral, bull)
alertcondition(long, 'Buy')
alertcondition(short, 'Sell')