3X Hưng
// This source code is subject to the terms of the Mozilla Public License 3.0 at https://mozilla.org/MPL/2.0/
// © thiennarts

//@version=5
indicator('3X', '3X', true,timeframe="30", timeframe_gaps=true, precision=4, max_labels_count=500) 

//------------------------------------------------------------------------------
bool1 = input(true, title='Line S1')
atr1len = input.int(10, minval=1, title='ATR period 1')
multiplier1 = input.float(3, minval=0.1, title='ATR multiplier 1')
bool2 = input(true, title='Line S2')
atr2len = input.int(20, minval=1, title='ATR period 2')
multiplier2 = input.float(5, minval=0.1, title='ATR multiplier 2')
bool3 = input(true, title='Line S3')
atr3len = input.int(30, minval=1, title='ATR period 3')
multiplier3 = input.float(9, minval=0.1, title='ATR multiplier 3')





//------------------------------------------------------------------------------
atr1 = ta.atr(atr1len)
atr2 = ta.atr(atr2len)
atr3 = ta.atr(atr3len)


sma = plot(ta.sma(close, 50), color=color.new(color.white, 0), title='0', display=display.none)
// 1 ------------------------------------------------------------------------------
up_one = hl2 - atr1 * multiplier1
up1_one = up_one[1]
up_one := close[1] > up1_one ? math.max(up_one, up1_one) : up_one
down_one = hl2 + atr1 * multiplier1
down1_one = down_one[1]
down_one := close[1] < down1_one ? math.min(down_one, down1_one) : down_one
trendup_one = ta.crossover(close, down1_one)
trenddown_one = ta.crossunder(close, up1_one)
var trend_one = 0
if trendup_one
    trend_one := 1
    trend_one
if trenddown_one
    trend_one := -1
    trend_one
buysignal1 = trend_one == 1 and trend_one[1] == -1
sellsignal1 = trend_one == -1 and trend_one[1] == 1

greenline1 = plot(trend_one == 1 and bool1 ? up_one : na, style=plot.style_linebr, color=color.new(color.green, 0), linewidth=1, title='S1')
redline1 = plot(trend_one == -1 and bool1 ? down_one : na, style=plot.style_linebr, color=color.new(color.red, 0), linewidth=1, title='S1')
//fill(greenline1, sma, color=color.new(color.green, 90))
//fill(redline1, sma, color=color.new(color.red, 90))
//plotshape(buysignal1 and bool1 ? up_one : na, style=shape.arrowup, location=location.absolute, size=size.tiny, color=color.new(color.green, 0))
//plotshape(sellsignal1 and bool1 ? down_one : na, style=shape.arrowdown, location=location.absolute, size=size.tiny, color=color.new(color.red, 0))
//plotshape(buysignal1 and bool1 ? up_one : na, title='Buy', text='Buy', location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.lime, 0), textcolor=color.new(color.black, 0))
//plotshape(sellsignal1 and bool1 ? down_one : na, title='Sell', text='Sell', location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.new(color.white, 0))


// 2 ------------------------------------------------------------------------------
up_two = hl2 - atr2 * multiplier2
up1_two = up_two[1]
up_two := close[1] > up1_two ? math.max(up_two, up1_two) : up_two
down_two = hl2 + atr2 * multiplier2
down1_two = down_two[1]
down_two := close[1] < down1_two ? math.min(down_two, down1_two) : down_two
trendup_two = ta.crossover(close, down1_two)
trenddown_two = ta.crossunder(close, up1_two)
var trend_two = 0
if trendup_two
    trend_two := 1
    trend_two
if trenddown_two
    trend_two := -1
    trend_two
buysignal2 = trend_two == 1 and trend_two[1] == -1
sellsignal2 = trend_two == -1 and trend_two[1] == 1

greenline2 = plot(trend_two == 1 and bool2 ? up_two : na, style=plot.style_linebr, color=color.new(color.green, 0), linewidth=3, title='S2')
redline2 = plot(trend_two == -1 and bool2 ? down_two : na, style=plot.style_linebr, color=color.new(color.red, 0), linewidth=3, title='S2')
fill(greenline2, sma, color=color.new(color.green, 90))
fill(redline2, sma, color=color.new(color.red, 90))
plotshape(buysignal2 and bool2 ? up_two : na, style=shape.arrowup, location=location.absolute, size=size.tiny, color=color.new(color.green, 0))
plotshape(sellsignal2 and bool2 ? down_two : na, style=shape.arrowdown, location=location.absolute, size=size.tiny, color=color.new(color.red, 0))
// 3 ------------------------------------------------------------------------------
up_Three = hl2 - atr3 * multiplier3
up1_Three = up_Three[1]
up_Three := close[1] > up1_Three ? math.max(up_Three, up1_Three) : up_Three
down_Three = hl2 + atr3 * multiplier3
down1_Three = down_Three[1]
down_Three := close[1] < down1_Three ? math.min(down_Three, down1_Three) : down_Three
trendup_Three = ta.crossover(close, down1_Three)
trenddown_Three = ta.crossunder(close, up1_Three)
var trend_Three = 0
if trendup_Three
    trend_Three := 1
    trend_Three
if trenddown_Three
    trend_Three := -1
    trend_Three
buysignal3 = trend_Three == 1 and trend_Three[1] == -1
sellsignal3 = trend_Three == -1 and trend_Three[1] == 1

greenline3 = plot(trend_Three == 1 and bool3 ? up_Three : na, style=plot.style_linebr, color=color.new(color.green, 0), linewidth=3, title='S3')
redline3 = plot(trend_Three == -1 and bool3 ? down_Three : na, style=plot.style_linebr, color=color.new(color.red, 0), linewidth=3, title='S3')
fill(greenline3, sma, color=color.new(color.green, 90))
fill(redline3, sma, color=color.new(color.red, 90))
plotshape(buysignal3 and bool3 ? up_Three : na, style=shape.arrowup, location=location.absolute, size=size.tiny, color=color.new(color.green, 0))
plotshape(sellsignal3 and bool3 ? down_Three : na, style=shape.arrowdown, location=location.absolute, size=size.tiny, color=color.new(color.red, 0))

alertcondition(buysignal1 or buysignal2 or buysignal3, title='Buy S 123', message='Long Q=0.01')
alertcondition(sellsignal1 or sellsignal2 or sellsignal3, title='Sell S 123', message='Short Q=0.01 ')


