Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
- // © TheSocialCryptoClub
- // Author: @devil_machine
- //@version=5
- strategy("Center of Gravity and ADX Trend Follower Strategy AVAX-USDT.P BYBIT 3H", overlay=true, pyramiding=1,
- initial_capital=1000,
- default_qty_value=1000, default_qty_type=strategy.cash,
- slippage=2,
- commission_type=strategy.commission.percent,commission_value=0.06
- )
- // --------------------------
- // Directional Filter
- // --------------------------
- trade_long = input.bool(true)
- trade_short = input.bool(true)
- direction = trade_long and not trade_short ? strategy.direction.long :
- trade_short and not trade_long ? strategy.direction.short :
- strategy.direction.all
- strategy.risk.allow_entry_in(direction)
- // --------------------------
- // Risk Management
- // --------------------------
- max_intraday_loss = input.int(100)
- strategy.risk.max_intraday_loss(max_intraday_loss, strategy.cash)
- // --------------------------
- // Indicators
- // --------------------------
- mfi_len = input.int(11)
- rsi_len = input.int(11)
- cog_len = input.int(10)
- cog_smoothing = input.int(3)
- mfi = ta.mfi(close, mfi_len)
- rsi = ta.rsi(close, rsi_len)
- cog_value=ta.cog(close,cog_len)
- signal_value = ta.sma(ta.cog(close,cog_len),cog_smoothing)
- adx_len= input(15) // 10: btc 30m; 70: btc 3h
- di_len= input(22) //8 btc 30m; 100: btc 3h
- dirmov(len)=>
- up=ta.change(high)
- down= -ta.change(low)
- plusDM= na(up) ? na : (up>down and up> 0 ? up:0)
- minusDM= na(down) ? na : (down> up and down > 0 ? down : 0)
- truerange= ta.rma(ta.tr, len)
- plus= fixnan(100*ta.rma(plusDM, len) /truerange)
- minus= fixnan(100* ta.rma(minusDM, len)/ truerange)
- [plus, minus]
- adx(dilen, adxlen)=>
- [plus, minus]= dirmov(dilen)
- sum = plus + minus
- adx = 100* ta.rma(math.abs(plus - minus) / (sum == 0?1:sum), adxlen)
- sig=adx(di_len, adx_len)
- // ----------------------------
- // Long/Short Entry Conditions
- // ----------------------------
- adx_entry_condition = input.int(25)
- el_cond = ta.crossover(cog_value, signal_value) and sig < adx_entry_condition
- es_cond = ta.crossunder(cog_value, signal_value) and sig < adx_entry_condition
- // --------------------------
- // Plots
- // --------------------------
- plotshape(el_cond, location.belowbar, color=color.green)
- plotshape(es_cond, location.abovebar, color=color.red)
- if el_cond
- strategy.entry("EL", strategy.long)
- if es_cond
- strategy.entry("ES", strategy.short)
- // -------------------------------
- // Long Exit Conditions and Orders
- // -------------------------------
- xl_mfi_cond = input.int(90)
- xl_cond = ta.crossover(mfi, xl_mfi_cond)
- xl_sl_percent = input.float(2, step=0.5)
- xl_tp_percent = input.float(20, step=0.5)
- xl_sl_price = strategy.position_avg_price * (1-xl_sl_percent/100)
- xl_tp_price = strategy.position_avg_price * (1+xl_tp_percent/100)
- xl_ts_percent = input.float(1, step=0.1)
- xl_to_percent = input.float(0.5, step=0.1)
- xl_ts_tick = xl_ts_percent * close/syminfo.mintick/100
- xl_to_tick = xl_to_percent * close/syminfo.mintick/100
- strategy.exit("XL+SL/TP", "EL", stop=xl_sl_price, limit=xl_tp_price, trail_points=xl_ts_tick, trail_offset=xl_to_tick)
- if xl_cond
- strategy.close("EL")
- // --------------------------------
- // Short Exit Conditions and Orders
- // --------------------------------
- xs_rsi_cond = input.int(18)
- xs_cond = ta.crossunder(rsi, xs_rsi_cond)
- xs_sl_percent = input.float(2,step=0.5)
- xs_tp_percent = input.float(20,step=0.5)
- xs_sl_price = strategy.position_avg_price * (1+xs_sl_percent/100)
- xs_tp_price = strategy.position_avg_price * (1-xs_tp_percent/100)
- xs_ts_percent = input.float(1, step=0.1)
- xs_to_percent = input.float(0.5, step=0.1)
- xs_ts_tick = xs_ts_percent * close/syminfo.mintick/100
- xs_to_tick = xs_to_percent * close/syminfo.mintick/100
- strategy.exit("XS-SL/TP", "ES", stop=xs_sl_price, limit=xs_tp_price, trail_points=xs_ts_tick, trail_offset=xs_to_tick)
- if xs_cond
- strategy.close("ES")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement