Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //@version=2
  2.  
  3. /////// !!!   COMMENT OUT THIS TO USE STUDY   !!!  //
  4. 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)
  5. /////// ><><><><><><><><><><><><><><><><><><><><>< //
  6.  
  7. /////// !!!  COMMENT OUT THIS TO USE STRATEGY  !!! //
  8. //study(title="GM-SIG v1.4 *LIVE*",overlay=false)  //
  9. /////// ><><><><><><><><><><><><><><><><><><><><>< //    
  10.  
  11.  
  12. ///////////////////////////////////////////////
  13. // PARAMETERS
  14. ///////////////////////////////////////////////
  15.  
  16. // Default parameter set for Bitmex Perpetual Futures at 15m interval
  17.  
  18. x =         input("https://www.tradingview.com/script/oA3U7pok-GODMODE-OSCILLATOR-FRESH-BREAD-GENERATOR-FREE-TO-USE/",  title="><><><> GODMODE <><><><")
  19. n1 =            input(9,    "GM Channel Length")
  20. n2 =            input(26,   "GM Average Length")
  21. n3 =            input(11,   "GM Short Length")
  22. n4 =            input(8,    "GM RSI Length")
  23.  
  24. xx=         input("https://www.thebalance.com/how-to-trade-with-the-momentum-indicator-1031195",  title="><><><> MOM <><><><")
  25. mofilt =        input(true, "Momentum reversal entry filter?")
  26. n5 =            input(10,   "MOM Length")
  27. n6 =            input(5,    "MOM EMA short")
  28. n7 =            input(7,    "MOM EMA long")
  29.  
  30. xxx =       input("https://www.thebalance.com/directional-movement-index-dmi-1031185",  title="><><><> DMI ADX <><><><")
  31. trendfilt =      input(true, "ADX trade direction filter?")
  32. adxlen =        input(14,   "ADXLength")
  33. adxemalen =     input(30,   "EMA")
  34.  
  35. xxxx =      input("https://www.thebalance.com/how-average-true-range-atr-can-improve-trading-4154923",  title="><><><> ATR <><><><")
  36. volfilt =       input(true, "Countertrend scalping in high volatility?")
  37. onlyvolfilt =   input(false,"ONLY ever trade during volatile periods?")
  38. atrbaselen =    input(500,  "Volatility Baseline Length")
  39. atrlen =        input(30,   "Volatility signal Length")
  40.  
  41. xxxxx=      input("*",  title="><><><> TRADES <><><><")
  42. longOK =        input(true, "Long trades")
  43. longopen =      input(18,   "Long open line")
  44. longclose =     input(80,   "Long close line")
  45. shortOK =       input(true, "Short trades")
  46. shortopen =     input(90,   "Short open line")
  47. shortclose =    input(19,   "Short close line")
  48.  
  49. xxxxxx =    input("*",  title="><><><> DATA <><><><")
  50. multi =         input(true, title="Additional exchange data?")
  51. m1 =            input("BITFINEX:BTCUSD",    title="Market 1")
  52. m2 =            input("BITSTAMP:BTCUSD",    title="Market 2")
  53. m3 =            input("BITFLYER:BTCJPY",    title="Market 3")
  54. m4 =            input("BITHUMB:BTCKRW",     title="Market 4")
  55.  
  56.  
  57. ///////////////////////////////////////////////
  58. // BTC MULTI MARKET DATA
  59. ///////////////////////////////////////////////
  60.  
  61. src0 =      hlc3
  62. src1 =      security(m1, period, src0), src2 = security(m2, period, src0)
  63. src3 =      security(m3, period, src0), src4 = security(m4, period, src0)
  64. srcavg =    multi?avg(src0,src1,src2,src3,src4):src0
  65.  
  66.  
  67. ///////////////////////////////////////////////
  68. // GODMODE INDICATOR
  69. ///////////////////////////////////////////////
  70.  
  71. tci(src) =>         ema((src - ema(src, n1)) / (0.025 * ema(abs(src - ema(src, n1)), n1)), n2)+50
  72. mf(src) =>          rsi(sum(volume * (change(src) <= 0 ? 0 : src), n3), sum(volume * (change(src) >= 0 ? 0 : src), n3))
  73. willy(src) =>       60 * (src - highest(src, n2)) / (highest(src, n2) - lowest(src, n2)) + 80
  74. csi(src) =>         avg(rsi(src, n3),tsi(src0,n1,n2)*50+50)
  75. godmode(src) =>     avg(tci(src),csi(src),mf(src),willy(src))
  76. tradition(src) =>   avg(tci(src),mf(src),rsi(src, n3))
  77. wt1 =               multi?avg(godmode(src0),godmode(src1),godmode(src2),godmode(src3),godmode(src4)):tradition(src0)
  78. wt2 =               sma(wt1,6)
  79. wt3 =               rsi(wt2,n4)
  80. extended =          wt2<20 ? wt3+5 : wt2>80 ? wt3-5 : na
  81.  
  82.  
  83. ///////////////////////////////////////////////
  84. // MARKET CONDITION INDICATORS
  85. ///////////////////////////////////////////////
  86.  
  87. // MOMENTUM
  88. mom =           mom(src0,n5)/6
  89. ema1 =          ema(mom,n6)
  90. ema2 =          ema(mom,n7)
  91. momup =         ema1 > ema2
  92.  
  93. // AVERAGE TRUE RANGE VOLATILITY
  94. volrange =      ema(tr, atrlen)
  95. volbase =       ema(tr, atrbaselen)
  96. vol =           volrange > volbase
  97. volscalp =      (volfilt and vol)
  98.  
  99. // AVERAGE DIRECTIONAL INDEX
  100. TrueRange =                         max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1])))
  101. DirectionalMovementPlus =           high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0
  102. DirectionalMovementMinus =          nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0
  103. SmoothedTrueRange =                 nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/adxlen) + TrueRange
  104. SmoothedDirectionalMovementPlus =   nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1])/adxlen) + DirectionalMovementPlus
  105. SmoothedDirectionalMovementMinus =  nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1])/adxlen) + DirectionalMovementMinus
  106. DIPlus =                            ema(SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100,adxemalen)
  107. DIMinus =                           ema(SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100,adxemalen)
  108. DIPlusEMA =                         DIPlus
  109. DIMinusEMA =                        DIMinus
  110. trendup =                           DIPlusEMA > DIMinusEMA
  111.  
  112.  
  113. ///////////////////////////////////////////////
  114. // TRADE ENTRY / EXIT CONDITIONS
  115. ///////////////////////////////////////////////
  116.  
  117. // BUYS
  118. bc1 =           crossover(wt3,longopen)
  119. bc2 =           (not mofilt or momup) and ((not trendfilt or trendup) or volscalp)
  120. buy =           bc1 and bc2 and longOK
  121. buysig =        buy and (not onlyvolfilt or vol)
  122.  
  123. // SELLS
  124. sc1 =           crossunder(wt3,shortopen)
  125. sc2 =           (not mofilt or not momup) and ((not trendfilt or not trendup) or volscalp)
  126. sell =          sc1 and sc2 and shortOK
  127. sellsig =       sell and (not onlyvolfilt or vol)
  128.  
  129. // EXITS
  130. posclosesig =   buysig ? -100 : sellsig ? 100 : 0 // study doesn't track positions like a strategy does, this creates a signal to let it know
  131. poscloseema =   ema(posclosesig,30) // ema prevents signal line from returning to 0 for duration of position
  132. closelong =     crossover(wt3,longclose) and poscloseema < 0
  133. closeshort =    crossunder(wt3,shortclose) and poscloseema > 0
  134.  
  135.  
  136. ///////////////////////////////////////////////
  137. // PLOTS
  138. ///////////////////////////////////////////////
  139.  
  140. // ADX
  141. dp =                plot(DIPlusEMA+30,color=green,title="ADX Plus")
  142. dm =                plot(DIMinusEMA+30,color=red,title="ADX Minus")
  143. trendcolor =        DIPlusEMA > DIMinusEMA ? green : red
  144. fill(dp,dm,color=trendcolor,transp=70)
  145.  
  146. // ATR
  147. plotshape(vol,      style=shape.cross,location=location.bottom,size=size.tiny,color=yellow,title="volatility true",transp=40)
  148.  
  149. // TRIGGER LEVELS
  150. hline(longopen,     color=lime,title="long entry")
  151. hline(longclose,    title="long close")
  152. hline(shortopen,    color=red,title="short entry")
  153. hline(shortclose,   title="short close")
  154.  
  155. // TRADE MARKERS
  156. buymark =           buysig      ? wt3 : na
  157. sellmark =          sellsig     ? wt3 : na
  158. closelongmark =     closelong   ? wt3 : na
  159. closeshortmark =    closeshort  ? wt3 : na
  160.  
  161. plotshape(buymark,          style=shape.flag,   location=location.absolute,size=size.small,color=lime,text="buy",title="buy condition")
  162. plotshape(sellmark,         style=shape.flag,   location=location.absolute,size=size.small,color=yellow,text="short",title="short condition")
  163. plotshape(closelongmark,    style=shape.diamond,location=location.absolute,size=size.small,color=aqua,text="",title="exit buy condition")
  164. plotshape(closeshortmark,   style=shape.diamond,location=location.absolute,size=size.small,color=orange,text="",title="exit short condition")
  165.  
  166. // SIGNAL LINE
  167. momcolor = momup ? aqua : orange // MOM EMA based signal line color
  168. plot(wt3,color=momcolor,title="GM RSI",lineWidth=2,transp=10)
  169. plot(extended, title="Caution!", color=fuchsia, style=circles, linewidth=3)
  170.  
  171.  
  172. /////// ><><><><><><><><><><><><><><><><><><><><>< ////////////////////////////////////////////
  173. /////// !!! COMMENT OUT ALL OF BELOW FOR STUDY !!! ////////////////////////////////////////////
  174. /////// ><><><><><><><><><><><><><><><><><><><><>< ////////////////////////////////////////////
  175.  
  176. ///////////////////////////////////////////////
  177. // BACKTEST TIME WINDOW
  178. ///////////////////////////////////////////////
  179.  
  180. xxxxxxx =           input("><><><><><><",title="><><><> BACKTEST PERIOD <><><><")
  181. testStartYear =     input(2018, "Backtest Start Year")
  182. testStartMonth =    input(1, "Backtest Start Month")
  183. testStartDay =      input(1, "Backtest Start Day")
  184. testPeriodStart =   timestamp(testStartYear,testStartMonth,testStartDay,0,0)
  185.  
  186. testStopYear =      input(2018, "Backtest Stop Year")
  187. testStopMonth =     input(3, "Backtest Stop Month")
  188. testStopDay =       input(1, "Backtest Stop Day")
  189. testPeriodStop =    timestamp(testStopYear,testStopMonth,testStopDay,0,0)
  190. testPeriod() =>
  191.     time >= testPeriodStart and time <= testPeriodStop
  192.  
  193.  
  194. ///////////////////////////////////////////////
  195. // STRATEGY ENTRY EXITS
  196. ///////////////////////////////////////////////
  197.  
  198. if testPeriod()
  199.     strategy.entry("Long", strategy.long, when = buysig)
  200.     strategy.close("Long", when = closelong )
  201.  
  202.     strategy.entry("Short", strategy.short, when = sellsig)
  203.     strategy.close("Short", when = closeshort )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement