You are on page 1of 4

// Get Components

ocAvg = math.avg(open, close)


sma1 = ta.sma(close, 8)
sma2 = ta.sma(close, 9)
sma3 = ta.sma(close, 10)
sma4 = ta.sma(close, 11)
sma5 = ta.sma(close, 12)
sma6 = ta.sma(close, 13)
sma7 = ta.sma(close, 14)
sma8 = ta.sma(close, 15)
sma9 = ta.sma(close, 15)

// --- CONSTANTS ---


DodgerRed = #3cff00

// === /INPUTS ===


// Constants colours that include fully non-transparent option.
green100 = #00FF00FF
lime100 = #00FF00FF
red100 = #FF0000FF
blue100 = color.rgb(89, 0, 255)
aqua100 = color.rgb(89, 0, 255)
darkred100 = #FF0000FF

//@version=5
indicator("NAS Simple TradinG"
, overlay = true
, max_labels_count = 500
, max_lines_count = 500
, max_boxes_count = 500
, max_bars_back = 500)

// Get user input


sensitivity = input.int(defval=6, title="Sensitivity", minval=1, maxval=20)

enCloud = input.bool(true, 'Enable Trend Ribbon', group='Cloud')


// Risk Management

levels = input.bool(true, "Show TP/SL Levels" , group = "Risk Management" ,


inline = "MMDB2")
lvlLines = input.bool(true, "Show Lines ", inline="levels", group = "Risk
Management")
linesStyle = input.string("SOLID", "", ["SOLID", "DASHED", "DOTTED"],
inline="levels", group = "Risk Management")
lvlDistance = input.int(1, "Distance", 1, inline="levels2", group = "Risk
Management")
lvlDecimals = input.int(2, " Decimals", 1, 8, inline="levels2", group = "Risk
Management")
atrRisk = input.int(1, "Risk % ", 1, group = "Risk Management" ,
inline="levels3")
atrLen = input.int(14, " ATR Length", 1, group = "Risk Management" ,
inline="levels3")
decimals = lvlDecimals == 1 ? "#.#" : lvlDecimals == 2 ? "#.##" : lvlDecimals == 3
? "#.###" : lvlDecimals == 4 ? "#.####" : lvlDecimals == 5 ? "#.#####" :
lvlDecimals == 6 ? "#.######" : lvlDecimals == 7 ? "#.#######" : "#.########"

// Signal Generation
supertrend(_src, factor, atrLen) =>
atr = ta.atr(atrLen)
upperBand = _src + factor * atr
lowerBand = _src - factor * atr
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ?
lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ?
upperBand : prevUpperBand
int direction = na
float superTrend = na
prevSuperTrend = superTrend[1]
if na(atr[1])
direction := 1
else if prevSuperTrend == prevUpperBand
direction := close > upperBand ? -1 : 1
else
direction := close < lowerBand ? 1 : -1
superTrend := direction == -1 ? lowerBand : upperBand
[superTrend, direction]

// SMA

//*in Easy Words Super Trend + SMA = Signals


[supertrend, direction] = supertrend(close, sensitivity, 11)

source = close, period = 150

// Colors
green = #2BBC4D, green2 = #00DD00
red = #C51D0B, red2 = #DD0000

// High Lows
y1 = low - (ta.atr(30) * 2), y1B = low - ta.atr(30)
y2 = high + (ta.atr(30) * 2), y2B = high + ta.atr(30)
bull = ta.crossover(close, supertrend) and close >= sma9
bear = ta.crossunder(close, supertrend) and close <= sma9

// Plots

// ---------------------------- Fast ---------------------------- \\


candle = ta.sma(close, 21)
reach = ta.sma(close, 34)
candlep = plot(enCloud ? candle : na, color=color.new(color.white, 100))
reachp = plot(enCloud ? reach : na, color=color.new(color.white, 100))
fill(reachp, candlep, color= candle > reach ? color.new(#0099cc, 75) :
color.new(#ccc900, 75))

buy = bull ? label.new(bar_index, y1, sma4 >= sma5 ? "Long 😄" : "Long 😄",
xloc.bar_index, yloc.price, #00CC00, label.style_label_up, #141923, size.normal) :
na
sell = bear ? label.new(bar_index, y2, sma4 <= sma5 ? "Short 😄" : "Short 😄",
xloc.bar_index, yloc.price, #CC0000, label.style_label_down, color.white,
size.normal) : na

trigger2 = bull ? 1 : 0
countBull = ta.barssince(bull)
countBear = ta.barssince(bear)
trigger = nz(countBull, bar_index) < nz(countBear, bar_index) ? 1 : 0
atrBand = ta.atr(atrLen) * atrRisk
atrStop = trigger == 1 ? low - atrBand : high + atrBand

lastTrade(src) => ta.valuewhen(bull or bear , src, 0)

entry = levels ? label.new(time, close, "ENTRY " + str.tostring(lastTrade(close),


decimals), xloc.bar_time, yloc.price, color.rgb(255, 255, 255),
label.style_label_left, color.rgb(0, 0, 0), size.normal) : na
label.set_x(entry, label.get_x(entry) + math.round(ta.change(time) * lvlDistance))
label.set_y(entry, lastTrade(close))
label.delete(entry[1])

stop_y = lastTrade(atrStop)
stop = levels ? label.new(time, close, "SL " + str.tostring(stop_y, decimals),
xloc.bar_time, yloc.price, red2, label.style_label_left, color.white,
size.normal) : na
label.set_x(stop, label.get_x(stop) + math.round(ta.change(time) * lvlDistance))
label.set_y(stop, stop_y)
label.delete(stop[1])

tp1Rl_y = (lastTrade(close)-lastTrade(atrStop))*1 + lastTrade(close)


tp1Rl = levels ? label.new(time, close, "TP 1 🎱 " + str.tostring(tp1Rl_y,
decimals), xloc.bar_time, yloc.price, green2, label.style_label_left, color.rgb(0,
0, 0), size.normal ) : na
label.set_x(tp1Rl, label.get_x(tp1Rl) + math.round(ta.change(time) * lvlDistance))
label.set_y(tp1Rl, tp1Rl_y)
label.delete(tp1Rl[1])
tp2RL_y = (lastTrade(close)-lastTrade(atrStop))*2 + lastTrade(close)
tp2RL = levels ? label.new(time, close, "TP 2 🎱 " + str.tostring(tp2RL_y,
decimals), xloc.bar_time, yloc.price, green2, label.style_label_left, color.rgb(0,
0, 0), size.normal) : na
label.set_x(tp2RL, label.get_x(tp2RL) + math.round(ta.change(time) * lvlDistance))
label.set_y(tp2RL, tp2RL_y)
label.delete(tp2RL[1])

tp3RL_y = (lastTrade(close)-lastTrade(atrStop))*3 + lastTrade(close)


tp3RL = levels ? label.new(time, close, "TP 3 🎱 " + str.tostring(tp3RL_y,
decimals), xloc.bar_time, yloc.price, green2, label.style_label_left, color.rgb(0,
0, 0), size.normal) : na
label.set_x(tp3RL, label.get_x(tp3RL) + math.round(ta.change(time) * lvlDistance))
label.set_y(tp3RL, tp3RL_y)
label.delete(tp3RL[1])

style = linesStyle == "SOLID" ? line.style_solid : linesStyle == "DASHED" ?


line.style_dashed : line.style_dotted
lineEntry = levels and lvlLines ? line.new(bar_index - (trigger == 0 ? countBull :
countBear), lastTrade(close), bar_index + lvlDistance, lastTrade(close),
xloc.bar_index, extend.none, color.rgb(0, 255, 251), style, 2) : na,
line.delete(lineEntry[1])
lineStop = levels and lvlLines ? line.new(bar_index - (trigger == 0 ? countBull :
countBear), stop_y, bar_index + lvlDistance, stop_y, xloc.bar_index, extend.none,
#CC0000, style, 2) : na, line.delete(lineStop[1])
lineTp1Rl = levels and lvlLines ? line.new(bar_index - (trigger == 0 ?
countBull : countBear), tp1Rl_y, bar_index + lvlDistance, tp1Rl_y, xloc.bar_index,
extend.none, green2, style, 2) : na, line.delete(lineTp1Rl[1])
lineTp2RL = levels and lvlLines ? line.new(bar_index - (trigger == 0 ?
countBull : countBear), tp2RL_y, bar_index + lvlDistance, tp2RL_y, xloc.bar_index,
extend.none, green2, style, 2) : na, line.delete(lineTp2RL[1])
lineTp3RL = levels and lvlLines ? line.new(bar_index - (trigger == 0 ?
countBull : countBear), tp3RL_y, bar_index + lvlDistance, tp3RL_y, xloc.bar_index,
extend.none, green2, style, 2) : na, line.delete(lineTp3RL[1])

alertcondition(bull, title='Buy Signal', message = "BUY")


alertcondition(bear, title='Buy Signal', message = "BUY")

import protradingart/pta_plot/6 as pp
pp.peakprofit(bull, bear)

You might also like