Tim Ord Indicator

H

hoojsn

New member
Anyone could help to translate this script to TOS, this in found this in https://www.tradingview.com/script/lhda3xOg-Ord-Volume-LucF/
Code:
//@version=3
//@author=LucF
is
// Ord Volume [LucF]
// v1.1, 2019.03.24

// Shows average volume for each price wave (a Tim Ord concept).
// It's basically Weis Wave with average volume instead of cumulative volume.
// Credits to LazyBear for original Weis Wave code (a David Weis concept).

study("Ord Volume [LucF]", shorttitle="Ord Volume", precision=0)

MyGreenRaw = color(#00FF00,0),      MyGreenMedium = color(#00FF00,40),      MyGreenSemiDark = color(#00FF00,62),    MyGreenDark = color(#00FF00,75),    MyGreenDarkDark = color(#00FF00,82),    MyGreenDarkDarkDark = color(#00FF00,93)
MyRedRaw = color(#FF0000,0),        MyRedMedium = color(#FF0000,30),        MyRedSemiDark = color(#FF0000,50),      MyRedDark = color(#FF0000,75),      MyRedDarkDark = color(#FF0000,85),      MyRedDarkDarkDark = color(#FF0000,92)
MyOrangeRaw = color(#FF9800,0),     MyOrangeMedium = color(#FF9800,30),     MyOrangeSemiDark = color(#FF9800,50),   MyOrangeDark = color(#FF9800,60)
Invisible = color(white,100)

// ---------- Inputs
ColorAvg = input(true, "Distinguish rising/falling states")
ShowAvgEma = input(false, "EMA of averages")
ShowLastAvg = input(false, "Last Wave's Ending Average")
ShowLastHighestAvg = input(false, "Last Wave's Highest Average")
TrendReversalLength = input(5, "Trend reversal length")
PriceSource = input(close, "Price Source for trend detection")
LongsOnly = input(false,"Only Long Markers")
ShortsOnly = input(false,"... Or Only Short Markers")
ShowMarker1 = input(false, "Marker 1: Breach of previous wave's highest Average")

// ---------- Detect Wave
Trend = 0
Wave = 0
WaveBars = 0
CumVolume = volume

UpOrDn = PriceSource>PriceSource[1] ? 1 : PriceSource<PriceSource[1] ? -1 : 0                           // Price movement Up->1, Dn->-1, No change->0
Trend := (UpOrDn != 0) and (UpOrDn != UpOrDn[1]) ? UpOrDn : nz(Trend[1])                                // Trend changes when price reverses direction.
ReversalTrend = rising(PriceSource, TrendReversalLength) or falling(PriceSource, TrendReversalLength)   // Detect reversal condition.
Wave := (Trend != nz(Wave[1])) and ReversalTrend ? Trend : nz(Wave[1])                                  // Stay in wave until a counter trend of trendDetectionLength occurs.

// ---------- States
BullWave = Wave==1
BearWave = Wave==-1
SameWave = Wave==Wave[1]

// ---------- Build average volume for current wave.
CumVolume := SameWave ? (nz(CumVolume[1])+volume) : volume
WaveBars := SameWave ? nz(WaveBars[1])+1 : 1
AverageWaveVolume = CumVolume/WaveBars

// ---------- Keep track of last wave's ending average.
LastAvg = 0.0
LastAvg := not SameWave ? AverageWaveVolume[1] : LastAvg[1]

// ---------- Keep track of last wave's maximum average.
CurrentMaxAvg = 0.0
CurrentMaxAvg := SameWave ? max(AverageWaveVolume, nz(CurrentMaxAvg[1])) : AverageWaveVolume
// plot(CurrentMaxAvg)
LastMaxAvg = CurrentMaxAvg
LastMaxAvg := SameWave ? LastMaxAvg[1] : CurrentMaxAvg[2]

// ---------- Plots
plot( AverageWaveVolume, "Average Volume", color=BullWave? rising(AverageWaveVolume,1) and ColorAvg? MyGreenSemiDark:MyGreenDark: rising(AverageWaveVolume,1) and ColorAvg? MyRedSemiDark:MyRedDark, linewidth=1, style=area)
plot( ShowAvgEma? ema( AverageWaveVolume,20):na, "EMA of Average Volume", color=MyOrangeMedium, linewidth=1)
plot( ShowLastAvg ? LastAvg:na, "Last Wave Average", color=BullWave? red:green, linewidth=2, style=circles)
plot( ShowLastHighestAvg ? LastMaxAvg:na, "Last wave Maximum Average", color=not SameWave? Invisible: BullWave? red:green, linewidth=2, style=line)

// ---------- Markers
// Marker 1: Last wave's maximum average surpassed
M1U = ShowMarker1 and not ShortsOnly and BullWave and close>open and (crossover(AverageWaveVolume, LastMaxAvg) or (not SameWave and AverageWaveVolume>CurrentMaxAvg[1]))
M1D = ShowMarker1 and not LongsOnly and BearWave and close<open and (crossover(AverageWaveVolume, LastMaxAvg) or (not SameWave and AverageWaveVolume>CurrentMaxAvg[1]))
plotshape( M1U, "Marker 1 Up", color=MyGreenMedium, style=shape.triangleup, location=location.top, size=size.tiny, text="1")
plotshape( M1D, "Marker 1 Dn", color=MyRedMedium, style=shape.triangledown, location=location.top, size=size.tiny, text="1")

// ---------- Alert
alertcondition(M1U or M1D, title="Ord V: Configured Markers", message="OrdV Marker")
 
Last edited by a moderator:

Similar threads

Top