Stocks Algo
Stocks Algo
0
at https://mozilla.org/MPL/2.0/
// © World_of_Indicators
//@version=5
indicator('Stocks Algo', shorttitle='Stocks Algo', overlay=true)
// Input settings
var string calcGroup = 'Calculation'
length = input.int(title='ATR Period', defval=22, group=calcGroup)
mult = input.float(title='ATR Multiplier', step=0.1, defval=3.0, group=calcGroup)
useClose = input.bool(title='Use Close Price for Extremums', defval=true,
group=calcGroup)
// Calculation
atr = mult * ta.atr(length)
longStop = (useClose ? ta.highest(close, length) : ta.highest(length)) - atr
longStopPrev = nz(longStop[1], longStop)
longStop := close[1] > longStopPrev ? math.max(longStop, longStopPrev) : longStop
// Colors
var color longColor = color.green
var color shortColor = color.red
var color textColor = color.new(color.white, 0)
// Buy/Sell signals
buySignal = dir == 1 and dir[1] == -1
sellSignal = dir == -1 and dir[1] == 1
if (buySignal or sellSignal)
f_delete_labels_and_lines()
if (buySignal)
buySignalLabel := label.new(x=bar_index, y=high, text='Buy Entry',
style=label.style_label_up, color=color.new(longColor, 0), textcolor=textColor)
entryPrice = high
stoplossPrice = entryPrice - atr * 0.5
target1Price = entryPrice + atr
target2Price = entryPrice + atr * 1.5
target3Price = entryPrice + atr * 2
if (sellSignal)
sellSignalLabel := label.new(x=bar_index, y=low, text='Sell Entry',
style=label.style_label_down, color=color.new(shortColor, 0), textcolor=textColor)
entryPrice = low
stoplossPrice = entryPrice + atr * 0.5
target1Price = entryPrice - atr
target2Price = entryPrice - atr * 1.5
target3Price = entryPrice - atr * 2
// Alerts
await = awaitBarConfirmation ? barstate.isconfirmed : true
alertcondition(dir != dir[1] and await, title='Alert: SA Direction Change',
message='Stocks Algo has changed direction!')
alertcondition(buySignal and await, title='Alert: SA Buy', message='Stocks Algo
Buy!')
alertcondition(sellSignal and await, title='Alert: SA Sell', message='Stocks Algo
Sell!')