input
:移动止盈(
60
,-
1
,
100
,
0.1
);
input
:阈值(
4
,-
1
,
100
,
0.1
);
input
:固定止损(
2
,
1
,
100
,
0.1
);
path:='
c
:\'&
formulaname
;
maxp_str:=
stklabel
&
'_'
&
'max'
;
dk_str:=
stklabel
&
'_'
&
'dk'
;
if
tbuyholdingex
(
''
,
''
,
1
)>
0
and
extgbdata
(dk_str)<=
0
then
begin
extgbdataset
(maxp_str,
tavgenterpriceex2
(
''
,
''
,
0
));
extgbdataset
(dk_str,
1
);
end
if
tsellholdingex
(
''
,
''
,
1
)>
0
and
extgbdata
(dk_str)>=
0
then
begin
extgbdataset
(maxp_str,
tavgenterpriceex2
(
''
,
''
,
1
));
extgbdataset
(dk_str,-
1
);
end
if
dynainfo
(
7
)>
extgbdata
(maxp_str)
and
extgbdata
(dk_str)>
0
and
tbuyholdingex
(
''
,
''
,
1
)>
0
then
begin
extgbdataset
(maxp_str,
dynainfo
(
7
));
debugfile
(path&
stklabel
&
'.txt'
,
stklabel
&
'的最高价更新:%.2f'
,
dynainfo
(
7
));
end
if
dynainfo
(
7
)<
extgbdata
(maxp_str)
and
extgbdata
(dk_str)<
0
and
tsellholdingex
(
''
,
''
,
1
)>
0
then
begin
extgbdataset
(maxp_str,
dynainfo
(
7
));
debugfile
(path&
stklabel
&
'.txt'
,
stklabel
&
'的最低价更新:%.2f'
,
dynainfo
(
7
));
end
maxp:=
extgbdata
(maxp_str);
多最大盈利:=maxp-
tavgenterpriceex2
(
''
,
''
,
0
);
空最大盈利:=
tavgenterpriceex2
(
''
,
''
,
1
)-maxp;
if
移动止盈>
0
then
begin
if
tbuyholdingex
(
''
,
''
,
1
)>
0
and
((阈值>
0
and
maxp>=
tavgenterpriceex2
(
''
,
''
,
0
)*(
1
+(阈值/
100
)))
or
阈值<
0
)
and
(
c
-
tavgenterpriceex2
(
''
,
''
,
0
))<=(
1
-移动止盈/
100
)*多最大盈利
then
begin
debugfile
(path&
stklabel
&
'.txt'
,
stklabel
&
'多回撤止盈'
,
0
);
debugfile
(path&
stklabel
&
'.txt'
,
stklabel
&
'最新价:%.2f'
,
c
);
debugfile
(path&
stklabel
&
'.txt'
,
stklabel
&
'持仓均价:%.2f'
,
tavgenterpriceex2
(
''
,
''
,
0
));
debugfile
(path&
stklabel
&
'.txt'
,
stklabel
&
'最大盈利价格:%.2f'
,maxp);
tsell
(
1
,
0
,
mkt
),
allowrepeat
;
extgbdataset
(maxp_str,
0
);
extgbdataset
(dk_str,
0
);
end
if
tsellholdingex
(
''
,
''
,
1
)>
0
and
((阈值>
0
and
maxp<=
tavgenterpriceex2
(
''
,
''
,
1
)*(
1
-(阈值/
100
)))
or
阈值<
0
)
and
(
tavgenterpriceex2
(
''
,
''
,
1
)-
c
)<=(
1
-移动止盈/
100
)*空最大盈利
then
begin
debugfile
(path&
stklabel
&
'.txt'
,
stklabel
&
'空回撤止盈'
,
0
);
debugfile
(path&
stklabel
&
'.txt'
,
stklabel
&
'最新价:%.2f'
,
c
);
debugfile
(path&
stklabel
&
'.txt'
,
stklabel
&
'持仓均价:%.2f'
,
tavgenterpriceex2
(
''
,
''
,
1
));
debugfile
(path&
stklabel
&
'.txt'
,
stklabel
&
'最大盈利价格:%.2f'
,maxp);
tsellshort
(
1
,
0
,
mkt
),
allowrepeat
;
extgbdataset
(maxp_str,
0
);
extgbdataset
(dk_str,
0
);
end
end
if
tbuyholdingex
(
''
,
''
,
1
)>
0
and
c
<=
tavgenterpriceex2
(
''
,
''
,
0
)*(
1
-(固定止损/
100
))
then
begin
debugfile
(path&
stklabel
&
'.txt'
,
stklabel
&
'多固定止损'
,
0
);
debugfile
(path&
stklabel
&
'.txt'
,
stklabel
&
'最新价:%.2f'
,
c
);
debugfile
(path&
stklabel
&
'.txt'
,
stklabel
&
'持仓均价:%.2f'
,
tavgenterpriceex2
(
''
,
''
,
0
));
tsell
(
1
,
0
,
mkt
),
allowrepeat
;
extgbdataset
(maxp_str,
0
);
extgbdataset
(dk_str,
0
);
end
if
tsellholdingex
(
''
,
''
,
1
)>
0
and
c
>=
tavgenterpriceex2
(
''
,
''
,
1
)*(
1
+(固定止损/
100
))
then
begin
debugfile
(path&
stklabel
&
'.txt'
,
stklabel
&
'空固定止损'
,
0
);
debugfile
(path&
stklabel
&
'.txt'
,
stklabel
&
'最新价:%.2f'
,
c
);
debugfile
(path&
stklabel
&
'.txt'
,
stklabel
&
'持仓均价:%.2f'
,
tavgenterpriceex2
(
''
,
''
,
1
));
tsellshort
(
1
,
0
,
mkt
),
allowrepeat
;
extgbdataset
(maxp_str,
0
);
extgbdataset
(dk_str,
0
);
end