Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=2
- /////// !!! COMMENT OUT THIS TO USE STUDY !!! //
- strategy(title="GM-BAC v1.4",pyramiding=2,initial_capital=1000000,default_qty_type=strategy.percent_of_equity,default_qty_value=30,commission_type=strategy.commission.percent,commission_value=0.0)
- /////// ><><><><><><><><><><><><><><><><><><><><>< //
- /////// !!! COMMENT OUT THIS TO USE STRATEGY !!! //
- //study(title="GM-SIG v1.4 *LIVE*",overlay=false) //
- /////// ><><><><><><><><><><><><><><><><><><><><>< //
- ///////////////////////////////////////////////
- // PARAMETERS
- ///////////////////////////////////////////////
- // Default parameter set for Bitmex Perpetual Futures at 15m interval
- x = input("https://www.tradingview.com/script/oA3U7pok-GODMODE-OSCILLATOR-FRESH-BREAD-GENERATOR-FREE-TO-USE/", title="><><><> GODMODE <><><><")
- n1 = input(9, "GM Channel Length")
- n2 = input(26, "GM Average Length")
- n3 = input(11, "GM Short Length")
- n4 = input(8, "GM RSI Length")
- xx= input("https://www.thebalance.com/how-to-trade-with-the-momentum-indicator-1031195", title="><><><> MOM <><><><")
- mofilt = input(true, "Momentum reversal entry filter?")
- n5 = input(10, "MOM Length")
- n6 = input(5, "MOM EMA short")
- n7 = input(7, "MOM EMA long")
- xxx = input("https://www.thebalance.com/directional-movement-index-dmi-1031185", title="><><><> DMI ADX <><><><")
- trendfilt = input(true, "ADX trade direction filter?")
- adxlen = input(14, "ADXLength")
- adxemalen = input(30, "EMA")
- xxxx = input("https://www.thebalance.com/how-average-true-range-atr-can-improve-trading-4154923", title="><><><> ATR <><><><")
- volfilt = input(true, "Countertrend scalping in high volatility?")
- onlyvolfilt = input(false,"ONLY ever trade during volatile periods?")
- atrbaselen = input(500, "Volatility Baseline Length")
- atrlen = input(30, "Volatility signal Length")
- xxxxx= input("*", title="><><><> TRADES <><><><")
- longOK = input(true, "Long trades")
- longopen = input(18, "Long open line")
- longclose = input(80, "Long close line")
- shortOK = input(true, "Short trades")
- shortopen = input(90, "Short open line")
- shortclose = input(19, "Short close line")
- xxxxxx = input("*", title="><><><> DATA <><><><")
- multi = input(true, title="Additional exchange data?")
- m1 = input("BITFINEX:BTCUSD", title="Market 1")
- m2 = input("BITSTAMP:BTCUSD", title="Market 2")
- m3 = input("BITFLYER:BTCJPY", title="Market 3")
- m4 = input("BITHUMB:BTCKRW", title="Market 4")
- ///////////////////////////////////////////////
- // BTC MULTI MARKET DATA
- ///////////////////////////////////////////////
- src0 = hlc3
- src1 = security(m1, period, src0), src2 = security(m2, period, src0)
- src3 = security(m3, period, src0), src4 = security(m4, period, src0)
- srcavg = multi?avg(src0,src1,src2,src3,src4):src0
- ///////////////////////////////////////////////
- // GODMODE INDICATOR
- ///////////////////////////////////////////////
- tci(src) => ema((src - ema(src, n1)) / (0.025 * ema(abs(src - ema(src, n1)), n1)), n2)+50
- mf(src) => rsi(sum(volume * (change(src) <= 0 ? 0 : src), n3), sum(volume * (change(src) >= 0 ? 0 : src), n3))
- willy(src) => 60 * (src - highest(src, n2)) / (highest(src, n2) - lowest(src, n2)) + 80
- csi(src) => avg(rsi(src, n3),tsi(src0,n1,n2)*50+50)
- godmode(src) => avg(tci(src),csi(src),mf(src),willy(src))
- tradition(src) => avg(tci(src),mf(src),rsi(src, n3))
- wt1 = multi?avg(godmode(src0),godmode(src1),godmode(src2),godmode(src3),godmode(src4)):tradition(src0)
- wt2 = sma(wt1,6)
- wt3 = rsi(wt2,n4)
- extended = wt2<20 ? wt3+5 : wt2>80 ? wt3-5 : na
- ///////////////////////////////////////////////
- // MARKET CONDITION INDICATORS
- ///////////////////////////////////////////////
- // MOMENTUM
- mom = mom(src0,n5)/6
- ema1 = ema(mom,n6)
- ema2 = ema(mom,n7)
- momup = ema1 > ema2
- // AVERAGE TRUE RANGE VOLATILITY
- volrange = ema(tr, atrlen)
- volbase = ema(tr, atrbaselen)
- vol = volrange > volbase
- volscalp = (volfilt and vol)
- // AVERAGE DIRECTIONAL INDEX
- TrueRange = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1])))
- DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0
- DirectionalMovementMinus = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0
- SmoothedTrueRange = nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/adxlen) + TrueRange
- SmoothedDirectionalMovementPlus = nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1])/adxlen) + DirectionalMovementPlus
- SmoothedDirectionalMovementMinus = nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1])/adxlen) + DirectionalMovementMinus
- DIPlus = ema(SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100,adxemalen)
- DIMinus = ema(SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100,adxemalen)
- DIPlusEMA = DIPlus
- DIMinusEMA = DIMinus
- trendup = DIPlusEMA > DIMinusEMA
- ///////////////////////////////////////////////
- // TRADE ENTRY / EXIT CONDITIONS
- ///////////////////////////////////////////////
- // BUYS
- bc1 = crossover(wt3,longopen)
- bc2 = (not mofilt or momup) and ((not trendfilt or trendup) or volscalp)
- buy = bc1 and bc2 and longOK
- buysig = buy and (not onlyvolfilt or vol)
- // SELLS
- sc1 = crossunder(wt3,shortopen)
- sc2 = (not mofilt or not momup) and ((not trendfilt or not trendup) or volscalp)
- sell = sc1 and sc2 and shortOK
- sellsig = sell and (not onlyvolfilt or vol)
- // EXITS
- posclosesig = buysig ? -100 : sellsig ? 100 : 0 // study doesn't track positions like a strategy does, this creates a signal to let it know
- poscloseema = ema(posclosesig,30) // ema prevents signal line from returning to 0 for duration of position
- closelong = crossover(wt3,longclose) and poscloseema < 0
- closeshort = crossunder(wt3,shortclose) and poscloseema > 0
- ///////////////////////////////////////////////
- // PLOTS
- ///////////////////////////////////////////////
- // ADX
- dp = plot(DIPlusEMA+30,color=green,title="ADX Plus")
- dm = plot(DIMinusEMA+30,color=red,title="ADX Minus")
- trendcolor = DIPlusEMA > DIMinusEMA ? green : red
- fill(dp,dm,color=trendcolor,transp=70)
- // ATR
- plotshape(vol, style=shape.cross,location=location.bottom,size=size.tiny,color=yellow,title="volatility true",transp=40)
- // TRIGGER LEVELS
- hline(longopen, color=lime,title="long entry")
- hline(longclose, title="long close")
- hline(shortopen, color=red,title="short entry")
- hline(shortclose, title="short close")
- // TRADE MARKERS
- buymark = buysig ? wt3 : na
- sellmark = sellsig ? wt3 : na
- closelongmark = closelong ? wt3 : na
- closeshortmark = closeshort ? wt3 : na
- plotshape(buymark, style=shape.flag, location=location.absolute,size=size.small,color=lime,text="buy",title="buy condition")
- plotshape(sellmark, style=shape.flag, location=location.absolute,size=size.small,color=yellow,text="short",title="short condition")
- plotshape(closelongmark, style=shape.diamond,location=location.absolute,size=size.small,color=aqua,text="",title="exit buy condition")
- plotshape(closeshortmark, style=shape.diamond,location=location.absolute,size=size.small,color=orange,text="",title="exit short condition")
- // SIGNAL LINE
- momcolor = momup ? aqua : orange // MOM EMA based signal line color
- plot(wt3,color=momcolor,title="GM RSI",lineWidth=2,transp=10)
- plot(extended, title="Caution!", color=fuchsia, style=circles, linewidth=3)
- /////// ><><><><><><><><><><><><><><><><><><><><>< ////////////////////////////////////////////
- /////// !!! COMMENT OUT ALL OF BELOW FOR STUDY !!! ////////////////////////////////////////////
- /////// ><><><><><><><><><><><><><><><><><><><><>< ////////////////////////////////////////////
- ///////////////////////////////////////////////
- // BACKTEST TIME WINDOW
- ///////////////////////////////////////////////
- xxxxxxx = input("><><><><><><",title="><><><> BACKTEST PERIOD <><><><")
- testStartYear = input(2018, "Backtest Start Year")
- testStartMonth = input(1, "Backtest Start Month")
- testStartDay = input(1, "Backtest Start Day")
- testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
- testStopYear = input(2018, "Backtest Stop Year")
- testStopMonth = input(3, "Backtest Stop Month")
- testStopDay = input(1, "Backtest Stop Day")
- testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)
- testPeriod() =>
- time >= testPeriodStart and time <= testPeriodStop
- ///////////////////////////////////////////////
- // STRATEGY ENTRY EXITS
- ///////////////////////////////////////////////
- if testPeriod()
- strategy.entry("Long", strategy.long, when = buysig)
- strategy.close("Long", when = closelong )
- strategy.entry("Short", strategy.short, when = sellsig)
- strategy.close("Short", when = closeshort )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement