
runmode:0;
input:length1(60);
input:length2(30);
variable:myholding=0;
variable:myprofit=0;
variable:myentryprice=0;
variable:myexitprice=0;
variable:myfailtrade=0;
entryupperband:=ref(hhv(high,length1),1);
entrylowerband:=ref(llv(low,length1),1);
entrylongcond:=high>=entryupperband;
entryshortcond:=low<=entrylowerband;
exitupperband:=ref(hhv(high,length2),1);
exitlowerband:=ref(llv(low,length2),1);
exitlongcond:=low<=exitlowerband;
exitshortcond:=high>=exitupperband;
if myholding=0 then begin
if entrylongcond then begin
myholding:=1;
myentryprice:=max(open,entryupperband);
end
end
if myholding=0 then begin
if entryshortcond then begin
myholding:=2;
myentryprice:=min(open,entrylowerband);
end
end
if myholding=1 then begin
if exitlongcond then begin
myholding:=0;
myexitprice:=min(open,exitlowerband);
myprofit:=myexitprice-myentryprice;
if myprofit<0 then
myfailtrade:=myfailtrade+1;
else
myfailtrade:=0;
end
end
if myholding=2 then begin
if exitshortcond then begin
myholding:=0;
myexitprice:=max(open,exitupperband);
myprofit:=myentryprice-myexitprice;
if myprofit<0 then
myfailtrade:=myfailtrade+1;
else
myfailtrade:=0;
end
end
if holding=0 and myfailtrade=1 then begin
if entrylongcond then
buy(1,1,limitr,max(open,entryupperband));
end
if holding=0 and myfailtrade=1 then begin
if entryshortcond then
buyshort(1,1,limitr,min(open,entrylowerband));
end
if holding>0 then begin
if exitlongcond then
sell(1,holding,limitr,min(open,exitlowerband));
end
if holding<0 then begin
if exitshortcond then
sellshort(1,holding,limitr,max(open,exitupperband));
end
盈亏:asset-50000,noaxis,colorred,linethick2;