OPEN-SOURCE SCRIPT

Humble idrees Candles

199
//version=5
indicator(title="Humble LinReg Candles", shorttitle="41-80-LinReg Candles", format=format.price, precision=4, overlay=true)

signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 200, defval = 11)
sma_signal = input.bool(title="Simple MA (Signal Line)", defval=true)

lin_reg = input.bool(title="Lin Reg", defval=true)
linreg_length = input.int(title="Linear Regression Length", minval = 1, maxval = 200, defval = 11)

bopen = lin_reg ? ta.linreg(open, linreg_length, 0) : open
bhigh = lin_reg ? ta.linreg(high, linreg_length, 0) : high
blow = lin_reg ? ta.linreg(low, linreg_length, 0) : low
bclose = lin_reg ? ta.linreg(close, linreg_length, 0) : close

r = bopen < bclose

signal = sma_signal ? ta.sma(bclose, signal_length) : ta.ema(bclose, signal_length)

//plotcandle(r ? bopen : na, r ? bhigh : na, r ? blow: na, r ? bclose : na, title="LinReg Candles", color= color.green, wickcolor=color.green, bordercolor=color.green, editable= true)
//plotcandle(r ? na : bopen, r ? na : bhigh, r ? na : blow, r ? na : bclose, title="LinReg Candles", color=color.red, wickcolor=color.red, bordercolor=color.red, editable= true)

plot(signal, color=color.black)

// Inputs
a = input(1, title='Key Vaule. \'This changes the sensitivity\'')
c = input(10, title='ATR Period')
h = input(false, title='Signals from Heikin Ashi Candles')

xATR = ta.atr(c)
nLoss = a * xATR

src = h ? request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close, lookahead=barmerge.lookahead_off) : close

xATRTrailingStop = 0.0
iff_1 = src > nz(xATRTrailingStop[1], 0) ? src - nLoss : src + nLoss
iff_2 = src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0) ? math.min(nz(xATRTrailingStop[1]), src + nLoss) : iff_1
xATRTrailingStop := src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0) ? math.max(nz(xATRTrailingStop[1]), src - nLoss) : iff_2

pos = 0
iff_3 = src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0) ? -1 : nz(pos[1], 0)
pos := src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0) ? 1 : iff_3

xcolor = pos == -1 ? color.red : pos == 1 ? color.green : color.blue

ema = ta.ema(src, 1)
above = ta.crossover(ema, xATRTrailingStop)
below = ta.crossover(xATRTrailingStop, ema)

buy = src > xATRTrailingStop and above
sell = src < xATRTrailingStop and below

barbuy = src > xATRTrailingStop
barsell = src < xATRTrailingStop

plotshape(buy, title='Buy', text='Buy', style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.white, 0), size=size.tiny)
plotshape(sell, title='Sell', text='Sell', style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.white, 0), size=size.tiny)

barcolor(barbuy ? color.green : na)
barcolor(barsell ? color.red : na)

alertcondition(buy, 'UT Long', 'UT Long')
alertcondition(sell, 'UT Short', 'UT Short')

longCondition = buy
shortCondition = sell

gpA = "PineConnector Settings"
LicenseID = input.string("xxxxxxxx", title = "License ID", group=gpA) // 1. change to your PineConnector License ID (required)
pairName = input.string("XAUUSD", title = "Pair Name to Trade", tooltip = "Confirm exact name from MT5 before entering", group=gpA)
risk_ = input.float(10, "Risk [Lots]", group = gpA)
sl_ = input.float(30, "SL [Pips]", group = gpA)
tp_ = input.float(30, "TP [Pips]     ", group = gpA, inline = "tp_"), use_tp = input.bool(false, "Enable", group = gpA, inline = "tp_")

entryAlertMessage(side_,risk, sl, tp)=>
LicenseID + ',' + side_ + ',' + pairName + ',risk=' + str.tostring(risk) + ',sl=' + str.tostring(sl, "#.####") + (use_tp ? ',tp=' + str.tostring(tp, "#.####") : "")
closeAlertMessage(side_)=>
LicenseID +',' + side_ + ',' + pairName

if longCondition
alertMessage = entryAlertMessage("buy", risk_, sl_, tp_)
alert(alertMessage, alert.freq_once_per_bar_close)
// label.new(bar_index, high, alertMessage, xloc.bar_index, yloc.price, color.green, label.style_label_down, color.white, size.small, text.align_left, na, font.family_monospace, force_overlay = true)

if shortCondition
alertMessage = entryAlertMessage("sell", risk_, sl_, tp_)
alert(alertMessage, alert.freq_once_per_bar_close)



Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.