以下全以多头为例, 介绍此功能
if barpos>extgbdata('t') then
begin
extgbdataset('num',0);//记录当根K线的交易次数
extgbdataset('lossnum',0);//记录亏损次数,在新一根K线开始时,初始化为0
extgbdataset('t',barpos);//控制新的一根K线重新计算
end
if cond1 and tholding>0 then //cond1平仓条件
begin
tsell(1,1,mkt);
extgbdataset('num',extgbdata('num'+1));//平仓一次算一次交易
if c<tenterprice then extgbdataset('lossnum',extgbdata('lossnum')+1);//平仓时判断,是否亏损,并记录亏损次数
end
if cond2 and tholding=0 and extgbdata('lossnum')<3 then tbuy(1,1,mkt);//cond2开仓条件
全局变量使用注意事项:
策略运行过程中,手动平仓进行干预,请到"工具--数据--全局变量"里,将对应的全局变量清0,否则会引起开平仓混乱
“全局变量使用注意事项:
策略运行过程中,手动平仓进行干预,请到"工具--数据--全局变量"里,将对应的全局变量清0,否则会引起开平仓混乱。”