xmd79

Real Scalping God

Sep 25th, 2021
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.13 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © sunw31
  3.  
  4. //@version=4
  5. study("Real Scalping God",overlay = true)
  6. var color longColor = color.green
  7. var color shortColor = color.red
  8.  
  9.  
  10. // PSAR
  11. start = input(title="Start", type=input.float, step=0.001, defval=0.02)
  12. increment = input(title="Increment", type=input.float, step=0.001, defval=0.02)
  13. maximum = input(title="Maximum", type=input.float, step=0.01, defval=0.2)
  14. width = input(title="Point Width", type=input.integer, minval=1, defval=2)
  15. highlightStartPoints = input(title="Highlight Start Points ?", type=input.bool, defval=true)
  16.  
  17. psar = sar(start, increment, maximum)
  18. dir_psar = psar < close ? 1 : -1
  19. psarColor = dir_psar == 1 ? #3388bb : #fdcc02
  20.  
  21. plotshape(dir_psar == 1 and dir_psar[1] == -1 and highlightStartPoints ? psar : na, title="Long Start", location=location.absolute, style=shape.circle, size=size.tiny, color=longColor, transp=0)
  22. plotshape(dir_psar == -1 and dir_psar[1] == 1 and highlightStartPoints ? psar : na, title="Short Start", location=location.absolute, style=shape.circle, size=size.tiny, color=shortColor, transp=0)
  23.  
  24.  
  25. // supertrend
  26.  
  27. length = input(title="ATR Period", type=input.integer, defval=22)
  28. mult = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3)
  29. src = input(title="Source", type=input.source, defval=hl2)
  30. wicks = input(title="Take Wicks into Account ?", type=input.bool, defval=true)
  31.  
  32. atr = mult * atr(length)
  33.  
  34. highPrice = wicks ? high : close
  35. lowPrice = wicks ? low : close
  36. doji4price = open == close and open == low and open == high
  37.  
  38. longStop = src - atr
  39. longStopPrev = nz(longStop[1], longStop)
  40.  
  41. if longStop > 0
  42. if doji4price
  43. longStop := longStopPrev
  44. else
  45. longStop := (lowPrice[1] > longStopPrev ? max(longStop, longStopPrev) : longStop)
  46. else
  47. longStop := longStopPrev
  48.  
  49. shortStop = src + atr
  50. shortStopPrev = nz(shortStop[1], shortStop)
  51.  
  52. if shortStop > 0
  53. if doji4price
  54. shortStop := shortStopPrev
  55. else
  56. shortStop := (highPrice[1] < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop)
  57. else
  58. shortStop := shortStopPrev
  59.  
  60. var int dir_supertrend = 1
  61. dir_supertrend :=
  62. dir_supertrend == -1 and highPrice > shortStopPrev ? 1 :
  63. dir_supertrend == 1 and lowPrice < longStopPrev ? -1 :
  64. dir_supertrend
  65.  
  66.  
  67. buySignal_supertrend = dir_supertrend == 1 and dir_supertrend[1] == -1
  68. plotshape(buySignal_supertrend ? longStop : na, title="Long Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=longColor, transp=0)
  69.  
  70. sellSignal_supertrend = dir_supertrend == -1 and dir_supertrend[1] == 1
  71. plotshape(sellSignal_supertrend ? shortStop : na, title="Short Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=shortColor, transp=0)
  72.  
  73.  
  74. // halftrend
  75.  
  76. amplitude = input(title="Amplitude", defval=2)
  77. channelDeviation = input(title="Channel Deviation", defval=2)
  78. showArrows = input(title="Show Arrows", defval=true)
  79. showChannels = input(title="Show Channels", defval=true)
  80.  
  81. var int trend = 0
  82. var int nextTrend = 0
  83. var float maxLowPrice = nz(low[1], low)
  84. var float minHighPrice = nz(high[1], high)
  85.  
  86. var float up = 0.0
  87. var float down = 0.0
  88. float atrHigh = 0.0
  89. float atrLow = 0.0
  90. float arrowUp = na
  91. float arrowDown = na
  92.  
  93. atr2 = atr(100) / 2
  94. dev = channelDeviation * atr2
  95.  
  96. highPrice_halftrend = high[abs(highestbars(amplitude))]
  97. lowPrice_halftrend = low[abs(lowestbars(amplitude))]
  98. highma = sma(high, amplitude)
  99. lowma = sma(low, amplitude)
  100.  
  101. if nextTrend == 1
  102. maxLowPrice := max(lowPrice_halftrend, maxLowPrice)
  103.  
  104. if highma < maxLowPrice and close < nz(low[1], low)
  105. trend := 1
  106. nextTrend := 0
  107. minHighPrice := highPrice_halftrend
  108. else
  109. minHighPrice := min(highPrice_halftrend, minHighPrice)
  110.  
  111. if lowma > minHighPrice and close > nz(high[1], high)
  112. trend := 0
  113. nextTrend := 1
  114. maxLowPrice := lowPrice_halftrend
  115.  
  116. if trend == 0
  117. if not na(trend[1]) and trend[1] != 0
  118. up := na(down[1]) ? down : down[1]
  119. arrowUp := up - atr2
  120. else
  121. up := na(up[1]) ? maxLowPrice : max(maxLowPrice, up[1])
  122. atrHigh := up + dev
  123. atrLow := up - dev
  124. else
  125. if not na(trend[1]) and trend[1] != 1
  126. down := na(up[1]) ? up : up[1]
  127. arrowDown := down + atr2
  128. else
  129. down := na(down[1]) ? minHighPrice : min(minHighPrice, down[1])
  130. atrHigh := down + dev
  131. atrLow := down - dev
  132.  
  133. ht = trend == 0 ? up : down
  134.  
  135.  
  136. buySignal_halftrend = not na(arrowUp) and (trend == 0 and trend[1] == 1)
  137. sellSignall_halftrend = not na(arrowDown) and (trend == 1 and trend[1] == 0)
  138.  
  139. plotshape(showArrows and buySignal_halftrend ? atrLow : na, title="Arrow Up", style=shape.triangleup, location=location.absolute, size=size.tiny, color=longColor)
  140. plotshape(showArrows and sellSignall_halftrend ? atrHigh : na, title="Arrow Down", style=shape.triangledown, location=location.absolute, size=size.tiny, color=shortColor)
  141.  
  142.  
  143. // chandelier exit
  144.  
  145. useClose = input(title="Use Close Price for Extremums ?", type=input.bool, defval=true)
  146.  
  147. longStop_chandelier = (useClose ? highest(close, length) : highest(length)) - atr
  148. longStopPrev_chandelier = nz(longStop_chandelier[1], longStop_chandelier)
  149. longStop_chandelier := close[1] > longStopPrev_chandelier ? max(longStop_chandelier, longStopPrev_chandelier) : longStop_chandelier
  150.  
  151. shortStop_chandelier = (useClose ? lowest(close, length) : lowest(length)) + atr
  152. shortStopPrev_chandelier = nz(shortStop_chandelier[1], shortStop_chandelier)
  153. shortStop_chandelier := close[1] < shortStopPrev_chandelier ? min(shortStop_chandelier, shortStopPrev_chandelier) : shortStop_chandelier
  154.  
  155. var int dir_chandelier = 1
  156. dir_chandelier := close > shortStopPrev_chandelier ? 1 : close < longStopPrev_chandelier ? -1 : dir_chandelier
  157.  
  158. plotshape(dir_chandelier == 1 and dir_chandelier[1] == -1 ? longStop_chandelier : na, title="Long Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=longColor, transp=0)
  159. plotshape(dir_chandelier == -1 and dir_chandelier[1] == 1 ? shortStop_chandelier : na, title="Short Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=shortColor, transp=0)
  160.  
  161.  
  162. // nrtr
  163.  
  164. k = input(title="Coefficient of Correction, %", type=input.float, minval=0, maxval=100, step=0.1, defval=2)
  165. applyRibbon = input(title="Apply Ribbon ?", type=input.bool, defval=true)
  166.  
  167. var int trend_nrtr = 0
  168. var float hp = close
  169. var float lp = close
  170. float nrtr = close
  171.  
  172. percentage = k * 0.01
  173.  
  174. if trend_nrtr >= 0
  175. if close > hp
  176. hp := close
  177. hp
  178. nrtr := hp * (1 - percentage)
  179. if close <= nrtr
  180. trend_nrtr := -1
  181. lp := close
  182. nrtr := lp * (1 + percentage)
  183. nrtr
  184. else
  185. if close < lp
  186. lp := close
  187. lp
  188. nrtr := lp * (1 + percentage)
  189. if close > nrtr
  190. trend_nrtr := 1
  191. hp := close
  192. nrtr := hp * (1 - percentage)
  193. nrtr
  194.  
  195.  
  196. plotshape(trend_nrtr == 1 and trend_nrtr[1] == -1 ? nrtr : na, title="Long Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=longColor, transp=0)
  197. plotshape( trend_nrtr == -1 and trend_nrtr[1] == 1 ? nrtr : na, title="Short Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=shortColor, transp=0)
  198.  
Advertisement
Add Comment
Please, Sign In to add comment