door Paul M » zo 08 feb 2004, 22:14
Hoi Cees,
MA,EMA en MACD op dagbasis in een intradag grafiek.
Functie:
Value function zzDonIDGetPrices (value Price)begin
Value DOpen[],DHigh[],DLow[],DClose[];
Array:VorigeO[550](0),VorigeH[550](0),VorigeL[550](0),VorigeC[550](0);
If Date <> Date[-1] and Value1 > 0 then begin
? DClose = Close;
? DHigh = High;
? DLow = Low;
? For Value2 = 0 to Value1 begin
? ? ? ?If High[Value2] > Dhigh then
? ? ? ? ? ?Dhigh = High[Value2];
? ? ? ?If Low[Value2] < Dlow then
? ? ? ? ? ?Dlow = Low[Value2];
? ? ? ?If Value2 = Value1 ?then
? ? ? ? ? ?DOpen = Open[Value2];
? ?End;
{ Sla ?Open, High, Low and Close of Day op in Arrays}
? ?For Value3 = 0 To 549 Begin
? ?
? ?VorigeO[Value3] = DOpen;
? ?VorigeH[Value3] = DHigh;
? ?VorigeL[Value3] = DLow;
? ?VorigeC[Value3] = DClose;
?
? ?
? ? ? ?If Price = Open then
? ? ? ? ?zzDonIDGetPrices = VorigeO[Value3];
? ? ? ?If Price = High then
? ? ? ? ?zzDonIDGetPrices = VorigeH[Value3];
? ? ? ?If Price = Low then
? ? ? ? ?zzDonIDGetPrices = VorigeL[Value3];
? ? ? ?If Price = Close then
? ? ? ? ? zzDonIDGetPrices = VorigeC[Value3];
? ?End;
? ?Value1 = -1;
End;
Value1 = Value1 + 1;
end;
Functie: (voor MA)
Value function zzDonIDAverage (value Price,value AvgLen)begin
Value WeekAvg[],xPrice[];
Array:WkODAvg[200](0);
xPrice=zzDonIDGetPrices(Price);
WeekAvg = 0;
IF Date<>Date[-1] Then Begin
For Value1 = AvgLen DownTo 2 Begin
? ? ? WkODAvg[Value1] = WkODAvg[Value1-1];
End;
WkODAvg[1] = xPrice;
End;
IF WkODAvg[AvgLen] <> 0 Then Begin
For Value2 = 1 To ?AvgLen Begin
WeekAvg = WeekAvg + WkODAvg[Value2];
End;
zzDonIDAverage = WeekAvg / AvgLen;
End;
end;
Functie: (Voor EMA)
Value function zzDonIDxAverage (value Price,value AvgLen)begin
Value xPrice[];
value zzDonIDxxAverage=0;
xPrice=zzDonIDGetPrices(Price);
IF date<>date[-1] Then Begin
if (AvgLen<1) then zzDonIDxxAverage := xPrice else if zzDonIDxxAverage=0 or zzDonIDxxAverage=_NA then zzDonIDxxAverage := xPrice
else begin
? value xFactor;
?
? ?
? ?xFactor := 2/(AvgLen+1);
? zzDonIDxxAverage = xFactor*xPrice+(1-xFactor)*zzDonIDxxAverage;
? end;
? end;
?
zzDonIDxAverage := zzDonIDxxAverage;
end;
Functie: (voor MACD)
value function zzDonIDMACD (value Price,value xSlowlength,value xFastLength) begin
value xFast[],xSlow[],xMACD[];
xSlow=zzDonIDxAverage(Price,xSlowLength);
xFast=zzDonIDxAverage(Price,xFastLength);
xMACD=xFast-xSlow;
zzDonIDMACD=xMACD;
end;
Functie: (voor MACD Signal)
value function zzDonIDSignalMACD (value Price,value xSlowlength,value xFastLength,value AvgLen) begin
value WeekAvg[], xMACD[],xSignal,zzDonIDxSignalMACD=0;
xMACD=zzDonIDMACD(Price,xSlowLength,xFastLength);
IF Date<>date[-1] Then Begin
if (AvgLen<1) then zzDonIDxSignalMACD := xMACD else if zzDonIDxSignalMACD=0 or zzDonIDxSignalMACD=_NA then zzDonIDxSignalMACD := xMACD
else begin
? ?value xFactor;
?
? ?
? ? xFactor := 2/(AvgLen+1);
? ?zzDonIDxSignalMACD = xFactor*xMACD+(1-xFactor)*zzDonIDxSignalMACD;
? ?end;
? ?end;
zzDonIDSignalMACD =zzDonIDxSignalMACD;
End;
Indicator: (MA)
Value function zzDonIDMA (value Price=close,value xLength=9)begin
Value xDailyonID[];
xDailyonID=zzDonIDAverage(Price,xLength);
Plot1(xDailyonID," MA Dialy on ID");
end;
Indicator: (EMA)
Value function zzDonIDEMA (value Price=close,value xLength=9)begin
Value xDailyonID[];
xDailyonID=zzDonIDxAverage(Price,xLength);
Plot1(xDailyonID," EMA Dialy on ID");
end;
Indicator: (MACD)
value function zzDonIntraDMACD (value Price=close,value xSlowlength=26,value xFastLength=9,
value xSignalBars=9) begin
value xMACD[],xSignal,xDelta;
xMACD=zzDonIDMACD(Price,xSlowLength,xFastLength);
xSignal=zzDonIDSignalMACD(price,xSlowLength,xFastLength,xSignalBars);
xDelta=xMACD-xSignal;
Plot1(xDelta,'');
?Plot2(xSignal,'Signalline');
?Plot3(xMACD,'MACD');
end;
Paul