Advertisement
Guest User

Untitled

a guest
Jun 18th, 2021
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © ysantur
  3. //@version=4
  4. strategy("Yeşillim strategy", overlay = true , precision = 7, max_bars_back = 500,pyramiding = 0, initial_capital = 1000, currency = currency.USD, default_qty_type = strategy.cash, default_qty_value = 500, commission_type = "percent", commission_value = 0.1, calc_on_every_tick=false, process_orders_on_close=false)
  5.  
  6. // === INPUT BACKTEST RANGE ===
  7. fromMonth = input(defval = 1, title = "From Month", type = input.integer, minval = 1, maxval = 12)
  8. fromDay = input(defval = 1, title = "From Day", type = input.integer, minval = 1, maxval = 31)
  9. fromYear = input(defval = 2021, title = "From Year", type = input.integer, minval = 1970)
  10. thruMonth = input(defval = 1, title = "Thru Month", type = input.integer, minval = 1, maxval = 12)
  11. thruDay = input(defval = 1, title = "Thru Day", type = input.integer, minval = 1, maxval = 31)
  12. thruYear = input(defval = 2112, title = "Thru Year", type = input.integer, minval = 1970)
  13.  
  14. // === INPUT SHOW PLOT ===
  15. showDate = input(defval = true, title = "Show Date Range", type = input.bool)
  16.  
  17. // === FUNCTION EXAMPLE ===
  18. start = timestamp(fromYear, fromMonth, fromDay, 00, 00) // backtest start window
  19. finish = timestamp(thruYear, thruMonth, thruDay, 23, 59) // backtest finish window
  20. window() => time >= start and time <= finish ? true : false // create function "within window of time"
  21.  
  22.  
  23. src = (close*2+high+low+open)/5
  24. depth = input(title="Depth", type=input.integer, defval=10)
  25. smooth = input(title="Smooth", type=input.integer, defval=9)
  26.  
  27. bias = input(title="Bias", type=input.float, step=0.1, defval=0.3)
  28. up=(100+bias)/100
  29. down=(100-bias)/100
  30.  
  31. f=array.new_int(depth+1)
  32. W=array.new_float(depth)
  33. a=1
  34. b=1
  35. sum=0.0
  36.  
  37. for i=0 to depth
  38. array.set(f,i,a+b)
  39. a:=b
  40. b:=array.get(f,i)
  41.  
  42. x=0.0
  43.  
  44. for i=1 to depth-1
  45. array.set(W,i,array.get(f,depth-1)/array.get(f,i))
  46. sum:=sum+array.get(f,depth-1)/array.get(f,i)
  47.  
  48. for i=1 to depth-1
  49. x:=x+array.get(W,depth-i) * src
  50.  
  51. x:=x/sum
  52.  
  53. x:=ema(x,8)
  54. y=ema(x,3)
  55. e1 = stdev(x, 3)
  56. e2 = stdev(x, 8)
  57.  
  58. u=x+e1
  59. l=x-2*(e1+e2)
  60.  
  61.  
  62. buySignal = crossover(src, x)
  63. sellSignal = crossunder(src, y)
  64. //plotshape(buySignal,text="Buy",style=shape.labelup, size=size.tiny,color=color.green, textcolor=color.white)
  65. //plotshape(sellSignal,text="Sell",style=shape.labeldown, size=size.tiny,color=color.red, textcolor=color.white)
  66.  
  67. renk=color.yellow
  68. if (crossover(src, x) or src>=x ) or src>=y
  69. renk:=color.green
  70. if (crossunder(src, y) or src<y)
  71. renk:=color.red
  72.  
  73. plot(l,color=renk, linewidth=3)
  74.  
  75.  
  76. longCond = bool(na)
  77. shortCond = bool(na)
  78.  
  79. //longCond := (crossover(src, x) or src>=x ) or src>=y
  80. //shortCond := (crossunder(src, y) or src<y)
  81.  
  82. longCond := crossover(src, x)
  83. shortCond := crossunder(src, y)
  84.  
  85.  
  86. CondIni = 0
  87. CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
  88. long = longCond and CondIni[1] == -1
  89. short = shortCond and CondIni[1] == 1
  90. plotshape(long, title="BUY", text="B", style=shape.labeldown, textcolor=color.white, size=size.auto, location=location.top, color=color.green, transp=0)
  91. plotshape(short, title="SELL", text="S", style=shape.labelup, textcolor=color.white, size=size.auto, location=location.bottom, color=color.red, transp=0)
  92.  
  93. strategy.entry(id="Long Entry", comment="buy", long=true, when=long and window() )
  94. strategy.close("Long Entry", comment="sell", when=short and window() )
  95.  
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement