Advertisement
Maurizio-Ciullo

Center of Gravity and ADX Trend Follower Strategy AVAXYSDT.P BYBIT 3H

Mar 2nd, 2023 (edited)
820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This source code is subject to the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
  2. // © TheSocialCryptoClub
  3. // Author: @devil_machine
  4.  
  5. //@version=5
  6.  
  7. strategy("Center of Gravity and ADX Trend Follower Strategy AVAX-USDT.P BYBIT 3H", overlay=true, pyramiding=1,
  8.          initial_capital=1000,
  9.          default_qty_value=1000, default_qty_type=strategy.cash,
  10.          slippage=2,
  11.          commission_type=strategy.commission.percent,commission_value=0.06
  12.          )
  13.  
  14. // --------------------------
  15. // Directional Filter
  16. // --------------------------
  17. trade_long = input.bool(true)
  18. trade_short = input.bool(true)
  19.  
  20. direction = trade_long and not trade_short ? strategy.direction.long :
  21.          trade_short and not trade_long ? strategy.direction.short :
  22.          strategy.direction.all
  23.  
  24. strategy.risk.allow_entry_in(direction)
  25.  
  26. // --------------------------
  27. // Risk Management
  28. // --------------------------
  29.  
  30. max_intraday_loss = input.int(100)
  31.  
  32. strategy.risk.max_intraday_loss(max_intraday_loss, strategy.cash)
  33.  
  34. // --------------------------
  35. // Indicators
  36. // --------------------------
  37.  
  38. mfi_len = input.int(11)
  39. rsi_len = input.int(11)
  40. cog_len = input.int(10)
  41. cog_smoothing = input.int(3)
  42.  
  43.  
  44.  
  45. mfi = ta.mfi(close, mfi_len)
  46. rsi = ta.rsi(close, rsi_len)
  47.  
  48. cog_value=ta.cog(close,cog_len)
  49. signal_value = ta.sma(ta.cog(close,cog_len),cog_smoothing)
  50.  
  51. adx_len= input(15) // 10: btc 30m; 70: btc 3h
  52. di_len= input(22) //8 btc 30m; 100: btc 3h
  53. dirmov(len)=>
  54.     up=ta.change(high)
  55.     down= -ta.change(low)
  56.     plusDM= na(up) ? na : (up>down and up> 0 ? up:0)
  57.     minusDM= na(down) ? na : (down> up and down > 0 ? down : 0)
  58.     truerange= ta.rma(ta.tr, len)
  59.     plus= fixnan(100*ta.rma(plusDM, len) /truerange)
  60.     minus= fixnan(100* ta.rma(minusDM, len)/ truerange)
  61.     [plus, minus]
  62. adx(dilen, adxlen)=>
  63.     [plus, minus]= dirmov(dilen)
  64.     sum = plus + minus
  65.     adx = 100* ta.rma(math.abs(plus - minus) / (sum == 0?1:sum), adxlen)
  66. sig=adx(di_len, adx_len)
  67.  
  68.  
  69. // ----------------------------
  70. // Long/Short Entry Conditions
  71. // ----------------------------
  72.  
  73. adx_entry_condition = input.int(25)
  74.  
  75. el_cond = ta.crossover(cog_value, signal_value) and sig < adx_entry_condition
  76. es_cond = ta.crossunder(cog_value, signal_value) and sig < adx_entry_condition      
  77.  
  78. // --------------------------
  79. // Plots
  80. // --------------------------
  81.  
  82. plotshape(el_cond, location.belowbar, color=color.green)
  83. plotshape(es_cond, location.abovebar, color=color.red)
  84.  
  85.  
  86. if el_cond
  87.     strategy.entry("EL", strategy.long)
  88. if es_cond
  89.     strategy.entry("ES", strategy.short)
  90.  
  91. // -------------------------------
  92. // Long Exit Conditions and Orders
  93. // -------------------------------
  94.  
  95. xl_mfi_cond = input.int(90)
  96.  
  97. xl_cond = ta.crossover(mfi, xl_mfi_cond)
  98.  
  99. xl_sl_percent = input.float(2, step=0.5)
  100. xl_tp_percent = input.float(20, step=0.5)
  101.  
  102. xl_sl_price = strategy.position_avg_price * (1-xl_sl_percent/100)
  103. xl_tp_price = strategy.position_avg_price * (1+xl_tp_percent/100)
  104.  
  105. xl_ts_percent = input.float(1, step=0.1)
  106. xl_to_percent = input.float(0.5, step=0.1)
  107.  
  108. xl_ts_tick = xl_ts_percent * close/syminfo.mintick/100
  109. xl_to_tick = xl_to_percent * close/syminfo.mintick/100
  110.  
  111. strategy.exit("XL+SL/TP", "EL", stop=xl_sl_price, limit=xl_tp_price, trail_points=xl_ts_tick, trail_offset=xl_to_tick)
  112.  
  113. if xl_cond
  114.     strategy.close("EL")
  115.  
  116. // --------------------------------
  117. // Short Exit Conditions and Orders
  118. // --------------------------------
  119.  
  120. xs_rsi_cond = input.int(18)
  121.  
  122. xs_cond = ta.crossunder(rsi, xs_rsi_cond)
  123.  
  124. xs_sl_percent = input.float(2,step=0.5)
  125. xs_tp_percent = input.float(20,step=0.5)
  126.  
  127. xs_sl_price = strategy.position_avg_price * (1+xs_sl_percent/100)
  128. xs_tp_price = strategy.position_avg_price * (1-xs_tp_percent/100)
  129.  
  130. xs_ts_percent = input.float(1, step=0.1)
  131. xs_to_percent = input.float(0.5, step=0.1)
  132.  
  133. xs_ts_tick = xs_ts_percent * close/syminfo.mintick/100
  134. xs_to_tick = xs_to_percent * close/syminfo.mintick/100
  135.  
  136. strategy.exit("XS-SL/TP", "ES", stop=xs_sl_price, limit=xs_tp_price, trail_points=xs_ts_tick, trail_offset=xs_to_tick)
  137.  
  138. if xs_cond
  139.     strategy.close("ES")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement