Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
2.8 kB
69
Indexable
Never
//@version=5
indicator("YYY for future",overlay=true)

// Inputs 
factor = input.int(5, "factor")
atrPeriod = input.int(5, "atrPeriod")
wma=input.int(30)

len = int(20)
vlen = int(20)
threshold = float(2)
trnd = bool(true)
green = color(#00ffbb)
red = color(#ff1100)
var hstore = 0.0
var lstore = 0.0
leftBars  = 2
rightBars = 1
prec      = 2


hma = ta.hma(close, 30)
rvol = volume/ta.sma(volume, vlen)
strongvol = rvol > threshold

sh = ta.wma(high, 20)
sl = ta.wma(low, 20)
h = ta.highest(sh, 20)
l = ta.lowest(sl, wma)

if  (h[1] < h[2] or h[1] > h[2])
    hstore := h[2]
if  (l[1] < l[2] or l[1] > l[2])
    lstore := l[2]

candledir = close > open ? 1 : -1

var bullishrej = bool(na)
var bearishrej = bool(na)

var state = 0.0
 
breakout = candledir == 1 and close > hstore and open < hstore
breakdown = candledir == -1 and close < lstore and open > lstore
bullishrej := (low < lstore and close > lstore) and not (bullishrej[1] or bullishrej[2] or bullishrej[3] or bullishrej[4]) 
bearishrej := (high > hstore and close < hstore) and not (bearishrej[1] or bearishrej[2] or bearishrej[3] or bearishrej[4])

if (ta.crossover(low, lstore) and state == -1) or (ta.crossunder(high, hstore) and state == 1)
    state := 0
dip_igne=(bullishrej and not (state ==- 1) ? low * 0.9995 :na)
ust=(bearishrej and not (state == 1) ? high * 1.0005 : na)
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
plot(direction < 0 ? supertrend : na, "Up direction", color = color.green, style=plot.style_linebr)
// The same on Pine Script
pine_supertrend(factor, atrPeriod) =>
    src = hl2
    atr = ta.atr(atrPeriod)
    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]

[Pine_Supertrend, pineDirection] = pine_supertrend(factor, atrPeriod)
Buy = (bool(dip_igne)  and pineDirection < 0) 
Sell = pineDirection > 0 and pineDirection[1] < 0
plotshape(Buy,"BUY",shape.triangleup, location.belowbar, color.new(green, 0), size = size.tiny, text = "BUY", textcolor = color.gray)
plotshape(Sell, "SELL", shape.triangledown, location.abovebar, color.new(red, 0), size = size.tiny, text = "SELL", textcolor = color.gray)
Leave a Comment