Could someone convert this code into AFL/amibroker? (RVI)

#2
hi

where is the code for inertia?
HTML:
//I have the following AFL code for the RVI:
//by Gordon Sutherland 


  // Donald Dorsey's RVI Indicator (Relative Volatility Index?)

  // Posted to AB Yahoo Groups by Rakesh Sahgal on 23rd April 2007



  SD10=StDev(C,10);

  RVI=RSIa(SD10,10);

  Plot(RVI,"RVI",colorBlack,styleLine);
==========================================================
MS CODE INERTIA IS
 Inertia 2 in 1

Mov( ((100 * Mov( If(HIGH > Ref(HIGH,-1), Std(HIGH,10),0),14,E) /
(Mov( If(HIGH > Ref(HIGH,-1), Std(HIGH,10), 0),14,E)+
Mov(If(HIGH < Ref(HIGH,-1), Std(HIGH,10),0),14,E)) +
100 * Mov( If(LOW > Ref(LOW,-1), Std(LOW,10),0),14,E) /
(Mov( If(LOW > Ref(LOW,-1), Std(LOW,10), 0),14,E)+
Mov(If(LOW < Ref(LOW,-1), Std(LOW,10), 0),14,E)))/ 2),20,SIMPLE)
============================================================
RULES ARE
Buy if RVI > 50
Sell if RVI < 50
If you miss the first RVI buy signal buy when RVI > 60
If you miss the first RVI Sell signal sell when RVI < 40
Close a long position when the RVI falls below 40
Close a short position when the RVI rises above 60



INERTIA = nature or tendency to continue in trend or no trend
============================================
Appeared in the September 95 issue of Stocks &Commodities magazine
The Inertia indicator was developed by Donald Dorsey.
It was originally introduced in theSeptember1995 issue of Technical Analysis of Stocks and Commodities magazine.

It is an outgrowth of Dorsey's Relative Volatility Index (see Relative Volatility Index).
Dorsey chose the name "Inertia" because of his definition of a trend.
He asserts that a trend is simply the outward result of inertia.
It takes significantly more energy for a market to reverse direction than to continue along the same path. Therefore a trend is a measurement of market inertia.

In physics, Inertia is defined in terms of mass and direction of motion.
Using technical analysis to analyze security prices, the direction of motion is easily defined.
However, mass is not so easily defined. Dorsey asserts that volatility may be the simplest and most accurate measurement of inertia.
This theory led him to use the Relative Volatility Index (RVI) as the basis for a trend indicator.
Inertia is simply a smoothed RVI.
The smoothing mechanism is a Linear Regression indicator (see Linear Regression Indicator).
The RVI helps measure the general direction of volatility.
Dorsey found that by smoothing the RVI, a good long-term trend indicator resulted.

If the Inertia indicator is above 50, positive inertia is indicated.
The long-term trend is up and should remain up as long as the indicator is above 50.
If the Inertia indicator is below 50, negative inertia is indicated.
The long-term trend is down and should remain down, as long as the indicator is below 50.
------------------------------
metastock code(our friends can now coinvert this code into afl)
New Relative Volatility Index

(100 * Mov( If(HIGH > Ref(HIGH,-1),Std(HIGH,10),0),14,E) /
(Mov( If(HIGH > Ref(HIGH,-1), Std(HIGH,10),0),14,E) +
Mov(If(HIGH < Ref(HIGH,-1), Std(HIGH,10),0),14,E)) +
100 * Mov( If(LOW > Ref(LOW,-1), Std(LOW,10),0),14,E) /
(Mov( If(LOW > Ref(LOW,-1), Std(LOW,10), 0),14,E)+
Mov(If(LOW < Ref(LOW,-1), Std(LOW,10),0),14,E))) / 2

Inertia

Mov( Fml( "New Relative Volatility Index" ),20,SIMPLE)
 
Last edited:
#3
HI FRIENDS

HERE IS TRADE STATION CODE FOR INERTIA

HTML:
TRADESTATION CODE FOR THE NEW RELATIVE VOLATILITY INDEX(RVI)

