input
:cyc(
10
,
1
,
100
,
2
);
runmode
:
0
;
variable
:step =
2
/
100
;
variable
:fmax =
20
/
100
;
variable
:sarx=
0
;
variable
:trendx=
0
;
variable
:ep=
0
;
variable
:af=
0
;
highprice:=
ref
(
hhv
(
c
,cyc),
1
);
lowprice:=
ref
(
llv
(
c
,cyc),
1
);
原始
sar
:
sar
(
10
,
2
,
20
);
if
barpos
<= cyc
then
exit
;
if
barpos
= cyc+
1
then
begin
af:=step;
ep:=-
1
;
if
(
high
[
barpos
]-
high
[
barpos
-
1
])+(
low
[
barpos
]-
low
[
barpos
-
1
]) >
0
then
begin
trendx:= -
1
;
sarx:=highprice;
end
else
begin
trendx:=
1
;
sarx:=lowprice;
end
goto
endandshow;
end
if
trendx >
0
then
begin
if
ep >
0
then
begin
sarx:=lowprice;
ep:=-
1
;
goto
endandshow;
end
if
high
> highprice
then
begin
af := af+step;
if
af > fmax
then
af := fmax;
end
fsar := sarx + af * (highprice - sarx);
if
fsar >
low
then
begin
trendx:=-
1
;
ep:=
1
;
af:=step;
end
sarx:=fsar;
end
else
begin
if
ep >
0
then
begin
sarx:=highprice;
ep:=-
1
;
goto
endandshow;
end
if
low
< lowprice
then
begin
af := af + step;
if
af > fmax
then
af := fmax;
end
fsar := sarx + af * (lowprice-sarx);
if
fsar <
high
then
begin
trendx :=
1
;
ep :=
1
;
af := step;
end
sarx := fsar;
end
endandshow@;
showsar:sarx;