|
发表于 2008-12-25 10:42:22
|
显示全部楼层
/*[[
/*[[
Name := OsMA
Author := Copyright ?2003, MetaQuotes Software Corp.
Link := http://www.metaquotes.ru/
Separate Window := Yes
First Color := White
First Draw Type := Line
Use Second Data := Yes
Second Color := Red
Second Draw Type := Line
]]*/
Inputs : FastMAPeriod(3), SlowMAPeriod(13), SignalMAPeriod(3);
Variables : shift(0), cnt(0), sum(0), loopbegin1(0), loopbegin2(0), first(True), prevbars(0);
Variables : FastMA(0), SlowMA(0);
SetLoopCount(0);
// initial checkings
If FastMAPeriod < 1 Or SlowMAPeriod < 1 Or SignalMAPeriod < 1 Then Exit;
If FastMAPeriod >= SlowMAPeriod Then Exit;
// check for additional bars loading or total reloading
If Bars < prevbars Or Bars-prevbars>1 Then first = True;
prevbars = Bars;
// loopbegin1 and loopbegin2 prevent couning of counted bars exclude current
If first Then Begin
loopbegin1 = Bars-SlowMAPeriod-1;
If loopbegin1 < 0 Then Exit; // not enough bars for counting
loopbegin2 = Bars-SlowMAPeriod-SignalMAPeriod-2;
If loopbegin2 < 0 Then Exit; // not enough bars for counting
first = False; // this block is to be evaluated once only
End;
// convergence-divergence
loopbegin1 = loopbegin1+1; // current bar is to be recounted too
For shift = loopbegin1 Downto 0 Begin
FastMA = iMACDEx(FastMAPeriod,SlowMAPeriod,SignalMAPeriod,PRICE_CLOSE,MODE_MAIN,shift);
SlowMA = iMACDEx(FastMAPeriod,SlowMAPeriod,SignalMAPeriod,PRICE_CLOSE,MODE_SIGNAL,shift);
SetIndexValue(shift,FastMA-SlowMA);
loopbegin1 = loopbegin1-1; // prevent to previous bars recounting
End;
// signal line
loopbegin2 = loopbegin2+1; // current bar is to be recounted too
For shift = loopbegin2 Downto 0 Begin
sum = 0;
for cnt = 0 To SignalMAPeriod-1 Begin
sum = sum + GetIndexValue(shift+cnt);
End;
SetIndexValue2(shift,sum/SignalMAPeriod);
loopbegin2 = loopbegin2-1; // prevent to previous bars recounting
End; |
|