RVIH

VALUE1=@STDDEV(H,10);

IF CURRENTBAR=13 THEN BEGIN
FOR VALUE0=0 TO 13 BEGIN
IF H[VALUE0]>H[VALUE0+1] THEN VALUE10=VALUE10+VALUE1[VALUE0];
IF H[VALUE0]<H[VALUE0+1] THEN VALUE11=VALUE11+VALUE1[VALUE0];
END;
END;

IF CURRENTBAR>13 THEN BEGIN
IF H>H[1] THEN VALUE 10=(13*VALUE10[1]+VALUE1)/14 ELSE VALUE10=13*VALUE10[1]/14;
IF H<H[1] THEN VALUE 11=(13*VALUE11[1]+VALUE1)/14 ELSE VALUE11=13*VALUE11[1]/14;
END;

IF @CURRENTBAR>13 THEN RVIH=100*(VALUE10)/(VALUE10+VALUE11);

RVIL

VALUE1=@STDDEV(L,10);

IF CURRENTBAR=13 THEN BEGIN
FOR VALUE0=0 TO 13 BEGIN
IF L[VALUE0]>L[VALUE0+1] THEN VALUE10=VALUE10+VALUE1[VALUE0];
IF L[VALUE0]<L[VALUE0+1] THEN VALUE11=VALUE11+VALUE1[VALUE0];
END;
END;

IF CURRENTBAR>13 THEN BEGIN
IFL>L[1] THEN VALUE10=(13*VALUE10[1]+VALUE1)/14 ELSE VALUE10=13*VALUE10[1]/14;
IFL<L[1] THEN VALUE11=(13*VALUE11[1]+VALUE1)/14 ELSE VALUE11=13*VALUE11[1]/14;
END;

IF @CURRENTBAR>13 THEN RVIL=100*(VALUE10)/(VALUE10+VALUE11);

INERTIA

IF @CURRENTBAR<33 THEN INERTIA=50 ELSE INERTIA=AVERAGE((RVIH+RVIL)/2,20);
{
OR A SLIGHTLY BETTER FORMULA IS:
IF @CURRENTBAR<33 THEN INERTIA=50ELSE INERTIA=LINEARREGVALUE((RVIH+RVIL)/2,20,10);
}
AS PER ROBERT,read below

RVI was subsequently refined by Donald Dorsey in an article in the TASC September 1995 issue.

Instead of using the close in the calculation of the RVI Dorsey changed its calculation using the highs and the lows. The 1995 Tradestation code is given but since I do not know the TS easy language I am unable to use it for help in converting the new RVI into an efs.

However I have tried modifying the original code from TS Support by using the high and low. The new RVI appears to be plotting on a chart but I am uncertain as to whether my modification has resulted in a correctly working new RVI. I am attaching my modified efs and would be grateful if someone could kindly check if the resultant RVI plot/logic is working correctly. The TS code is also attached.

I have not tried coding the inertia section and any help in including it would be very much appreciated too.

Robert
 

extremist

Well-Known Member
#4
the converted AFL version required by ford is as follows :



_SECTION_BEGIN("RVI");
x=(100 * EMA( IIf(High > Ref(High,-1),StDev(High,10),0),14) /
(EMA( IIf(High > Ref(High,-1), StDev(High,10),0),14) +
EMA(IIf(High < Ref(High,-1), StDev(High,10),0),14)) +
100 * EMA( IIf(Low > Ref(Low,-1), StDev(Low,10),0),14) /
(EMA( IIf(Low > Ref(Low,-1), StDev(Low,10), 0),14)+
EMA(IIf(Low < Ref(Low,-1), StDev(Low,10),0),14))) / 2 ;

Inertia=MA( x,20);
Plot(x,"Inertia",colorBrightGreen,styleLine);
Plot(Inertia,"Signal",colorRed,styleLine);

_SECTION_END();
 
#5
Hi extremist

Thank you for the afl coding.

My humble request to other senior experts is
please post some hints and charts if we can make use of INERTIA in trading
for support.
regards
ford
 

Similar threads