Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- study(title="[LamBOTguini][ALERTa2]", overlay = true)
- // EMA 1
- src0 = input(hlc3, "Source EMA 1", type = source), len0 = input(3, minval=1, title = "Lenght EMA 1")
- ema01 = ema(src0, len0)
- direction = rising(ema01, 2) ? +1 : falling(ema01, 2) ? -1 : 0
- plot_color = direction > 0 ? lime: direction < 0 ? red : na
- pema01 = plot(ema01, title="EMA 1", style=line, linewidth=1, color = plot_color)
- // EMA 2
- src02 = input(hlc3, "Source EMA 2", type = source), len02 = input(8, minval=1, title = "Lenght EMA 2")
- ema02 = ema(src02, len02)
- direction2 = rising(ema02, 2) ? +1 : falling(ema02, 2) ? -1 : 0
- plot_color2 = direction2 > 0 ? lime: direction2 < 0 ? red : na
- plot(ema02, title="EMA 2", style=line, linewidth=1, color = plot_color2)
- // EMA 3
- src03 = input(hlc3, "Source EMA 3", type = source), len03 = input(13, minval=1, title = "Lenght EMA 3")
- ema03 = ema(src03, len03)
- direction3 = rising(ema03, 2) ? +1 : falling(ema03, 2) ? -1 : 0
- plot_color3 = direction3 > 0 ? lime: direction3 < 0 ? red : na
- pema03 = plot(ema03, title="EMA 3", style=line, linewidth=1, color = plot_color3)
- fill(pema01, pema03, color = ema01 > ema03 ? lime : red, editable = false)
- // RSI Divergence
- src_fast = hlc3, len_fast = input(5, minval=1, title="Length Fast RSI")
- src_slow = hlc3, len_slow = input(15,minval=1, title="Length Slow RSI")
- up_fast = rma(max(change(src_fast), 0), len_fast)
- down_fast = rma(-min(change(src_fast), 0), len_fast)
- rsi_fast = down_fast == 0 ? 100 : up_fast == 0 ? 0 : 100 - (100 / (1 + up_fast / down_fast))
- up_slow = rma(max(change(src_slow), 0), len_slow)
- down_slow = rma(-min(change(src_slow), 0), len_slow)
- rsi_slow = down_slow == 0 ? 100 : up_slow == 0 ? 0 : 100 - (100 / (1 + up_slow / down_slow))
- divergence = rsi_fast - rsi_slow
- // SAR
- Sst = input (0.2, "SAR start")
- Sinc = input (0.2, "SAR inc")
- Smax = input (0.2, "SAR max")
- pSAR = sar (Sst, Sinc, Smax)
- plot (pSAR, style = cross)
- longCond = na
- shortCond = na
- longCond := divergence > 0 and rising(ema01,2) and not falling(ema03,2) and pSAR < open
- shortCond := divergence < 0 and falling(ema01,2) and not rising(ema02,2) and pSAR > open
- // Count your long short conditions for more control with Pyramiding
- sectionLongs = 0
- sectionLongs := nz(sectionLongs[1])
- sectionShorts = 0
- sectionShorts := nz(sectionShorts[1])
- if longCond
- sectionLongs := sectionLongs + 1
- sectionShorts := 0
- if shortCond
- sectionLongs := 0
- sectionShorts := sectionShorts + 1
- // Pyramiding Inputs
- pyrl = 1
- // These check to see your signal and cross references it against the pyramiding settings above
- longCondition = longCond and sectionLongs <= pyrl
- shortCondition = shortCond and sectionShorts <= pyrl
- // Get the price of the last opened long or short
- last_open_longCondition = na
- last_open_shortCondition = na
- last_open_longCondition := longCondition ? high[1] : nz(last_open_longCondition[1])
- last_open_shortCondition := shortCondition ? low[1] : nz(last_open_shortCondition[1])
- // Check if your last postion was a long or a short
- last_longCondition = na
- last_shortCondition = na
- last_longCondition := longCondition ? time : nz(last_longCondition[1])
- last_shortCondition := shortCondition ? time : nz(last_shortCondition[1])
- in_longCondition = last_longCondition > last_shortCondition
- in_shortCondition = last_shortCondition > last_longCondition
- // Take profit
- isTPl = input(true, "Take Profit Long")
- isTPs = input(true, "Take Profit Short")
- tp = input(40, "Take Profit %", type=float)
- long_tp = isTPl and crossover(high, (1+(tp/100))*last_open_longCondition) and in_longCondition == 1
- short_tp = isTPs and crossunder(low, (1-(tp/100))*last_open_shortCondition) and in_shortCondition == 1
- // Stop Loss
- isSLl = input(false, "Stop Loss Long")
- isSLs = input(false, "Stop Loss Short")
- sl= 0.0
- sl := input(3, "Stop Loss %", type=float)
- long_sl = isSLl and crossunder(low, (1-(sl/100))*last_open_longCondition) and longCondition == 0 and in_longCondition == 1
- short_sl = isSLs and crossover(high, (1+(sl/100))*last_open_shortCondition) and shortCondition == 0 and in_shortCondition == 1
- // Create a single close for all the different closing conditions.
- long_close = long_tp or long_sl ? 1 : 0
- short_close = short_tp or short_sl ? 1 : 0
- // Get the time of the last close
- last_long_close = na
- last_short_close = na
- last_long_close := long_close ? time : nz(last_long_close[1])
- last_short_close := short_close ? time : nz(last_short_close[1])
- // Alerts & Signals
- bton(b) => b ? 1 : 0
- bgcolor(color = longCondition ? lime : shortCondition ? orange : na, transp = 90)
- plotshape(longCondition, title = "Buy Signal", text = "Buy", style=shape.triangleup, location=location.belowbar, color = lime, editable = false, transp = 0)
- plotshape(shortCondition, title = "Sell Signal", text = "Sell", style=shape.triangledown, location=location.abovebar, color = orange, editable = false, transp = 0)
- plotshape(long_tp and last_longCondition > nz(last_long_close[1]), text ="TP", title="Take Profit Long", style=shape.triangledown,
- location=location.abovebar, color = red, editable = false, transp = 0)
- plotshape(short_tp and last_shortCondition > nz(last_short_close[1]) , text ="TP", title="Take Profit Short", style=shape.triangleup,
- location=location.belowbar, color = lime, editable = false, transp = 0)
- ltp = iff(long_tp and last_longCondition > nz(last_long_close[1]), (1+(tp/100))*last_open_longCondition, na)
- plot(ltp, style=cross, linewidth=3, color = white, editable = false)
- stp = iff(short_tp and last_shortCondition > nz(last_short_close[1]), (1-(tp/100))*last_open_shortCondition, na)
- plot(stp, style = cross, linewidth=3, color = white, editable = false)
- plotshape(long_sl and last_longCondition > nz(last_long_close[1]), text ="SL", title="Stop Loss Long", style=shape.triangledown,
- location=location.abovebar, color = red, editable = false, transp = 0)
- plotshape(short_sl and last_shortCondition > nz(last_short_close[1]), text ="SL", title="Stop Loss Short", style=shape.triangleup,
- location=location.belowbar, color = lime, editable = false, transp = 0)
- lsl = iff(long_sl and last_longCondition > nz(last_long_close[1]), (1-(sl/100))*last_open_longCondition, na)
- plot(lsl, style=cross, linewidth=3, color = white, editable = false)
- ssl = iff(short_sl and last_shortCondition > nz(last_short_close[1]), (1+(sl/100))*last_open_shortCondition, na)
- plot(ssl, style = cross, linewidth=3, color = white, editable = false)
- alertcondition(bton(longCondition or
- (short_tp and last_shortCondition > nz(last_short_close[1])) or
- (short_sl and last_shortCondition > nz(last_short_close[1]))), title="Buy Alert", message = "a=xavi b=buy u=currency q=3 t=market")
- alertcondition(bton(shortCondition or
- (long_tp and last_longCondition > nz(last_long_close[1])) or
- (long_sl and last_longCondition > nz(last_long_close[1]))), title="Sell Alert", message = "a=xavi b=sell q=99% t=market")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement