Advertisement
Guest User

"BTCbot HullMA 3x Pair" script written by SeaSide420

a guest
Jan 15th, 2018
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.79 KB | None | 0 0
  1. //@version=3
  2. //
  3. //This alert script is for use with Autoview.
  4. //Use the corresponding strategy script to backtest parameters and fill in the defaults here with the best results.
  5. //Checks for correlated action on US Dollar Index (DXY), GOLD:USD (XAU), and the currency being traded against USD (CUR).
  6. // Modify DXY with any quote currency strength meter,
  7. // GOLD:QUOTE (thus the need for a GOLD:BTC pair),
  8. // and any currency pair trading against the quote currency.
  9. // Experiment with different triangular correlations in strategy mode.
  10. //
  11. //Original "BTCbot HullMA 3x Pair" script written by SeaSide420
  12. //
  13. study("BTCbot2", shorttitle="BTCbot2", overlay=true)
  14. keh=input(title="HullMA Length",type=integer,defval=7, minval=1)
  15. dt = 0.001
  16. ot=1
  17. src = ohlc4[1]
  18. tf='60' //Set desired timeframe. This can only be set manually here.
  19. //
  20. DXY=(security("DXY",tf, src)) //USDollar index... Quote currency strength.
  21. e2ma=2*wma(DXY,round(keh/2))
  22. ema=wma(DXY,keh)
  23. ediff=e2ma-ema
  24. esqn=round(sqrt(keh))
  25. e2ma1=2*wma(DXY[1],round(keh/2))
  26. ema1=wma(DXY[1],keh)
  27. ediff1=e2ma1-ema1
  28. esqn1=round(sqrt(keh))
  29. e1=wma(ediff,esqn)
  30. e2=wma(ediff1,esqn)
  31. XAU=(security("XAUUSD", tf, src)) //Gold:USD or correlated asset.
  32. n2ma=2*wma(XAU,round(keh/2))
  33. nma=wma(XAU,keh)
  34. ndiff=n2ma-nma
  35. nsqn=round(sqrt(keh))
  36. n2ma1=2*wma(XAU[1],round(keh/2))
  37. nma1=wma(XAU[1],keh)
  38. ndiff1=n2ma1-nma1
  39. nsqn1=round(sqrt(keh))
  40. n1=wma(ndiff,nsqn)
  41. n2=wma(ndiff1,nsqn)
  42. CUR=(security("BTCUSD", tf, src)) //Crypto:USD pair being traded.
  43. s2ma=2*wma(CUR,round(keh/2))
  44. sma=wma(CUR,keh)
  45. sdiff=s2ma-sma
  46. ssqn=round(sqrt(keh))
  47. s2ma1=2*wma(CUR[1],round(keh/2))
  48. sma1=wma(CUR[1],keh)
  49. sdiff1=s2ma1-sma1
  50. ssqn1=round(sqrt(keh))
  51. s1=wma(sdiff,ssqn)
  52. s2=wma(sdiff1,ssqn)
  53. confidence=(security(tickerid, 'D', src)-security(tickerid, 'D', src[1]))/security(tickerid, 'D', src[1])
  54. //
  55. //Hull Ribbon Chart Visuals
  56. b=s1>s2?lime:black
  57. c=s1>s2?black:red
  58. c1=plot(s1, color=b, title="hull1", linewidth=2, transp=0)
  59. c2=plot(s2, color=c, title="hull1", linewidth=2, transp=0)
  60. fill(c1, c2, color=c, transp=75)
  61.  
  62. //Original Triggers
  63. //closelong = e1>e2 and confidence<dt
  64. //if (closelong)
  65. // strategy.close("Long")
  66. //
  67. //Comment out short triggers for buy-sell strategy
  68. //
  69. //closeshort = e1<e2 and confidence>dt
  70. //if (closeshort)
  71. // strategy.close("Short")
  72. //
  73. //longCondition = e1<e2 and n1>n2 and s1>s2 and strategy.opentrades<ot and confidence>dt
  74. //if (longCondition)
  75. // strategy.entry("Long",strategy.long)
  76. //
  77. //shortCondition = e1>e2 and n1<n2 and s1<s2 and strategy.opentrades<ot and confidence<dt
  78. //if (shortCondition)
  79. // strategy.entry("Short",strategy.short)
  80. //
  81. //Short condition triggers commented out for a buy-sell strategy
  82.  
  83. ////////////////////////===ANION=CODE====///////////////////////////////////
  84. // //
  85. // ULTIMATE PINE INJECTOR V1.2 + rs fix //
  86. // //
  87. ////////////////////////////////////////////////////////////////////////////
  88.  
  89. // === Conditions ===
  90.  
  91. long_entry = e1<e2 and n1>n2 and s1>s2 and confidence>dt //Long Or Buy Condition Here
  92.  
  93. short_entry = e1>e2 and n1<n2 and s1<s2 and confidence<dt //Short Or Sell Condition Here
  94.  
  95. long_exit = e1>e2 and confidence<dt //Close Long Condition Here (Optional)
  96.  
  97. short_exit = e1<e2 and confidence>dt //Close Short Condition Here (Optional)
  98.  
  99. // === /END
  100.  
  101. ///////////////////////////////////////////////////////////////////////////
  102.  
  103. // init these values here, they will get updated later as more decisions are made
  104. last_long_close = na
  105. last_short_close = na
  106.  
  107. // === Long position detection ===
  108. // longs open
  109. longo = 0
  110. longo := nz(longo[1])
  111. // longs closed
  112. longc = 0
  113. longc := nz(longc[1])
  114. if long_entry
  115. longo := longo + 1
  116. longc := 0
  117. if long_exit
  118. longc := longc + 1
  119. longo := 0
  120. // === /END
  121.  
  122. // === Short position detection ===
  123. shorto = 0
  124. shorto := nz(shorto[1])
  125. shortc = 0
  126. shortc := nz(shortc[1])
  127. if (short_entry)
  128. shorto := shorto + 1
  129. shortc := 0
  130. if (short_exit)
  131. shortc := shortc + 1
  132. shorto := 0
  133. // === /END
  134.  
  135. // === Pyramiding Settings ===
  136. //pyr = input(1, title="Pyramiding Setting")
  137. pyr = 1
  138. longCondition = long_entry and longo <= pyr
  139. longX = long_exit and longc <= pyr
  140. shortCondition = short_entry and shorto <=pyr
  141. shortX = short_exit and shortc <=pyr
  142. // === /END
  143.  
  144. // === Get Last Position Price ===
  145. last_open_longCondition = na
  146. last_open_shortCondition = na
  147. // last open prices
  148. last_open_longCondition := longCondition ? close : nz(last_open_longCondition[1])
  149. last_open_shortCondition := shortCondition ? close : nz(last_open_shortCondition[1])
  150. // === /END
  151.  
  152. // === Check For Long/Short ===
  153. last_longCondition = na
  154. last_shortCondition = na
  155. // last open times
  156. last_longCondition := longCondition ? time : nz(last_longCondition[1])
  157. last_shortCondition := shortCondition ? time : nz(last_shortCondition[1])
  158. last_longClose = longX ? time : nz(last_long_close[1])
  159. last_shortClose = shortX ? time : nz(last_short_close[1])
  160.  
  161. in_longCondition = last_longCondition > last_shortCondition and last_longCondition >= last_longClose
  162. in_shortCondition = last_shortCondition > last_longCondition and last_shortCondition >= last_shortClose
  163. // === /END
  164.  
  165. // === Stop Loss (Long) ===
  166. isSLl = input(false, "Stop Loss (Long)")
  167. sll = input(0, "Stop Loss %", type=float, step=0.2, minval=0, maxval=100) / 100
  168. long_call_sl = last_open_longCondition * (1 - sll)
  169. long_sl = isSLl and low <= long_call_sl and longCondition == 0
  170. // === /END
  171.  
  172. // === Stop Loss (Short) ===
  173. isSLs = input(false, "Stop Loss (Short)")
  174. sls = input(0, "Stop Loss %", type=float, step=0.2, minval=0, maxval=100) / 100
  175. short_call_sl = last_open_shortCondition * (1 + sls)
  176. short_sl = isSLs and high >= short_call_sl and shortCondition == 0
  177. // === /END
  178.  
  179. // === Trailing Stop ===
  180. last_high = na
  181. last_low = na
  182. last_high := in_longCondition ? (na(last_high[1]) or high > nz(last_high[1])) ? high : nz(last_high[1]) : na
  183. last_low := in_shortCondition ? (na(last_low[1]) or low < nz(last_low[1])) ? low : nz(last_low[1]) : na
  184. isTSl = input(true, "Trailing Stop Long")
  185. tsil = input(19, "Activate Trailing Stop % Long", type=float, step=1, minval=0, maxval=100) / 100
  186. tsl = input(2, "Trailing Stop % Long", type=float, step=1, minval=0, maxval=100) / 100
  187. long_call_ts = last_high * (1 - tsl)
  188. long_call_tsi = last_open_longCondition * (1 + tsil)
  189. long_ts = isTSl and not na(last_high) and low <= long_call_ts and longCondition == 0 and last_high >= long_call_tsi
  190. isTSs = input(true, "Trailing Stop Short")
  191. tsis = input(19, "Activate Trailing Stop % Short", type=float, step=1, minval=0, maxval=100) / 100
  192. tss = input(2, "Trailing Stop % Short", type=float, step=1, minval=0, maxval=100) / 100
  193. short_call_ts = last_low * (1 + tss)
  194. short_call_tsi = last_open_shortCondition * (1 - tsis)
  195. short_ts = isTSs and not na(last_low) and high >= short_call_ts and shortCondition == 0 and last_low <= short_call_tsi
  196. // === /END
  197.  
  198. // === Create Single Close For All Closing Conditions ===
  199. closelong = long_sl or long_ts or longX
  200. closeshort = short_sl or short_ts or shortX
  201.  
  202. // Get Last Close
  203. last_long_close := closelong ? time : nz(last_long_close[1])
  204. last_short_close := closeshort ? time : nz(last_short_close[1])
  205.  
  206. // Check For Close Since Last Open
  207. if closelong and last_long_close[1] > last_longCondition
  208. closelong := 0
  209.  
  210. if closeshort and last_short_close[1] > last_shortCondition
  211. closeshort := 0
  212. // === /END
  213.  
  214. ////////////////////////////////////////////////////////////////////////////
  215.  
  216. // === Alarm Settings ===
  217. alertcondition(longCondition==1, title='LONG', message='LONG')
  218. alertcondition(closelong==1, title='EXIT LONG', message='EXIT LONG')
  219. alertcondition(shortCondition==1, title='SHORT', message='SHORT')
  220. alertcondition(closeshort==1, title='EXIT SHORT', message='EXIT SHORT')
  221. // === /END
  222.  
  223. ////////////////////////////////////////////////////////////////////////////
  224.  
  225. // === Debugs Here ===
  226. //Remove "//" To Check/Debug The Code Above
  227. // Signal Shapes
  228. plotshape(longCondition[1]==1, title='LONG', style=shape.triangleup, size=size.large, color=#02CB80, location= location.belowbar)
  229. plotshape(shortCondition[1]==1, title='SHORT', style=shape.triangledown, size=size.large, color=#DC143C, location=location.abovebar)
  230. plotshape(shortCondition[1]==0 and closelong[1]==1, title='EXIT LONG', style=shape.xcross, color=#02CB80, location=location.belowbar, transp=0)
  231. plotshape(longCondition[1]==0 and closeshort[1]==1, title='EXIT SHORT', style=shape.xcross, color=#DC143C, location=location.abovebar, transp=0)
  232. // SL Plot
  233. slColor = (isSLl or isSLs) and (in_longCondition or in_shortCondition) ? red : white
  234. plot(isSLl and in_longCondition ? long_call_sl : na, "Long SL", slColor, style=3, linewidth=2)
  235. plot(isSLs and in_shortCondition ? short_call_sl : na, "Short SL", slColor, style=3, linewidth=2)
  236. // TP Plot
  237. //tpColor = isTP and (in_longCondition or in_shortCondition) ? purple : white
  238. //plot(isTP and in_longCondition ? long_call_tp : na, "Long TP", tpColor, style=3, linewidth=2)
  239. //plot(isTP and in_shortCondition ? short_call_tp : na, "Short TP", tpColor, style=3, linewidth=2)
  240. // TS Plot
  241. tsColor = (isTSl or isTSs) and (in_longCondition or in_shortCondition) ? orange : white
  242. tsiColor = (isTSl or isTSs) and (in_longCondition or in_shortCondition) ? white : orange
  243. plot(isTSl and in_longCondition ? long_call_tsi : na, "Long Trailing", tsiColor, style=3, linewidth=2)
  244. plot(isTSs and in_shortCondition ? short_call_tsi : na, "Short Trailing", tsiColor, style=3, linewidth=2)
  245. plot(isTSl and in_longCondition and last_high > long_call_tsi ? long_call_ts : na, "Long Trailing", tsColor, style=2, linewidth=2)
  246. plot(isTSs and in_shortCondition and last_low < short_call_tsi ? short_call_ts : na, "Short Trailing", tsColor, style=2, linewidth=2)
  247. // === /END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement