This is an old topic but I would like to address it again.
I converted the following to RealCode
// @author LazyBear
// List of all my indicators: https://www.tradingview.com/v/4IneGo8h/
//
study("Weis Wave Volume [LazyBear]", shorttitle="WWV_LB")
trendDetectionLength=input(2)
showDistributionBelowZero=input(false, type=bool)
mov = close>close[1] ? 1 : close<close[1] ? -1 : 0
trend= (mov != 0) and (mov != mov[1]) ? mov : nz(trend[1])
isTrending = rising(close, trendDetectionLength) or falling(close, trendDetectionLength) //abs(close-close[1]) >= dif
wave=(trend != nz(wave[1])) and isTrending ? trend : nz(wave[1])
vol=wave==wave[1] ? (nz(vol[1])+volume) : volume
up=wave == 1 ? vol : 0
dn=showDistributionBelowZero ? (wave == 1 ? 0 : wave == -1 ? -vol : vol) : (wave == 1 ? 0 : vol)
plot(up, style=histogram, color=green, linewidth=3)
plot(dn, style=histogram, color=red, linewidth=3)
My RealCode
'# TrendLength = UserInput.Integer = 2
Static mov As Single
Static prevmov As Single
Static trend As Single
Static prevtrend As Single
Static isTrending As Single
Static wave As Single
Static prevwave As Single
Static vol As Single
If isFirstBar Then
mov = 0
prevmov = 0
trend = 0
prevtrend = 0
isTrending = 0
wave = 0
prevwave = 0
vol = 0
End If
'mov = close>close[1] ? 1 : close<close[1] ? -1 : 0
If price.close > price.Close(1) Then
mov = 1
Else If price.close < price.close(1) Then
mov = -1
Else
mov = 0
End If
'trend= (mov != 0) and (mov != mov[1]) ? mov : nz(trend[1])
If mov <> 0 And mov <> prevmov Then
trend = mov
Else
trend = prevtrend
End If
'isTrending = rising(close, trendDetectionLength) or falling(close, trendDetectionLength)
If price.close > price.close(1) AndAlso price.Close(1) > price.Close(2) _
Or price.close < price.Close(1) AndAlso price.close(1) < price.Close(2) Then
isTrending = 1
Else
isTrending = 0
End If
'wave = (trend != nz(wave[1])) and isTrending ? trend : nz(wave[1])
If trend <> prevwave AndAlso isTrending = 1 Then
wave = trend
Else
wave = prevwave
End If
'vol = wave==wave[1] ? (nz(vol[1])+volume) : volume
If wave = prevwave Then
vol += volume.value
Else
vol = volume.value
End If
If wave = 1 Then
plot = vol
Else
plot = -vol
End If
prevmov = mov
prevtrend = trend
prevwave = wave
This version has down volume displayed below 0, because I did not know how to set 2 different plot colors in the indicator RealCode. I set the plot to Bar in the edit window for the indicator and the Paint Scheme in the edit window. I like how this version matches to price movement.
My question - is this version of Weis Wave possible in TC2000 V17?
|