Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.13 KB | None | 0 0
  1. //@version=3
  2.  
  3. study("Sniper XBTUSD Full", overlay=true)
  4.  
  5.  
  6. /////////////////////////////////////
  7. //* Put your strategy logic below *//
  8. /////////////////////////////////////
  9.  
  10. sourcein=high
  11. haclose = security(heikinashi(tickerid), period, close)
  12. hullper=input(title="Hull Length", type=integer, defval=1, minval=1,maxval=500)
  13. hull = vwma(2*sma(sourcein,round(hullper/2))-sma(sourcein,hullper),round(sqrt(hullper)))
  14. price = ema(close,1)
  15.  
  16. topdecay = input(1, "Top Decay")
  17. decayt = atr(topdecay)*0.005
  18. topstage = input(-22, "Top Stage Length")
  19. topmalength = input(150, "TopMa Length")
  20.  
  21. botdecay = input(1, "Bot Decay")
  22. decayb = atr(botdecay)*0.005
  23. botstage = input(-15, "Bot Stage Length")
  24. botmalength = input(1, "Bot Ma Length")
  25.  
  26. topvector01 = 0.0
  27. topvector01finalcounter = 0.0
  28. pretopvector01 = nz(topvector01[2], sourcein)
  29. topvector01 := sourcein >= pretopvector01 ? sourcein : pretopvector01 - (decayt * topvector01finalcounter[1])
  30. topvector01counter = n - valuewhen(sourcein >= topvector01, n, 0)
  31. topvector01finalcounter := topvector01counter <= 87 ? topstage : topvector01counter <= 87*4 ? 15 : 12
  32.  
  33. botvector01 = 0.0
  34. botvector01finalcounter = 0.0
  35. prebotvector01 = nz(botvector01[1], sourcein)
  36. botvector01 := sourcein <= prebotvector01 ? sourcein : prebotvector01 + (decayb * botvector01finalcounter[1])
  37. botvector01counter = n - valuewhen(sourcein <= botvector01, n, 0)
  38. botvector01finalcounter := botvector01counter <= 87 ? botstage : botvector01counter <= 87*4 ? 15 : 12
  39.  
  40. topvecMA = sma(topvector01,topmalength)
  41. botvecMA = sma(botvector01,botmalength)
  42.  
  43. // Long/Short Logic
  44. // Long/Short Logic
  45.  
  46. longLogic = crossunder(hull,botvecMA) ? 1 : 0 or high[0] > high[1] and high[0] > high[2] and high[0] > high[3] and high[0] > high[4] and high[0] > high[5] and high[0] > high[6] and high[0] > high[7]? 1 : 0
  47. shortLogic = crossunder(hull,topvecMA) ? 1 : 0 or low[1] < low[2] and low[0] < low[5] and low[0] < low[6] and low[0] < low[7]? 1 : 0 //crossover(hull,topvecMA) ? 1 : 0 or
  48.  
  49.  
  50. // Bar Colors and signals
  51. //plotshape(longLogic, title= "ReversalLong", location=location.belowbar, color=green, style=shape.triangleup, text="BUY")
  52. //plotshape(shortLogic, title= "ReversalShort", location=location.abovebar, color=red, style=shape.triangledown, text="SELL")
  53.  
  54. shortflipvalue = valuewhen(shortLogic,open+10,0)
  55. longflipvalue = valuewhen(longLogic,open-10,0)
  56. longflip = crossunder(price,longflipvalue) or crossunder(price,shortflipvalue)
  57. shortflip = crossover(price,shortflipvalue) or crossover(price,longflipvalue)
  58.  
  59.  
  60. long_entry = longLogic //Long Or Buy Condition Here
  61.  
  62. short_entry = shortLogic //Short Or Sell Condition Here
  63.  
  64. ////////////////////////////////////////////////////////////////////////////
  65.  
  66. //Replace Only If Valid Exit Conditions
  67.  
  68. long_exit = short_entry
  69.  
  70. short_exit = long_entry
  71.  
  72. // === /END
  73.  
  74. ///////////////////////////////////////////////////////////////////////////
  75.  
  76. // init these values here, they will get updated later as more decisions are made
  77. last_long_close = na
  78. last_short_close = na
  79.  
  80. // === Long position detection ===
  81. // longs open
  82. longo = 0
  83. longo := nz(longo[1])
  84. // longs closed
  85. longc = 0
  86. longc := nz(longc[1])
  87. if long_entry
  88. longo := longo + 1
  89. longc := 0
  90. if long_exit
  91. longc := longc + 1
  92. longo := 0
  93. // === /END
  94.  
  95. // === Short position detection ===
  96. shorto = 0
  97. shorto := nz(shorto[1])
  98. shortc = 0
  99. shortc := nz(shortc[1])
  100. if short_entry
  101. shorto := shorto + 1
  102. shortc := 0
  103. if short_exit
  104. shortc := shortc + 1
  105. shorto := 0
  106. // === /END
  107.  
  108. // === Pyramiding Settings ===
  109. //pyr = input(1, title="Pyramiding Setting")
  110. pyr = 1
  111. longCondition = long_entry and longo <= pyr
  112. longX = long_exit and longc <= pyr
  113. shortCondition = short_entry and shorto <=pyr
  114. shortX = short_exit and shortc <=pyr
  115. // === /END
  116.  
  117. // === Get Last Position Price ===
  118. last_open_longCondition = na
  119. last_open_shortCondition = na
  120. // last open prices
  121. last_open_longCondition := longCondition ? close : nz(last_open_longCondition[1])
  122. last_open_shortCondition := shortCondition ? close : nz(last_open_shortCondition[1])
  123. // === /END
  124.  
  125. // === Check For Long/Short ===
  126. last_longCondition = na
  127. last_shortCondition = na
  128. // last open times
  129. last_longCondition := longCondition ? time : nz(last_longCondition[1])
  130. last_shortCondition := shortCondition ? time : nz(last_shortCondition[1])
  131. last_longClose = longX ? time : nz(last_long_close[1])
  132. last_shortClose = shortX ? time : nz(last_short_close[1])
  133.  
  134. in_longCondition = last_longCondition > last_shortCondition and last_longCondition >= last_longClose
  135. in_shortCondition = last_shortCondition > last_longCondition and last_shortCondition >= last_shortClose
  136. // === /END
  137.  
  138.  
  139.  
  140. isSL = input(false, "Take Profit")
  141. longSLlevel2 = input(17, "Long TP % below entry")
  142. shortSLlevel2 = input(60, "Short TP % above entry")
  143. longSLlevel = longSLlevel2 / 1
  144. shortSLlevel = shortSLlevel2 / 10
  145. longentry = valuewhen(longCondition,close,0)
  146. shortentry = valuewhen(shortCondition,close,0)
  147. longmath = (longentry * longSLlevel) / 1000000
  148. shortmath = (shortentry * shortSLlevel) / 1000
  149. longstop = longentry + longmath
  150. shortstop = shortentry - shortmath
  151. long_sl = isSL and in_longCondition and crossover(price,longstop)
  152. short_sl = isSL and in_shortCondition and crossunder(price,shortstop)
  153.  
  154. longSLcol = in_longCondition[1] ? lime : black
  155. shortSLcol = in_shortCondition[1] ? red : black
  156.  
  157. //Create Single Close For All Closing Conditions ===
  158. closelong = long_sl or longX
  159. closeshort = short_sl or shortX
  160.  
  161. // Get Last Close
  162. last_long_close := closelong ? time : nz(last_long_close[1])
  163. last_short_close := closeshort ? time : nz(last_short_close[1])
  164.  
  165. // Check For Close Since Last Open
  166. if closelong and last_long_close[1] > last_longCondition
  167. closelong := 0
  168.  
  169. if closeshort and last_short_close[1] > last_shortCondition
  170. closeshort := 0
  171. // === /END
  172.  
  173. // longCloseCol = na
  174. // shortCloseCol = na
  175. // longCloseCol := long_tp ? purple : long_sl ? maroon : longCloseCol[1]
  176. // shortCloseCol := short_tp ? purple : short_sl ? maroon : shortCloseCol[1]
  177. // tpColor = isTP and in_longCondition ? purple : isTP and in_shortCondition ? purple : white
  178. slColor = isSL and in_shortCondition and crossunder(price,shortstop)? lime : isSL and in_longCondition? lime : isSL and in_longCondition and crossover(price,longstop) ? white : red
  179. //==Plots==
  180.  
  181.  
  182. c2 = in_longCondition ? lime :in_shortCondition ? red : white// slColor// in_shortCondition and isSL ? red : isSL and in_longCondition ? lime : black
  183. n1t=plot(topvecMA, "Top MA", color = red, linewidth= 8, transp=65)
  184. n1b=plot(botvecMA, "Bot MA", color = lime, linewidth= 8, transp=65)
  185. n2b=plot(hull, "Signal MA", color=c2, transp=5)
  186. fill(n1b, n1t, color=c2, transp=85)
  187.  
  188.  
  189. ///////////////////////////////
  190. //======[ Alert Plots ]======//
  191. ///////////////////////////////
  192.  
  193.  
  194. // New Signal Plots
  195. plotshape(series=longCondition, title="Long",text = "Sniper long", style=shape.triangleup, location=location.belowbar, color=lime, size=size.small)
  196. plotshape(series=shortCondition, title="Short",text = "Sniper short", style=shape.triangledown, location=location.abovebar, color=red, size=size.small)
  197.  
  198. //plotshape(series=long_sl, title="Take money long", text = "Take money long", style=shape.triangledown, location=location.abovebar, color=red, size=size.tiny)
  199. //plotshape(series=short_sl, title="Take money short", text = "Take money short", style=shape.triangleup, location=location.belowbar, color=lime, size=size.tiny)
  200. //plotshape(series=long_sl3, title="SL", text = "SL", style=shape.triangledown, location=location.abovebar, color=red, size=size.tiny)
  201. //plotshape(series=short_sl3, title="SL", text = "SL", style=shape.triangleup, location=location.belowbar, color=lime, size=size.tiny)
  202.  
  203. alertcondition(condition=longCondition, title="Long", message="/Market_Buy*v5000*Bitmex*XBTUSD*3*1*40*1*AI")
  204. alertcondition(condition=shortCondition, title="Short", message="/Market_Sell*v5000*Bitmex*XBTUSD*3*1*40*1*AI")
  205. alertcondition(condition=long_sl, title="Take money long", message="/close*v5000*Bitmex*XBTUSD*3*1*40*1*AI")
  206. alertcondition(condition=short_sl, title="Take money short",message ="/close*v5000*Bitmex*XBTUSD*3*1*40*1*AI")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement