// Calculate the percentage change in price for each bar priceChange = close - close[1] priceChangePercentage = priceChange / close[1] * 100
// Calculate the average volume over the lookback period averageVolume = ta.ema(volume, lookbackPeriod)
// Initialize the counters for upward and downward trends upwardTrends = 0 downwardTrends = 0
// Iterate over the lookback period and count the number of upward and downward trends for i = 1 to lookbackPeriod if priceChangePercentage > 0 upwardTrends := upwardTrends + 1 else if priceChangePercentage < 0 downwardTrends := downwardTrends + 1
// Determine the probability trend based on the probabilities probabilityTrend = "" if probabilityUpward > probabilityDownward probabilityTrend := "Upward" else if probabilityUpward < probabilityDownward probabilityTrend := "Downward"
// Calculate the oscillator value based on the difference between upward and downward trends oscillatorValue = probabilityUpward - probabilityDownward
// Determine the histogram color based on the difference between the oscillator value and zero line histogramColor = oscillatorValue >= 0 ? (oscillatorValue[1] < oscillatorValue ? color.new(#089981, 50) : color.new(#089981, 50)) : (oscillatorValue[1] < oscillatorValue ? color.new(#f23645, 50) : color.new(#f23645, 50))
string TT_HARSI = 'Period for the RSI calculations used to generate the' + 'candles. This seperate from the RSI plot/histogram length.'
string TT_PBIAS = 'Smoothing feature for the OPEN of the HARSI candles.' + '\n\nIncreases bias toward the prior open value which can' + ' help provide better visualisation of trend strength.' + '\n\n** By changing the Open values, High and Low can also' + ' be distorted - however Close will remain unchanged.'
string TT_SMRSI = 'This option smoothes the RSI in a manner similar to HA' + ' open, but uses the realtime rsi rather than the prior' + ' close value.'
string TT_STOCH = 'Uses the RSI generated by the above settings, and as such' + ' will be affected by the smoothing option.'
string TT_STFIT = 'Adjusts the vertical scaling of the stochastic, can help' + ' to prevent distortion of other data in the channel.' + '\n\nHas no impact cross conditions.'
// zero median rsi helper function, just subtracts 50. f_zrsi(_source, _length) => ta.rsi(_source, _length) - 50
// zero median stoch helper function, subtracts 50 and includes % scaling f_zstoch(_source, _length, _smooth, _scale) => float _zstoch = ta.stoch(_source, _source, _source, _length) - 50 float _smoothed = ta.sma(_zstoch, _smooth) float _scaled = _smoothed / 100 * _scale _scaled
// mode selectable rsi function for standard, or smoothed output f_rsi(_source, _length, _mode) =>
// get base rsi float _zrsi = f_zrsi(_source, _length)
// smoothing in a manner similar to HA open, but rather using the realtime // rsi in place of the prior close value. var float _smoothed = na _smoothed := na(_smoothed[1]) ? _zrsi : (_smoothed[1] + _zrsi) / 2
// return the requested mode _mode ? _smoothed : _zrsi
// RSI Heikin-Ashi generation function f_rsiHeikinAshi(_length) =>
// get close rsi float _closeRSI = f_zrsi(close, _length)
// emulate "open" simply by taking the previous close rsi value float _openRSI = nz(_closeRSI[1], _closeRSI)
// the high and low are tricky, because unlike "high" and "low" by // themselves, the RSI results can overlap each other. So first we just go // ahead and get the raw results for high and low, and then.. float _highRSI_raw = f_zrsi(high, _length) float _lowRSI_raw = f_zrsi(low, _length) // ..make sure we use the highest for high, and lowest for low float _highRSI = math.max(_highRSI_raw, _lowRSI_raw) float _lowRSI = math.min(_highRSI_raw, _lowRSI_raw)
// ha calculation for close float _close = (_openRSI + _highRSI + _lowRSI + _closeRSI) / 4
// ha calculation for open, standard, and smoothed/lagged var float _open = na _open := na(_open[i_smoothing]) ? (_openRSI + _closeRSI) / 2 : (_open[1] * i_smoothing + _close[1]) / (i_smoothing + 1)
// ha high and low min-max selections float _high = math.max(_highRSI, math.max(_open, _close)) float _low = math.min(_lowRSI, math.min(_open, _close))
// return the OHLC values [_open, _high, _low, _close]
// Divergences f_top_fractal(src) => src[4] < src[2] and src[3] < src[2] and src[2] > src[1] and src[2] > src[0] f_bot_fractal(src) => src[4] > src[2] and src[3] > src[2] and src[2] < src[1] and src[2] < src[0] f_fractalize(src) => f_top_fractal(src) ? 1 : f_bot_fractal(src) ? -1 : 0
f_findDivs(src, topLimit, botLimit, useLimits) => fractalTop = f_fractalize(src) > 0 and (useLimits ? src[2] >= topLimit : true) ? src[2] : na fractalBot = f_fractalize(src) < 0 and (useLimits ? src[2] <= botLimit : true) ? src[2] : na highPrev = ta.valuewhen(fractalTop, src[2], 0)[2] highPrice = ta.valuewhen(fractalTop, high[2], 0)[2] lowPrev = ta.valuewhen(fractalBot, src[2], 0)[2] lowPrice = ta.valuewhen(fractalBot, low[2], 0)[2] bearSignal = fractalTop and high[2] > highPrice and src[2] < highPrev bullSignal = fractalBot and low[2] < lowPrice and src[2] > lowPrev bearDivHidden = fractalTop and high[2] < highPrice and src[2] > highPrev bullDivHidden = fractalBot and low[2] > lowPrice and src[2] < lowPrev [fractalTop, fractalBot, lowPrev, bearSignal, bullSignal, bearDivHidden, bullDivHidden]
wwttBearDivColor = wwttShowDiv and wwttBearDiv or wwttShowHiddenDiv and wwttBearDivHidden_ ? colorRed : na wwttBullDivColor = wwttShowDiv and wwttBullDiv or wwttShowHiddenDiv and wwttBullDivHidden_ ? colorGreen : na
wwttBearDivColor_add = wwttShowDiv and wwttDivOOBBLevel_addshow and wwttBearDiv_add or wwttShowHiddenDiv and wwttDivOOBBLevel_addshow and wwttBearDivHidden_add ? #9a0202 : na wwttBullDivColor_add = wwttShowDiv and wwttDivOOBBLevel_addshow and wwttBullDiv_add or wwttShowHiddenDiv and wwttDivOOBBLevel_addshow and wwttBullDivHidden_add ? #1b5e20 : na
rsiBearDivColor = rsiShowDiv and rsiBearDiv or rsiShowHiddenDiv and rsiBearDivHidden_ ? colorRed : na rsiBullDivColor = rsiShowDiv and rsiBullDiv or rsiShowHiddenDiv and rsiBullDivHidden_ ? colorGreen : na
// Buy signal. buySignal = wwttCross and wwttCrossUp and wwttOversold
buySignalDiv = wwttShowDiv and wwttBullDiv or wwttShowDiv and wwttBullDiv_add or rsiShowDiv and rsiBullDiv
plotchar(cross_down[1] and wwttBuyShow and buySignal ? -107 : na, title='Buy circle', char='·', color=color.new(colorGreen, 10), location=location.absolute, size=size.small) plotchar(cross_up[1] and wwttSellShow and sellSignal ? 105 : na, title='Sell circle', char='·', color=color.new(colorRed, 10), location=location.absolute, size=size.small)
plotchar(cross_down[1] and wwttDivShow and buySignalDiv and wwttBuyShow and buySignal[2] ? -106 : na, title='Divergence buy circle', char='▲', color=buySignalDiv_color, location=location.absolute, size=size.tiny, offset=-2, transp=10) plotchar(cross_up[1] and wwttDivShow and sellSignalDiv and wwttSellShow and sellSignal[2] ? 106 : na, title='Divergence sell circle', char='▼', color=sellSignalDiv_color, location=location.absolute, size=size.tiny, offset=-2, transp=10)
//Alerts alertcondition((cross_down[1] and wwttBuyShow and buySignal[2] and wwttDivShow and buySignalDiv) or (cross_up[1] and wwttSellShow and sellSignal[2] and wwttDivShow and sellSignalDiv), title='Buy/Sell Signal', message='Buy/Sell Signal')
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
차트에서 빠르게 액세스하려면 이 스크립트를 즐겨찾기에 추가하세요 — 여기에서 자세히 알아보기.