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/
- // © sunw31
- //@version=4
- study("Real Scalping God",overlay = true)
- var color longColor = color.green
- var color shortColor = color.red
- // PSAR
- start = input(title="Start", type=input.float, step=0.001, defval=0.02)
- increment = input(title="Increment", type=input.float, step=0.001, defval=0.02)
- maximum = input(title="Maximum", type=input.float, step=0.01, defval=0.2)
- width = input(title="Point Width", type=input.integer, minval=1, defval=2)
- highlightStartPoints = input(title="Highlight Start Points ?", type=input.bool, defval=true)
- psar = sar(start, increment, maximum)
- dir_psar = psar < close ? 1 : -1
- psarColor = dir_psar == 1 ? #3388bb : #fdcc02
- 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)
- 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)
- // supertrend
- length = input(title="ATR Period", type=input.integer, defval=22)
- mult = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3)
- src = input(title="Source", type=input.source, defval=hl2)
- wicks = input(title="Take Wicks into Account ?", type=input.bool, defval=true)
- atr = mult * atr(length)
- highPrice = wicks ? high : close
- lowPrice = wicks ? low : close
- doji4price = open == close and open == low and open == high
- longStop = src - atr
- longStopPrev = nz(longStop[1], longStop)
- if longStop > 0
- if doji4price
- longStop := longStopPrev
- else
- longStop := (lowPrice[1] > longStopPrev ? max(longStop, longStopPrev) : longStop)
- else
- longStop := longStopPrev
- shortStop = src + atr
- shortStopPrev = nz(shortStop[1], shortStop)
- if shortStop > 0
- if doji4price
- shortStop := shortStopPrev
- else
- shortStop := (highPrice[1] < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop)
- else
- shortStop := shortStopPrev
- var int dir_supertrend = 1
- dir_supertrend :=
- dir_supertrend == -1 and highPrice > shortStopPrev ? 1 :
- dir_supertrend == 1 and lowPrice < longStopPrev ? -1 :
- dir_supertrend
- buySignal_supertrend = dir_supertrend == 1 and dir_supertrend[1] == -1
- plotshape(buySignal_supertrend ? longStop : na, title="Long Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=longColor, transp=0)
- sellSignal_supertrend = dir_supertrend == -1 and dir_supertrend[1] == 1
- plotshape(sellSignal_supertrend ? shortStop : na, title="Short Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=shortColor, transp=0)
- // halftrend
- amplitude = input(title="Amplitude", defval=2)
- channelDeviation = input(title="Channel Deviation", defval=2)
- showArrows = input(title="Show Arrows", defval=true)
- showChannels = input(title="Show Channels", defval=true)
- var int trend = 0
- var int nextTrend = 0
- var float maxLowPrice = nz(low[1], low)
- var float minHighPrice = nz(high[1], high)
- var float up = 0.0
- var float down = 0.0
- float atrHigh = 0.0
- float atrLow = 0.0
- float arrowUp = na
- float arrowDown = na
- atr2 = atr(100) / 2
- dev = channelDeviation * atr2
- highPrice_halftrend = high[abs(highestbars(amplitude))]
- lowPrice_halftrend = low[abs(lowestbars(amplitude))]
- highma = sma(high, amplitude)
- lowma = sma(low, amplitude)
- if nextTrend == 1
- maxLowPrice := max(lowPrice_halftrend, maxLowPrice)
- if highma < maxLowPrice and close < nz(low[1], low)
- trend := 1
- nextTrend := 0
- minHighPrice := highPrice_halftrend
- else
- minHighPrice := min(highPrice_halftrend, minHighPrice)
- if lowma > minHighPrice and close > nz(high[1], high)
- trend := 0
- nextTrend := 1
- maxLowPrice := lowPrice_halftrend
- if trend == 0
- if not na(trend[1]) and trend[1] != 0
- up := na(down[1]) ? down : down[1]
- arrowUp := up - atr2
- else
- up := na(up[1]) ? maxLowPrice : max(maxLowPrice, up[1])
- atrHigh := up + dev
- atrLow := up - dev
- else
- if not na(trend[1]) and trend[1] != 1
- down := na(up[1]) ? up : up[1]
- arrowDown := down + atr2
- else
- down := na(down[1]) ? minHighPrice : min(minHighPrice, down[1])
- atrHigh := down + dev
- atrLow := down - dev
- ht = trend == 0 ? up : down
- buySignal_halftrend = not na(arrowUp) and (trend == 0 and trend[1] == 1)
- sellSignall_halftrend = not na(arrowDown) and (trend == 1 and trend[1] == 0)
- plotshape(showArrows and buySignal_halftrend ? atrLow : na, title="Arrow Up", style=shape.triangleup, location=location.absolute, size=size.tiny, color=longColor)
- plotshape(showArrows and sellSignall_halftrend ? atrHigh : na, title="Arrow Down", style=shape.triangledown, location=location.absolute, size=size.tiny, color=shortColor)
- // chandelier exit
- useClose = input(title="Use Close Price for Extremums ?", type=input.bool, defval=true)
- longStop_chandelier = (useClose ? highest(close, length) : highest(length)) - atr
- longStopPrev_chandelier = nz(longStop_chandelier[1], longStop_chandelier)
- longStop_chandelier := close[1] > longStopPrev_chandelier ? max(longStop_chandelier, longStopPrev_chandelier) : longStop_chandelier
- shortStop_chandelier = (useClose ? lowest(close, length) : lowest(length)) + atr
- shortStopPrev_chandelier = nz(shortStop_chandelier[1], shortStop_chandelier)
- shortStop_chandelier := close[1] < shortStopPrev_chandelier ? min(shortStop_chandelier, shortStopPrev_chandelier) : shortStop_chandelier
- var int dir_chandelier = 1
- dir_chandelier := close > shortStopPrev_chandelier ? 1 : close < longStopPrev_chandelier ? -1 : dir_chandelier
- 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)
- 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)
- // nrtr
- k = input(title="Coefficient of Correction, %", type=input.float, minval=0, maxval=100, step=0.1, defval=2)
- applyRibbon = input(title="Apply Ribbon ?", type=input.bool, defval=true)
- var int trend_nrtr = 0
- var float hp = close
- var float lp = close
- float nrtr = close
- percentage = k * 0.01
- if trend_nrtr >= 0
- if close > hp
- hp := close
- hp
- nrtr := hp * (1 - percentage)
- if close <= nrtr
- trend_nrtr := -1
- lp := close
- nrtr := lp * (1 + percentage)
- nrtr
- else
- if close < lp
- lp := close
- lp
- nrtr := lp * (1 + percentage)
- if close > nrtr
- trend_nrtr := 1
- hp := close
- nrtr := hp * (1 - percentage)
- nrtr
- 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)
- 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)
Advertisement
Add Comment
Please, Sign In to add comment