Bovespa Index-Mini Futures

I need to put an "iff" filter to my bot

37
Hi, I'm trying to develop a bot based on some indicators.

So I have this bot based on ATR and SMA. I could figure how to make the bot buy and sell everytime it crosses the ATR.

But what I need to make now is make the bot only buy if the price is above the moving average and cross the ATR or only sell if the price is below the SMA and cross the atr.

the source code is the following



//version=4

strategy(title="UT Bot", overlay = true)
//CREDITS to HPotter for the orginal code. The guy trying to sell this as his own is a scammer lol.
src = close

// Get user input
res = input(title="EMA Timeframe", type=input.resolution, defval="D")
len = input(title="EMA Length", type=input.integer, defval=50)
col = input(title="Color EMA", type=input.bool, defval=true)
smooth = input(title="Smooth", type=input.bool, defval=false)
// Calculate EMA
ema = ema(close, len)
emaSmooth = security(syminfo.tickerid, res, ema, barmerge.gaps_on, barmerge.lookahead_off)
emaStep = security(syminfo.tickerid, res, ema, barmerge.gaps_off, barmerge.lookahead_off)
// Draw EMA
plot(smooth ? emaSmooth : emaStep, color=col ? close > emaStep ? color.green : color.red : color.black, style=plot.style_line, linewidth=2, title="EMA (HTF)")


keyvalue = input(3, title = "Key Vaule. 'This changes the sensitivity'", step = .5)
atrperiod = input(10, title="ATR Period")
xATR = atr(atrperiod)
nLoss = keyvalue * xATR

xATRTrailingStop = 0.0
xATRTrailingStop := iff(src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), src - nLoss),
iff(src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), src + nLoss),
iff(src > nz(xATRTrailingStop[1], 0), src - nLoss, src + nLoss)))

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

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

plot(xATRTrailingStop, color = xcolor, title = "Trailing Stop")
buy = crossover(src,xATRTrailingStop)
sell = crossunder(src,xATRTrailingStop)
barcolor = src > xATRTrailingStop


barcolor(barcolor? color.green:color.red)


strategy.entry("compra", true, when = close > xATRTrailingStop)
strategy.entry("venda", false, when = close < xATRTrailingStop)

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.