写个大体的框架,你把对应的条件给带进去
思路是用全局变量来记录开仓条件a和其他开仓条件的状态
variable:n=0;
variable:m=0;
if 开仓条件a and holding=0 then begin
开仓语句;
n:=1;
end
if n=1 and m=0 and 任意的平仓条件 then begin//如果平仓条件太多,那么这句平仓代码要多谢几遍,枚举出所有的平仓条件
平仓语句........;
m:=1;
end
if m=1 and 其他开仓条件 then begin//同样的,如果其他开仓条件太多不能在一个if里面写完,那么这样的语句多谢几遍,把开仓条件逐一枚举
开仓语句......;
end
if time=closetime(0) then begin
n:=0;
m:=0;
end//重置全局变量为0
//判断当前持仓状态下的最大盈利
win:=0;
win2:=0;
if holding < 0 and enterbars > 0 then
begin
win:=(enterprice-c)/enterprice*100; //记录最大盈利
if win > maxprofit then
maxprofit:=win;
win2:=(maxprofit-win)/maxprofit*100; //最大盈利后的回调幅度
end
if holding > 0 and enterbars > 0 then
begin
win:=(c-enterprice)/enterprice*100; //记录最大盈利
if win > maxprofit then
maxprofit:=win;
win2:=(maxprofit-win)/maxprofit*100; //最大盈利后的回调幅度
end
你的意思是每个平仓的iF语句中都把上面这段嵌进去吗?
这个是原来代码有的你没有贴出来还是自己想加上去的?
如果是不是原有的就不要加,原来的代码意思已经满足了,不需要重置