Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © hibana2077
- //@version=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)
- //def and input
- source = close
- mg0 = 0.0
- mg1 = 0.0
- mg2 = 0.0
- mg3 = 0.0
- mg4 = 0.0
- mg5 = 0.0
- mg6 = 0.0
- mg7 = 0.0
- mg8 = 0.0
- length = input.int(20, minval=1)
- src = input(hlc3, title="Source")
- p = input.int(10, minval=1)
- x = input.int(1, minval=1)
- q = input.int(9, minval=1)
- n = input.int(120,title="Basic guides line")
- trail_points= input.int(6, minval=1)
- trail_offset= input.int(1, minval=1)
- //McGinley
- mg0 := na(mg0[1]) ? ta.ema(source, 2) : mg0[1] + (source - mg0[1]) / (2 * math.pow(source/mg0[1], 4))
- mg1 := na(mg1[1]) ? ta.ema(source, 3) : mg1[1] + (source - mg1[1]) / (3 * math.pow(source/mg1[1], 4))
- mg2 := na(mg2[1]) ? ta.ema(source, 5) : mg2[1] + (source - mg2[1]) / (5 * math.pow(source/mg2[1], 4))
- mg3 := na(mg3[1]) ? ta.ema(source, 8) : mg3[1] + (source - mg3[1]) / (8 * math.pow(source/mg3[1], 4))
- mg4 := na(mg4[1]) ? ta.ema(source, 13) : mg4[1] + (source - mg4[1]) / (13 * math.pow(source/mg4[1], 4))
- mg5 := na(mg5[1]) ? ta.ema(source, 21) : mg5[1] + (source - mg5[1]) / (21 * math.pow(source/mg5[1], 4))
- mg6 := na(mg6[1]) ? ta.ema(source, 34) : mg6[1] + (source - mg6[1]) / (34 * math.pow(source/mg6[1], 4))
- mg7 := na(mg7[1]) ? ta.ema(source, 55) : mg7[1] + (source - mg7[1]) / (55 * math.pow(source/mg7[1], 4))
- mg8 := na(mg8[1]) ? ta.ema(source, 89) : mg8[1] + (source - mg8[1]) / (89 * math.pow(source/mg8[1], 4))
- //stop and take
- first_high_stop = ta.highest(high, p) - x * ta.atr(p)
- first_low_stop = ta.lowest(low, p) + x * ta.atr(p)
- stop_short = ta.highest(first_high_stop, q)
- stop_long = ta.lowest(first_low_stop, q)
- //plot
- plot(mg0,color=color.fuchsia)
- plot(mg1,color=color.fuchsia)
- plot(mg2,color=color.fuchsia)
- plot(mg3,color=color.fuchsia)
- plot(mg4,color=color.fuchsia)
- plot(mg5,color=color.fuchsia)
- plot(mg6,color=color.fuchsia)
- plot(mg7,color=color.fuchsia)
- plot(mg8,color=color.fuchsia)
- plot(stop_long, color=#2962FF)
- plot(stop_short, color=#FF6D00)
- //cci
- ma = ta.sma(src, length)
- cci = (src - ma) / (0.015 * ta.dev(src, length))
- //single
- 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
- 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
- //order
- if not strategy.opentrades
- // Long Strategy
- if BUY
- strategy.entry("Long", strategy.long)
- strategy.exit("exit", "Long", stop=stop_long, trail_points=trail_points, trail_offset=trail_offset)
- // Short Strategy
- if SELL
- strategy.entry("Short", strategy.short)
- strategy.exit("exit","Short", stop=stop_short, trail_points=trail_points, trail_offset=trail_offset)
Advertisement
Add Comment
Please, Sign In to add comment