Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.05 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. longCondition = long_entry and longo <= pyr
  111. longX = long_exit and longc <= pyr
  112. shortCondition = short_entry and shorto <=pyr
  113. shortX = short_exit and shortc <=pyr
  114. // === /END
  115.  
  116. // === Get Last Position Price ===
  117. last_open_longCondition = na
  118. last_open_shortCondition = na
  119. // last open prices
  120. last_open_longCondition := longCondition ? close : nz(last_open_longCondition[1])
  121. last_open_shortCondition := shortCondition ? close : nz(last_open_shortCondition[1])
  122. // === /END
  123.  
  124. // === Check For Long/Short ===
  125. last_longCondition = na
  126. last_shortCondition = na
  127. // last open times
  128. last_longCondition := longCondition ? time : nz(last_longCondition[1])
  129. last_shortCondition := shortCondition ? time : nz(last_shortCondition[1])
  130. last_longClose = longX ? time : nz(last_long_close[1])
  131. last_shortClose = shortX ? time : nz(last_short_close[1])
  132.  
  133. in_longCondition = last_longCondition > last_shortCondition and last_longCondition >= last_longClose
  134. in_shortCondition = last_shortCondition > last_longCondition and last_shortCondition >= last_shortClose
  135. // === /END
  136.  
  137.  
  138.  
  139. isSL = input(false, "Take Profit")
  140. longSLlevel = input(17, "Long TP % above entry")
  141. shortSLlevel = input(60, "Short TP % below entry")
  142. longentry = valuewhen(longCondition,close,0)
  143. shortentry = valuewhen(shortCondition,close,0)
  144. longmath = (longentry * longSLlevel) / 100
  145. shortmath = (shortentry * shortSLlevel) / 100
  146. longstop = longentry + longmath
  147. shortstop = shortentry - shortmath
  148. long_sl = isSL and in_longCondition and crossover(price,longstop)
  149. short_sl = isSL and in_shortCondition and crossunder(price,shortstop)
  150.  
  151. longSLcol = in_longCondition[1] ? lime : black
  152. shortSLcol = in_shortCondition[1] ? red : black
  153.  
  154. //Create Single Close For All Closing Conditions ===
  155. closelong = long_sl or longX
  156. closeshort = short_sl or shortX
  157.  
  158. // Get Last Close
  159. last_long_close := closelong ? time : nz(last_long_close[1])
  160. last_short_close := closeshort ? time : nz(last_short_close[1])
  161.  
  162. // Check For Close Since Last Open
  163. if closelong and last_long_close[1] > last_longCondition
  164. closelong := 0
  165.  
  166. if closeshort and last_short_close[1] > last_shortCondition
  167. closeshort := 0
  168. // === /END
  169.  
  170. // longCloseCol = na
  171. // shortCloseCol = na
  172. // longCloseCol := long_tp ? purple : long_sl ? maroon : longCloseCol[1]
  173. // shortCloseCol := short_tp ? purple : short_sl ? maroon : shortCloseCol[1]
  174. // tpColor = isTP and in_longCondition ? purple : isTP and in_shortCondition ? purple : white
  175. 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
  176. //==Plots==
  177.  
  178.  
  179. c2 = in_longCondition ? lime :in_shortCondition ? red : black// slColor// in_shortCondition and isSL ? red : isSL and in_longCondition ? lime : black
  180. n1t=plot(topvecMA, "Top MA", color = red, linewidth= 8, transp=65)
  181. n1b=plot(botvecMA, "Bot MA", color = lime, linewidth= 8, transp=65)
  182. n2b=plot(hull, "Signal MA", color=c2, transp=5)
  183. fill(n1b, n1t, color=c2, transp=85)
  184.  
  185.  
  186. ///////////////////////////////
  187. //======[ Alert Plots ]======//
  188. ///////////////////////////////
  189.  
  190.  
  191. // New Signal Plots
  192. plotshape(series=longCondition, title="Long",text = "Sniper long", style=shape.triangleup, location=location.belowbar, color=lime, size=size.small)
  193. plotshape(series=shortCondition, title="Short",text = "Sniper short", style=shape.triangledown, location=location.abovebar, color=red, size=size.small)
  194.  
  195. //plotshape(series=long_sl, title="Take money long", text = "Take money long", style=shape.triangledown, location=location.abovebar, color=red, size=size.tiny)
  196. //plotshape(series=short_sl, title="Take money short", text = "Take money short", style=shape.triangleup, location=location.belowbar, color=lime, size=size.tiny)
  197. //plotshape(series=long_sl3, title="SL", text = "SL", style=shape.triangledown, location=location.abovebar, color=red, size=size.tiny)
  198. //plotshape(series=short_sl3, title="SL", text = "SL", style=shape.triangleup, location=location.belowbar, color=lime, size=size.tiny)
  199.  
  200. alertcondition(condition=longCondition, title="Long", message="/Market_Buy*v5000*Bitmex*XBTUSD*3*1*40*1*AI")
  201. alertcondition(condition=shortCondition, title="Short", message="/Market_Sell*v5000*Bitmex*XBTUSD*3*1*40*1*AI")
  202. alertcondition(condition=long_sl, title="Take money long", message="/close*v5000*Bitmex*XBTUSD*3*1*40*1*AI")
  203. 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