Advertisement
XaviZ

[LamBOTguini][ALERTa2]

Oct 15th, 2018
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.91 KB | None | 0 0
  1. //@version=3
  2.  
  3. study(title="[LamBOTguini][ALERTa2]", overlay = true)
  4.  
  5. // EMA 1
  6.  
  7. src0 = input(hlc3, "Source EMA 1", type = source), len0 = input(3, minval=1, title = "Lenght EMA 1")
  8. ema01 = ema(src0, len0)
  9. direction = rising(ema01, 2) ? +1 : falling(ema01, 2) ? -1 : 0
  10. plot_color = direction > 0 ? lime: direction < 0 ? red : na
  11. pema01 = plot(ema01, title="EMA 1", style=line, linewidth=1, color = plot_color)
  12.  
  13. // EMA 2
  14.  
  15. src02 = input(hlc3, "Source EMA 2", type = source), len02 = input(8, minval=1, title = "Lenght EMA 2")
  16. ema02 = ema(src02, len02)
  17. direction2 = rising(ema02, 2) ? +1 : falling(ema02, 2) ? -1 : 0
  18. plot_color2 = direction2 > 0 ? lime: direction2 < 0 ? red : na
  19. plot(ema02, title="EMA 2", style=line, linewidth=1, color = plot_color2)
  20.  
  21. // EMA 3
  22.  
  23. src03 = input(hlc3, "Source EMA 3", type = source), len03 = input(13, minval=1, title = "Lenght EMA 3")
  24. ema03 = ema(src03, len03)
  25. direction3 = rising(ema03, 2) ? +1 : falling(ema03, 2) ? -1 : 0
  26. plot_color3 = direction3 > 0 ? lime: direction3 < 0 ? red : na
  27. pema03 = plot(ema03, title="EMA 3", style=line, linewidth=1, color = plot_color3)
  28.  
  29. fill(pema01, pema03, color = ema01 > ema03 ? lime : red, editable = false)
  30.  
  31. // RSI Divergence
  32.  
  33. src_fast = hlc3, len_fast = input(5, minval=1, title="Length Fast RSI")
  34. src_slow = hlc3, len_slow = input(15,minval=1, title="Length Slow RSI")
  35. up_fast = rma(max(change(src_fast), 0), len_fast)
  36. down_fast = rma(-min(change(src_fast), 0), len_fast)
  37. rsi_fast = down_fast == 0 ? 100 : up_fast == 0 ? 0 : 100 - (100 / (1 + up_fast / down_fast))
  38. up_slow = rma(max(change(src_slow), 0), len_slow)
  39. down_slow = rma(-min(change(src_slow), 0), len_slow)
  40. rsi_slow = down_slow == 0 ? 100 : up_slow == 0 ? 0 : 100 - (100 / (1 + up_slow / down_slow))
  41.  
  42. divergence = rsi_fast - rsi_slow
  43.  
  44. // SAR
  45.  
  46. Sst = input (0.2, "SAR start")
  47. Sinc = input (0.2, "SAR inc")
  48. Smax = input (0.2, "SAR max")
  49. pSAR = sar (Sst, Sinc, Smax)
  50. plot (pSAR, style = cross)
  51.  
  52. longCond = na
  53. shortCond = na
  54. longCond := divergence > 0 and rising(ema01,2) and not falling(ema03,2) and pSAR < open
  55. shortCond := divergence < 0 and falling(ema01,2) and not rising(ema02,2) and pSAR > open
  56.  
  57. // Count your long short conditions for more control with Pyramiding
  58.  
  59. sectionLongs = 0
  60. sectionLongs := nz(sectionLongs[1])
  61. sectionShorts = 0
  62. sectionShorts := nz(sectionShorts[1])
  63.  
  64. if longCond
  65. sectionLongs := sectionLongs + 1
  66. sectionShorts := 0
  67.  
  68. if shortCond
  69. sectionLongs := 0
  70. sectionShorts := sectionShorts + 1
  71.  
  72. // Pyramiding Inputs
  73.  
  74. pyrl = 1
  75.  
  76. // These check to see your signal and cross references it against the pyramiding settings above
  77.  
  78. longCondition = longCond and sectionLongs <= pyrl
  79. shortCondition = shortCond and sectionShorts <= pyrl
  80.  
  81. // Get the price of the last opened long or short
  82.  
  83. last_open_longCondition = na
  84. last_open_shortCondition = na
  85. last_open_longCondition := longCondition ? high[1] : nz(last_open_longCondition[1])
  86. last_open_shortCondition := shortCondition ? low[1] : nz(last_open_shortCondition[1])
  87.  
  88. // Check if your last postion was a long or a short
  89.  
  90. last_longCondition = na
  91. last_shortCondition = na
  92. last_longCondition := longCondition ? time : nz(last_longCondition[1])
  93. last_shortCondition := shortCondition ? time : nz(last_shortCondition[1])
  94.  
  95. in_longCondition = last_longCondition > last_shortCondition
  96. in_shortCondition = last_shortCondition > last_longCondition
  97.  
  98. // Take profit
  99.  
  100. isTPl = input(true, "Take Profit Long")
  101. isTPs = input(true, "Take Profit Short")
  102. tp = input(40, "Take Profit %", type=float)
  103. long_tp = isTPl and crossover(high, (1+(tp/100))*last_open_longCondition) and in_longCondition == 1
  104. short_tp = isTPs and crossunder(low, (1-(tp/100))*last_open_shortCondition) and in_shortCondition == 1
  105.  
  106. // Stop Loss
  107.  
  108. isSLl = input(false, "Stop Loss Long")
  109. isSLs = input(false, "Stop Loss Short")
  110. sl= 0.0
  111. sl := input(3, "Stop Loss %", type=float)
  112. long_sl = isSLl and crossunder(low, (1-(sl/100))*last_open_longCondition) and longCondition == 0 and in_longCondition == 1
  113. short_sl = isSLs and crossover(high, (1+(sl/100))*last_open_shortCondition) and shortCondition == 0 and in_shortCondition == 1
  114.  
  115. // Create a single close for all the different closing conditions.
  116.  
  117. long_close = long_tp or long_sl ? 1 : 0
  118. short_close = short_tp or short_sl ? 1 : 0
  119.  
  120. // Get the time of the last close
  121.  
  122. last_long_close = na
  123. last_short_close = na
  124. last_long_close := long_close ? time : nz(last_long_close[1])
  125. last_short_close := short_close ? time : nz(last_short_close[1])
  126.  
  127. // Alerts & Signals
  128.  
  129. bton(b) => b ? 1 : 0
  130. bgcolor(color = longCondition ? lime : shortCondition ? orange : na, transp = 90)
  131. plotshape(longCondition, title = "Buy Signal", text = "Buy", style=shape.triangleup, location=location.belowbar, color = lime, editable = false, transp = 0)
  132. plotshape(shortCondition, title = "Sell Signal", text = "Sell", style=shape.triangledown, location=location.abovebar, color = orange, editable = false, transp = 0)
  133.  
  134. plotshape(long_tp and last_longCondition > nz(last_long_close[1]), text ="TP", title="Take Profit Long", style=shape.triangledown,
  135. location=location.abovebar, color = red, editable = false, transp = 0)
  136. plotshape(short_tp and last_shortCondition > nz(last_short_close[1]) , text ="TP", title="Take Profit Short", style=shape.triangleup,
  137. location=location.belowbar, color = lime, editable = false, transp = 0)
  138.  
  139. ltp = iff(long_tp and last_longCondition > nz(last_long_close[1]), (1+(tp/100))*last_open_longCondition, na)
  140. plot(ltp, style=cross, linewidth=3, color = white, editable = false)
  141. stp = iff(short_tp and last_shortCondition > nz(last_short_close[1]), (1-(tp/100))*last_open_shortCondition, na)
  142. plot(stp, style = cross, linewidth=3, color = white, editable = false)
  143.  
  144. plotshape(long_sl and last_longCondition > nz(last_long_close[1]), text ="SL", title="Stop Loss Long", style=shape.triangledown,
  145. location=location.abovebar, color = red, editable = false, transp = 0)
  146. plotshape(short_sl and last_shortCondition > nz(last_short_close[1]), text ="SL", title="Stop Loss Short", style=shape.triangleup,
  147. location=location.belowbar, color = lime, editable = false, transp = 0)
  148.  
  149. lsl = iff(long_sl and last_longCondition > nz(last_long_close[1]), (1-(sl/100))*last_open_longCondition, na)
  150. plot(lsl, style=cross, linewidth=3, color = white, editable = false)
  151. ssl = iff(short_sl and last_shortCondition > nz(last_short_close[1]), (1+(sl/100))*last_open_shortCondition, na)
  152. plot(ssl, style = cross, linewidth=3, color = white, editable = false)
  153.  
  154. alertcondition(bton(longCondition or
  155. (short_tp and last_shortCondition > nz(last_short_close[1])) or
  156. (short_sl and last_shortCondition > nz(last_short_close[1]))), title="Buy Alert", message = "a=xavi b=buy u=currency q=3 t=market")
  157. alertcondition(bton(shortCondition or
  158. (long_tp and last_longCondition > nz(last_long_close[1])) or
  159. (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