Effective Volume translate to Amibroker. Help

#1
Guys, I got effective volume formula from internet today. But the problem is the formula different with AFL. Help me please to translate the formula?
Thank you in advance.
Regards
Thariq


{- Filename: Effective Volume -}
{*************************************************
Effective Volume is an indicator developed by Pascal Willain and published in the book "Value in Time" , Wiley 2008.
This indicator detects institutional activities by stastistically analysing price/volume movements on the minute level.
This analysis allows to show institutional players' activities out of the noise generated by retail players.
More information can be found on www.effectivevolume.eu
Effective Volume is a registered trademark.
Adaptation of Effective Volume to "Wall Street" has been provided by Paul Menzing.
**************************************************}
var
Direction,NumBars,DayCount,iVolumeFilter,iPriceFilter,Dag : integer;
i,Counter,Counter1,Counter2,Loop : integer;
TotalDailyVolume,SPI,PriceFiter,Size : real;
PriceInflection,TotalDailyEV,SeperationNumber : real;
VolumeFilter,TotalEffVolume,xMidPoint,Temp,SeparationVolume : real;
PlotSEV,PlotLEV,LargeEffectiveVolume,SmallEffectiveVolume,TrueLow : TSeries;
TrueHigh,CloseAgo,EffectiveVolume,TotalEffectiveVolume,xDayCount : TSeries;
SessionEndTime,xSessionEndTime,StartDate : TdateTime;
ShowMD : Boolean;

aEffectiveVolume : array[1..1440]of Real;
aTmp : array[1..1440]of Real;

begin

iVolumeFilter := CreateParameterInteger('VolumeFilter %', 1, 999,5, true);
iPriceFilter := CreateParameterInteger('PriceFilter %', 1, 999, 1, true);
SPI := CreateParameterReal('Smallest Price Increment', 0, 1, 0.01, false);
Size := CreateParameterReal('Size', 0, 1, 0.001, false);
Dag := CreateParameterInteger ('Total Days' , 1 , 2000 , 15 , true);
ShowMD := CreateParameterBoolean('Multiple days', true, false);

with Indicator do
begin
ShortName := 'Effective Volume';
RequiredBars := 2*390;
end;

CloseAgo := Shiftseries(Close,1);
TrueLow := MinSeries(Low,CloseAgo);
TrueHigh := MaxSeries(High,CloseAgo);
xDayCount := CreateSeries(BarCount);
EffectiveVolume := CreateSeries(BarCount);
TotalEffectiveVolume := CreateSeries(BarCount);
LargeEffectiveVolume := CreateSeries(BarCount);
SmallEffectiveVolume := CreateSeries(BarCount);
PlotLEV := CreateSeries(BarCount);
PlotSEV := CreateSeries(BarCount);

if Dag <= 5 then Dag := 7 else Dag := Trunc((Dag/5) * 7);
StartDate := date - (Dag + 2);

DayCount := 0;

for i:=FirstValidIndex(close)+1 to barcount-1 do begin

xSessionEndTime := frac(datetime)+ 0.001;
SessionEndTime := Instrument.MarketClose;


if dateTime >= (StartDate) then
begin

if (DayCount = 0 ) then
begin
NumBars := 0;
LargeEffectiveVolume := 0;
SmallEffectiveVolume := 0;
PlotLEV := NAN;
PlotSEV := NAN;
end;

TotalDailyVolume := TotalDailyVolume + Volume;
PriceFiter := Abs(((Close - Close[i-1])/Close[i-1])*100);

if (DayCount > 0) then
begin
NumBars := NumBars + 1;
if Numbars = 1 then EffectiveVolume := 0;

if (Numbars > 1) then begin
if (Close[i-1] - Close <> 0) and ( (Volume <= VolumeFilter) and (PriceFiter <= iPriceFilter))then
begin

if close > close[i-1] then
begin
PriceInflection := close - close[i-1];
Direction := 1;
end;
if close < close[i-1] then
begin
PriceInflection := close[i-1] - close;
Direction := -1;
end;

if (TrueHigh - TrueLow + SPI) <> 0 then EffectiveVolume := Direction * ((PriceInflection + SPI)/(TrueHigh - TrueLow + SPI)) * Volume else EffectiveVolume := 0;
end
else EffectiveVolume := 0;
end;//Numbars

TotalEffVolume := TotalEffVolume + EffectiveVolume;
aEffectiveVolume[NumBars] := EffectiveVolume;
aTmp[NumBars] := Abs(EffectiveVolume);
TotalDailyEV := TotalDailyEV + aTmp[NumBars];
end;//Daycount
/////////////////////////////////End Of Day Calculation/////////////////////////////////////////////////////
if xSessionEndTime >= SessionEndTime then begin
DayCount := DayCount + 1;
xMidPoint := TotalDailyEV * 0.5;

if (DayCount > 0) and (Numbars > 2) then
begin

//Sorting Array High to Low
for Counter1 := 1 to Numbars-1 do
begin
for Counter2 := Counter1 + 1 to Numbars do
begin
if aTmp[Counter1] < aTmp[Counter2]then
begin
Temp := atmp[Counter1];
aTmp[Counter1] := aTmp[Counter2];
aTmp[Counter2] := Temp;
end ;
end ;
end ;

Loop := 1;
SeperationNumber := TotalDailyEV;
while (loop <= NumBars) and (SeperationNumber >= xMidPoint)do
begin
SeperationNumber := SeperationNumber - aTmp[Loop];
SeparationVolume := aTmp[Loop];
Loop := Loop + 1;
end;

for Counter := Numbars - 1 downto 0 do
begin

if abs(aEffectiveVolume[Numbars - Counter])>= SeparationVolume
then begin
LargeEffectiveVolume[i - Counter]:=LargeEffectiveVolume[i - Counter-1] + aEffectiveVolume[Numbars - Counter]*Size;
SmallEffectiveVolume[i - Counter]:=SmallEffectiveVolume[i - Counter-1]+ 0;
end
else
if abs(aEffectiveVolume[Numbars - Counter])< SeparationVolume then
begin
SmallEffectiveVolume[i - Counter]:=SmallEffectiveVolume[i - Counter-1] + aEffectiveVolume[Numbars - Counter]*Size;
LargeEffectiveVolume[i - Counter]:=LargeEffectiveVolume[i - Counter-1]+ 0;
end;
//Plot values starting with first minute
if (DayCount > 1) then begin
PlotLEV[i - Counter] := round(LargeEffectiveVolume[i - Counter]);
PlotSEV[i - Counter] := round(SmallEffectiveVolume[i - Counter]);
end;
end;

for Counter := 1 to Numbars do
begin
aEffectiveVolume[Numbars] := 0;
aTmp[Numbars] := 0;
end;
end;//NumBars

NumBars := 0;
VolumeFilter := TotalDailyVolume * (iVolumeFilter * 0.01);
TotalDailyEV := 0;
TotalDailyVolume := 0
TotalEffVolume := 0;
EffectiveVolume := 0;
TotalEffectiveVolume:= 0;
if not ShowMD then
begin
LargeEffectiveVolume := 0;
SmallEffectiveVolume := 0;
end;
end; //SessionEndTime
end; // StartDate
end; //for

with CreateLine(PlotLEV) do
begin
Name := 'LEV';
Color := clBlue;
width := 4;
end;
with CreateLine(PlotSEV) do
begin
Name := 'SEV';
Color := clYellow;
width := 4;
end;
end.
 

Similar threads