Al0rse

Omar Edited WF

Oct 26th, 2021 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.83 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. // © B_L_A_C_K_S_C_O_R_P_I_O_N
  3. // v 1.1
  4.  
  5. //@version=5
  6. strategy('Omar Edited WF', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=20, commission_type=strategy.commission.percent, commission_value=0.01)
  7.  
  8. // *************Appearance*************
  9. theme = input.string(defval='dark', options=['light', 'dark'], group='Appearance')
  10. show_fractals = input.bool(false, 'Show Fractals', group='Appearance')
  11. show_ema = input.bool(false, 'Show EMAs', group='Appearance')
  12.  
  13. // *************colors*************
  14. color_green = color.green
  15. color_red = color.red
  16. color_yellow = color.yellow
  17. color_orange = color.orange
  18. color_blue = color.blue
  19. color_white = color.white
  20.  
  21. // *************WF*************
  22. // Define "n" as the number of periods and keep a minimum value of 2 for error handling.
  23. n = input.int(title='Fractal Periods', defval=2, minval=2, group='Williams Fractals')
  24.  
  25. // UpFractal
  26. bool upflagDownFrontier = true
  27. bool upflagUpFrontier0 = true
  28. bool upflagUpFrontier1 = true
  29. bool upflagUpFrontier2 = true
  30. bool upflagUpFrontier3 = true
  31. bool upflagUpFrontier4 = true
  32.  
  33. for i = 1 to n by 1
  34. upflagDownFrontier := upflagDownFrontier and high[n - i] < high[n]
  35. upflagUpFrontier0 := upflagUpFrontier0 and high[n + i] < high[n]
  36. upflagUpFrontier1 := upflagUpFrontier1 and high[n + 1] <= high[n] and high[n + i + 1] < high[n]
  37. upflagUpFrontier2 := upflagUpFrontier2 and high[n + 1] <= high[n] and high[n + 2] <= high[n] and high[n + i + 2] < high[n]
  38. upflagUpFrontier3 := upflagUpFrontier3 and high[n + 1] <= high[n] and high[n + 2] <= high[n] and high[n + 3] <= high[n] and high[n + i + 3] < high[n]
  39. upflagUpFrontier4 := upflagUpFrontier4 and high[n + 1] <= high[n] and high[n + 2] <= high[n] and high[n + 3] <= high[n] and high[n + 4] <= high[n] and high[n + i + 4] < high[n]
  40. upflagUpFrontier4
  41. flagUpFrontier = upflagUpFrontier0 or upflagUpFrontier1 or upflagUpFrontier2 or upflagUpFrontier3 or upflagUpFrontier4
  42.  
  43. upFractal = upflagDownFrontier and flagUpFrontier
  44.  
  45. // downFractal
  46. bool downflagDownFrontier = true
  47. bool downflagUpFrontier0 = true
  48. bool downflagUpFrontier1 = true
  49. bool downflagUpFrontier2 = true
  50. bool downflagUpFrontier3 = true
  51. bool downflagUpFrontier4 = true
  52.  
  53. for i = 1 to n by 1
  54. downflagDownFrontier := downflagDownFrontier and low[n - i] > low[n]
  55. downflagUpFrontier0 := downflagUpFrontier0 and low[n + i] > low[n]
  56. downflagUpFrontier1 := downflagUpFrontier1 and low[n + 1] >= low[n] and low[n + i + 1] > low[n]
  57. downflagUpFrontier2 := downflagUpFrontier2 and low[n + 1] >= low[n] and low[n + 2] >= low[n] and low[n + i + 2] > low[n]
  58. downflagUpFrontier3 := downflagUpFrontier3 and low[n + 1] >= low[n] and low[n + 2] >= low[n] and low[n + 3] >= low[n] and low[n + i + 3] > low[n]
  59. downflagUpFrontier4 := downflagUpFrontier4 and low[n + 1] >= low[n] and low[n + 2] >= low[n] and low[n + 3] >= low[n] and low[n + 4] >= low[n] and low[n + i + 4] > low[n]
  60. downflagUpFrontier4
  61. flagDownFrontier = downflagUpFrontier0 or downflagUpFrontier1 or downflagUpFrontier2 or downflagUpFrontier3 or downflagUpFrontier4
  62.  
  63. downFractal = downflagDownFrontier and flagDownFrontier
  64.  
  65. // plotshape(downFractal and show_fractals, style=shape.triangleup, location=location.belowbar, offset=-n, color=color_green)
  66. // plotshape(upFractal and show_fractals, style=shape.triangledown, location=location.abovebar, offset=-n, color=color_red)
  67.  
  68. // *************EMA*************
  69. len_a = input.int(20, minval=1, title='EMA A   Length', group='Moving Averages', inline="a")
  70. src_a = input.source(close, title='Source', group='Moving Averages', inline="a")
  71. out_a = ta.ema(src_a, len_a)
  72. plot(show_ema ? out_a : na, title='EMA A', color=color_green)
  73.  
  74. len_b = input.int(50, minval=1, title='EMA B   Length', group='Moving Averages', inline="b")
  75. src_b = input.source(close, title='Source', group='Moving Averages', inline="b")
  76. out_b = ta.ema(src_b, len_b)
  77. ema_b_color = theme == 'dark' ? color_yellow : color_orange
  78. plot(show_ema ? out_b : na, title='EMA B', color=ema_b_color)
  79.  
  80. len_c = input.int(100, minval=1, title='EMA C   Length', group='Moving Averages', inline="c")
  81. src_c = input.source(close, title='Source', group='Moving Averages', inline="c")
  82. out_c = ta.ema(src_c, len_c)
  83. ema_c_color = theme == 'dark' ? color_white : color_blue
  84. plot(show_ema ? out_c : na, title='EMA C', color=ema_c_color)
  85.  
  86.  
  87.  
  88. // *************RSI*************
  89. res = input.timeframe(title="Timeframe", defval="15", group='RSI')
  90. len = input.int(14, minval=1, title='Length', group='RSI', inline='rsi')
  91. src = input.source(close, 'Source', group='RSI', inline='rsi', tooltip='3m chart => RSI in 5m\n5m chart => RSI in 15m\n15m chart => RSI in 45m\n1H chart => RSI in 4H\n4H chart => RSI in 1D\n>1D chart => RSI Auto')
  92. RSIFunc(len, src) =>
  93. up = ta.rma(math.max(ta.change(src), 0), len)
  94. down = ta.rma(-math.min(ta.change(src), 0), len)
  95. RSI = ta.rsi(src, len)
  96.  
  97. RSI
  98.  
  99. NormalRsi = RSIFunc(len, src)
  100. rsi = request.security(syminfo.tickerid, res, NormalRsi)
  101.  
  102. // *************Calculation*************
  103. long = out_a > out_b and out_a > out_c and downFractal and low[2] > out_c and rsi[2] < rsi
  104. // short = (out_a < out_b) and (out_a < out_c) and upFractal and high[2] < out_c and rsi[2] > rsi
  105.  
  106. // plotshape(long, style=shape.labelup, color=color_green, location=location.belowbar, title='long label', text='L', textcolor=color_white)
  107. // plotshape(short, style=shape.labeldown, color=color_red, location=location.abovebar, title="short label", text= "S", textcolor=color_white)
  108.  
  109. // *************End of Signals calculation*************
  110.  
  111. // Make inputs that set the take profit % (optional)
  112. longProfitPerc = input.float(title='Long Take Profit (%)', minval=0.0, step=0.1, defval=1.5, group='Orders') * 0.01
  113.  
  114. // shortProfitPerc = input(title="Short Take Profit (%)",
  115. // type=input.float, minval=0.0, step=0.1, defval=0.5, group="Orders") * 0.01
  116.  
  117. // Figure out take profit price
  118. longExitPrice = strategy.position_avg_price * (1 + longProfitPerc)
  119. // shortExitPrice = strategy.position_avg_price * (1 - shortProfitPerc)
  120.  
  121. // Plot take profit values for confirmation
  122. // plot(series=strategy.position_size > 0 ? longExitPrice : na, color=color_green, style=plot.style_circles, linewidth=1, title='Long Take Profit')
  123. // plot(series=(strategy.position_size < 0) ? shortExitPrice : na,
  124. // color=color_green, style=plot.style_circles,
  125. // linewidth=1, title="Short Take Profit")
  126.  
  127. // Submit entry orders
  128. if long and strategy.opentrades == 0
  129. strategy.entry(id='🟢', direction=strategy.long)
  130.  
  131. // if (short and strategy.opentrades == 0)
  132. // strategy.entry(id="Short", long=false)
  133.  
  134. // Set stop loss level with input options (optional)
  135. longLossPerc = input.float(title='Long Stop Loss (%)', minval=0.0, step=0.1, defval=3.1, group='Orders') * 0.01
  136.  
  137. // shortLossPerc = input(title="Short Stop Loss (%)",
  138. // type=input.float, minval=0.0, step=0.1, defval=3.1, group="Orders") * 0.01
  139.  
  140. // Determine stop loss price
  141. longStopPrice = strategy.position_avg_price * (1 - longLossPerc)
  142. // shortStopPrice = strategy.position_avg_price * (1 + shortLossPerc)
  143.  
  144. // Plot stop loss values for confirmation
  145. // plot(series=strategy.position_size > 0 ? longStopPrice : na, color=color_red, style=plot.style_cross, linewidth=1, title='Long Stop Loss')
  146. // plot(series=(strategy.position_size < 0) ? shortStopPrice : na,
  147. // color=color_red, style=plot.style_cross,
  148. // linewidth=1, title="Short Stop Loss")
  149.  
  150. // Submit exit orders based on calculated stop loss price
  151. if strategy.position_size > 0
  152. strategy.exit(id='🔴', limit=longExitPrice, stop=longStopPrice)
  153.  
  154. // if (strategy.position_size < 0)
  155. // strategy.exit(id="ExS", limit=shortExitPrice, stop=shortStopPrice)
  156.  
  157.  
Add Comment
Please, Sign In to add comment