xmd79

Technische Universität Berlin

Jun 21st, 2022
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 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. // © hibana2077
  3.  
  4. //@version=5
  5. strategy(title="Technische Universität Berlin",overlay=true, default_qty_type=strategy.cash, commission_value= 0.05, commission_type=strategy.commission.percent, slippage=1, currency=currency.USD, default_qty_value= 10000, initial_capital= 10000)
  6.  
  7. //def and input
  8. source = close
  9. mg0 = 0.0
  10. mg1 = 0.0
  11. mg2 = 0.0
  12. mg3 = 0.0
  13. mg4 = 0.0
  14. mg5 = 0.0
  15. mg6 = 0.0
  16. mg7 = 0.0
  17. mg8 = 0.0
  18. length = input.int(20, minval=1)
  19. src = input(hlc3, title="Source")
  20. p = input.int(10, minval=1)
  21. x = input.int(1, minval=1)
  22. q = input.int(9, minval=1)
  23. n = input.int(120,title="Basic guides line")
  24. trail_points= input.int(6, minval=1)
  25. trail_offset= input.int(1, minval=1)
  26.  
  27. //McGinley
  28. mg0 := na(mg0[1]) ? ta.ema(source, 2) : mg0[1] + (source - mg0[1]) / (2 * math.pow(source/mg0[1], 4))
  29. mg1 := na(mg1[1]) ? ta.ema(source, 3) : mg1[1] + (source - mg1[1]) / (3 * math.pow(source/mg1[1], 4))
  30. mg2 := na(mg2[1]) ? ta.ema(source, 5) : mg2[1] + (source - mg2[1]) / (5 * math.pow(source/mg2[1], 4))
  31. mg3 := na(mg3[1]) ? ta.ema(source, 8) : mg3[1] + (source - mg3[1]) / (8 * math.pow(source/mg3[1], 4))
  32. mg4 := na(mg4[1]) ? ta.ema(source, 13) : mg4[1] + (source - mg4[1]) / (13 * math.pow(source/mg4[1], 4))
  33. mg5 := na(mg5[1]) ? ta.ema(source, 21) : mg5[1] + (source - mg5[1]) / (21 * math.pow(source/mg5[1], 4))
  34. mg6 := na(mg6[1]) ? ta.ema(source, 34) : mg6[1] + (source - mg6[1]) / (34 * math.pow(source/mg6[1], 4))
  35. mg7 := na(mg7[1]) ? ta.ema(source, 55) : mg7[1] + (source - mg7[1]) / (55 * math.pow(source/mg7[1], 4))
  36. mg8 := na(mg8[1]) ? ta.ema(source, 89) : mg8[1] + (source - mg8[1]) / (89 * math.pow(source/mg8[1], 4))
  37.  
  38. //stop and take
  39. first_high_stop = ta.highest(high, p) - x * ta.atr(p)
  40. first_low_stop = ta.lowest(low, p) + x * ta.atr(p)
  41. stop_short = ta.highest(first_high_stop, q)
  42. stop_long = ta.lowest(first_low_stop, q)
  43.  
  44.  
  45. //plot
  46. plot(mg0,color=color.fuchsia)
  47. plot(mg1,color=color.fuchsia)
  48. plot(mg2,color=color.fuchsia)
  49. plot(mg3,color=color.fuchsia)
  50. plot(mg4,color=color.fuchsia)
  51. plot(mg5,color=color.fuchsia)
  52. plot(mg6,color=color.fuchsia)
  53. plot(mg7,color=color.fuchsia)
  54. plot(mg8,color=color.fuchsia)
  55. plot(stop_long, color=#2962FF)
  56. plot(stop_short, color=#FF6D00)
  57.  
  58. //cci
  59. ma = ta.sma(src, length)
  60. cci = (src - ma) / (0.015 * ta.dev(src, length))
  61.  
  62. //single
  63. BUY=cci[0]>cci[1] and cci>100 and mg0>mg1 and mg0>mg2 and mg0>mg3 and mg0>mg4 and mg0>mg5 and mg2>mg3 and mg3>mg4
  64. SELL=cci[0]<cci[1] and cci<-100 and mg0<mg1 and mg0<mg2 and mg0<mg3 and mg0<mg4 and mg0<mg5 and mg2<mg3 and mg3<mg4
  65.  
  66. //order
  67. if not strategy.opentrades
  68. // Long Strategy
  69. if BUY
  70. strategy.entry("Long", strategy.long)
  71. strategy.exit("exit", "Long", stop=stop_long, trail_points=trail_points, trail_offset=trail_offset)
  72.  
  73. // Short Strategy
  74. if SELL
  75. strategy.entry("Short", strategy.short)
  76. strategy.exit("exit","Short", stop=stop_short, trail_points=trail_points, trail_offset=trail_offset)
Advertisement
Add Comment
Please, Sign In to add comment