Advertisement
JustUncleL

[STRATEGY]Price Action Trading System

Apr 13th, 2017
1,551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.19 KB | None | 0 0
  1. //@version=3
  2.  
  3. strategy(title="[STRATEGY]Price Action Trading System v0.2 by JustUncleL",overlay = true, shorttitle="[STRATEGY]CCIPAT v0.2 by JustUncleL")
  4.  
  5. //Created By: JustUncleL on 3 Aug 2016
  6. //Version: 0.1
  7. //
  8. //Description:
  9. // Strategy version:
  10. // This is an implementation of 'Price Action Channel, “The Gold line” Trading System'
  11. // for Binary Options, originally a scapling system, but without the MA cross "Arrow1".
  12. // This is a Trend following price action system.
  13. // To complete the setup instead of the two "Chandelier Stop" indications,
  14. // I replaced them with a MACD(12,17,8) indicator.
  15. // This is suitable for 15min charts, with 2 to 4 candle (30min to 60min) expiry.
  16. //
  17. // Call Entry:
  18. // - Green Triangle, confirmed by MACD background green.
  19. // - CCI Candles aqua.
  20. // - For best call entry wait for the price retrace back to the gold line,
  21. // back inside channel also works well.
  22. //
  23. // Put Entry:
  24. // - Red Triangle, confirmed by MACD background red.
  25. // - CCI Candles black.
  26. // - For best put entry wait for the price retrace on the gold line,
  27. // back inside channel also works well.
  28. //
  29. //Notes:
  30. // - will work well on trending patterns only.
  31. // - works best on the first alert after MACD cross over.
  32. // - don't take trades when MACD and signal are close together.
  33. //
  34. //Modifications:
  35. // 0.1 : Original version.
  36. //
  37. // reference:
  38. // - Chandelier Stop by pipCharlie (not used in this version)
  39. // - http://www.forexstrategiesresources.com/scalping-forex-strategies/73-price-action-channel-the-gold-line/
  40. // - Used some ideas from RSI Candles by glaz
  41. //
  42. //
  43. len = input(14, minval=1, title="CCI Length")
  44. lenUpper = input(75, minval=1, title="CCI UpLevel")
  45. lenLower = input(-75, maxval=-1, title="CCI DownLevel")
  46. bars_on = input(true, title="Color CCI Bars")
  47. src = input(close,title="CCI Source")
  48. lenLo = input(5, minval=2, title="Low Channel Length")
  49. lenHi = input(5, minval=2, title="High Channel Length")
  50. lenMe = input(4, minval=1, title="Median Channel Length")
  51. //
  52. fastLength = input(12, minval=1,title="MACD Fast Length")
  53. slowLength=input(17,minval=1,title="MACD Slow Length")
  54. signalLength=input(8,minval=1,title="MACD Signal Length")
  55. //
  56. // Calculate MACD and color background
  57. fastMC = ema(src, fastLength)
  58. slowMC = ema(src, slowLength)
  59. macd = fastMC - slowMC
  60. signal = sma(macd, signalLength)
  61. OutputSignal = signal > macd ? 1 : signal < macd ? -1 : 0
  62. bgcolor(OutputSignal>0?red: OutputSignal<0?green:yellow, transp=90)
  63.  
  64. // Calculate and draw the Price Action channel
  65. emaLo = ema(low,lenLo)
  66. emaHi = ema(high,lenHi)
  67. emaMe = ema(hl2,lenMe)
  68. plot(emaLo,title="Low Price Line",style=line,color=gray,transp=0,linewidth=2)
  69. plot(emaHi,title="High Price Line",style=line,color=gray,transp=0,linewidth=2)
  70. plot(emaMe,title="Median Price Line",style=line,color=orange,transp=0,linewidth=2)
  71.  
  72. // Calculate CCI
  73. cciVal = cci(src, len)
  74.  
  75. // Calculate CCI indicating continuance of trend.
  76. isup = cciVal > lenUpper
  77. isdown = cciVal < lenLower
  78. barcolor(bars_on ? isup ? aqua : isdown ? black : na : na)
  79.  
  80. // Check have alert and use MACD filter
  81. cciup_alert = 0
  82. ccidn_alert = 0
  83. cciup_alert := isup and OutputSignal<0? na(cciup_alert[1]) ? 1 : cciup_alert[1]+1 : 0
  84. ccidn_alert := isdown and OutputSignal>0? na(ccidn_alert[1]) ? 1 : ccidn_alert[1]+1 : 0
  85.  
  86. plotshape(cciup_alert==1? cciup_alert : na, title="CCIPAT Up Arrow", style=shape.triangleup,location=location.belowbar, color=olive, transp=0, size=size.small)
  87. plotshape(ccidn_alert==1? ccidn_alert : na, title="CCIPAT Down Arrow", style=shape.triangledown,location=location.abovebar, color=red, transp=0, size=size.small)
  88.  
  89. // === STRATEGY RELATED INPUTS ===
  90. //
  91. // stop loss and target profit
  92. slPoints = input(defval = 0, title = "Stop Loss Points (zero to disable)", minval = 0)
  93. tpPoints = input(defval = 0, title = "Target Profit Points (zero for disable)", minval = 0)
  94. //
  95. ebar = input(defval = 5000, title="Number of Bars for Back Testing", minval=0)
  96. dummy = input(false, title="- SET to ZERO for Daily or Longer Timeframes" )
  97.  
  98. // Alternative Method to Restrict bars is to use Days since:
  99. // Calculate how many mars since last bar (only works for timeframes less than 1Day)
  100. tdays = (timenow-time)/60000.0 // number of minutes since last bar
  101. tdays := period=='M'? tdays/1440.0/5.0/4.3/interval : period=='W'? tdays/1440.0/5.0/interval : period=='D'? tdays/1440.0/interval : tdays/interval // number of bars since last bar
  102. //Set up money management parameters
  103. TP = tpPoints>0?tpPoints:na
  104. SL = slPoints>0?slPoints:na
  105.  
  106. // === STRATEGY - CLOSE ALL IF TOO MANY CANDLES ===
  107. if (ebar>0 and tdays>ebar)
  108. strategy.close_all()// ...and when to get out
  109.  
  110. // === STRATEGY - LONG AND SHORT POSITION EXECUTION, limit Lookk back to ebars ===
  111. if (ebar==0 or tdays<=ebar)
  112. // Long position
  113. strategy.entry("long", strategy.long, when = cciup_alert==1)
  114. strategy.close("long", when = isdown)
  115. strategy.exit("XL", from_entry = "long", profit = TP, loss = SL)
  116. // Short position
  117. strategy.entry("short", strategy.short, when = ccidn_alert==1)
  118. strategy.close("short", when = isup)
  119. strategy.exit("XS", from_entry = "short", profit = TP, loss = SL)
  120.  
  121. //EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement