I did not find a Trend Vigor indicator so I am adding it.
Trend Vigor, per Dr Ehlers, is used to determine if the market is trending or cycling.
• Suppose an RSI signals a valley
– The trading action is to buy
• However, the market keeps going down
– In hindsight a trend mode has started
• Oscillators and Moving Averages often give opposite signals
THE REAL PROBLEM IS HOW TO IDENTIFY THE CORRECT MARKET MODE
Trend Vigor is the ratio of the (smoothed) trend slope across one full cycle period to the cycle peak-to-peak amplitude.
• If the ratio is greater than one the trend component swamps the cycle
– Don’t stand in front of the train
– You can still use the cycle to enter the trade at the best time in the direction of the trend
• If the ratio is less than one the trend has a minimum effect on the cycle
– Use your favorite oscillator
• The simple model has two components
– A perfect trend
– A perfect cycle
Here is a screenshot of what it looks like. The Trend Vigor is the blue line at the bottom of the chart.
One very interesting thing other than the actual indicator that the code provides is a different way to estimate the peak to Peak Cycle amplitude. In short the code is as follows, where "BP" is the value of the Bandpass Filter:
For count = 0 to Period - 1 Begin
Power = Power + BP[count]*BP[count] + BP[count + Period / 4]*BP[count + Period / 4];
End;
RMS = SquareRoot(Power / Period);
PtoP = 2*1.414*RMS;
Plot1(PtoP, "PP", Yellow, 2);
Here is the code for the Trend Vigor indicator:
Enjoy!
Trend Vigor, per Dr Ehlers, is used to determine if the market is trending or cycling.
• Suppose an RSI signals a valley
– The trading action is to buy
• However, the market keeps going down
– In hindsight a trend mode has started
• Oscillators and Moving Averages often give opposite signals
THE REAL PROBLEM IS HOW TO IDENTIFY THE CORRECT MARKET MODE
Trend Vigor is the ratio of the (smoothed) trend slope across one full cycle period to the cycle peak-to-peak amplitude.
• If the ratio is greater than one the trend component swamps the cycle
– Don’t stand in front of the train
– You can still use the cycle to enter the trade at the best time in the direction of the trend
• If the ratio is less than one the trend has a minimum effect on the cycle
– Use your favorite oscillator
• The simple model has two components
– A perfect trend
– A perfect cycle
Here is a screenshot of what it looks like. The Trend Vigor is the blue line at the bottom of the chart.
One very interesting thing other than the actual indicator that the code provides is a different way to estimate the peak to Peak Cycle amplitude. In short the code is as follows, where "BP" is the value of the Bandpass Filter:
For count = 0 to Period - 1 Begin
Power = Power + BP[count]*BP[count] + BP[count + Period / 4]*BP[count + Period / 4];
End;
RMS = SquareRoot(Power / Period);
PtoP = 2*1.414*RMS;
Plot1(PtoP, "PP", Yellow, 2);
Here is the code for the Trend Vigor indicator:
CSS:
# Trend Vigor Index (TVI) per Dr Ehlers
declare lower;
#===================================================================
script HilbertTransform {
# Measures dominant cycle using Hilbert Transform method of
# CH 9 "Cybernetic Analysis for Stocks and Futures" by Dr Ehlers
input InstPeriodPrior = 20;
input price = HL2;
def alpha = 0.07;
def Smooth = (price + 2 * price[1] + 2 * price[2] + price[3]) / 6;
def Cycle = if IsNaN(Cycle[7]) then 0.25 * (price - 2 * price[1] + price[2]) else (1 - 0.5 * alpha) * (1 - 0.5 * alpha) * (Smooth - 2 * Smooth[1] + Smooth[2]) + 2 * (1 - alpha) * Cycle[1] - (1 - alpha) * (1 - alpha) * Cycle[2];
def Q1 = (0.0962 * Cycle + 0.5769 * Cycle[2] - 0.5769 * Cycle[4] - 0.0962 * Cycle[6]) * (0.5 + 0.08 * InstPeriodPrior);
def I1 = Cycle[3];
def DeltaPhase_calc = if Q1 <> 0 and Q1[1] <> 0 then (I1 / Q1 - I1[1] / Q1[1]) / (1 + I1 * I1[1] / (Q1 * Q1[1])) else 0;
plot DeltaPhase = if DeltaPhase_calc < 0.1 then 0.1 else if DeltaPhase_calc > 1.1 then 1.1 else DeltaPhase_calc;
plot MedianDelta = Median(DeltaPhase, 5);
plot DC = if MedianDelta == 0 then 15 else 6.28318 / MedianDelta + 0.5;
plot InstPeriod = 0.33 * DC + 0.67 * InstPeriodPrior;
} #End Script HilbertTransform{}
#-------------------------------------------------------
input price = HL2;
#******* This section measures the Dominant Cycle *******#
# The following line is the required means of calling script HilbertTransform
# because the algorithm is nonlinear in the definition of Period[1]. In order
# to provide the value of Period[1] before Period[0] has been computed we use
# a CompoundValue() method to front load the Period[1] value as required for
# the HilbertTransform to work
def Period_ = CompoundValue(4,
if BarNumber() > 5 then HilbertTransform(Period_[1], price).InstPeriod else Period_[1],
20);
# Per Ehlers, smoothes the cycle period
def Period = 0.15 * Period_ + 0.85 * Period[1];
def CycleLength = if IsNaN(Floor(Period)) then CycleLength[1] else Floor(Period);
#*******This section computes the adaptive Cycle indicator*******#
def alpha = 2 / (CycleLength + 1);
#def Smooth = (price + 2 * price[1] + 2 * price[2] + price[3]) / 6;
def Smooth = price;
def Pcyclic = if IsNaN(Pcyclic[7]) then (price - 2 * price[1] + price[2]) / 4 else (1 - 0.5 * alpha) * (1 - 0.5 * alpha) * (Smooth - 2 * Smooth[1] + Smooth[2]) + 2 * (1 - alpha) * Pcyclic[1] - (1 - alpha) * (1 - alpha) * Pcyclic[2];
#****** This is Ehlers ITrend, per CH 2-3 of "Cybernetic analysis for Stocks and Futures",
# has essentially no lag since it is a HPF subtracted from the price data.
# Refer to Figure 3.6 for the code:
def ITrend = if IsNaN(ITrend[7]) then (price + 2 * price[1] + price[2]) / 4 else (alpha - alpha * alpha / 4) * price + 0.5 * alpha * alpha * price[1] - (alpha - 0.75 * alpha * alpha) * price[2] + 2 * (1 - alpha) * ITrend[1] - (1 - alpha) * (1 - alpha) * ITrend[2];
def Power = fold count = 0 to CycleLength with pwr=0 do pwr + Sqr(GetValue(Pcyclic,count)) + Sqr(GetValue(Pcyclic,count + CycleLength / 4));
def RMS = sqrt(Power / CycleLength);
# Peak To Peak Amplitude of the Pcycle waveform
def PtoP = 2*1.414*RMS;
def TVI_val = (ITrend - GetValue(ITrend,CycleLength-1))/PtoP;
plot TVI = if TVI_val > 2 then 2 else if TVI_val < -2 then -2 else TVI_Val;
TVI.AssignValueColor(Color.Blue);
TVI.SetLineWeight(3);
plot Trending = 1;
Trending.HideBubble();
Trending.AssignValueColor(Color.GRAY);
Trending.SetStyle(Curve.SHORT_DASH);
Trending.SetLineWeight(3);
Enjoy!