Runmade:0;
Input:riskratio(1,0,2,1)
Input:atrlength(20,5,30,5);
Input:entryperiod(20,5,60,5);
Input:exitperiod(10,5,60,5);
Variable:times=0;
atr:=ref(ma(tr,atrlength),1);
Marginratio:=10/100;
Entryupperband:=ref(hhv(high, entryperiod),1),1+mindff;
Entrylowerband:=ref(llv(low, entryperiod),1)-mindff;
Exitupperband=ref(hhv (high, entryperiod),1)+mindff;
Exitlowerband:=ref(llv(low, entryperiod),1)-mindff;
Entrylongcond:= high>=entryupperband;
Entryshortcond:= low>=entrylowerband;
Exitlongcond:= low<= eixtlowerband;
Exitshortcond:= high<= eixtupperband;
If holding=0 then begin
Price:=0;
Lots:=0;
If entrylongcond then
Price:=max(open, entryupperband);
If price>0 then begin
Mycash:=cash(0);
Lots1:=intpart(mycash/(price*multiplier*marginratio));
Lots2:=intpart((mycash*riskratio/100)/(atr*multiplier));
Lots:=max(1,min(Lots1, Lots2));
end
If lots>=1 then begin
Buy(1,lots,limitr,price);
times=1;
end
end
If holding>0 then begin
While high>=enterprice+atr/2 and times<4 do begin
Price:=max(open,enterprice+atr/2);
Lots:=0;
If price>0 then begin
mycash:=cash(0);
Lots1:=intpart(mycash/(price*multiplier*marginratio));
Lots2:=intpart((mycash*riskratio/100)/(atr*multiplier));
Lots:=max(1,min(Lots1, Lots2));
end
if lots>=1 then begin
buy(1,lots,limitr,price);
times=times+1;
end
end
end
If holding=0 then begin
Price:=0;
Lots:=0;
If entrylongcond then
price:=min(open,entrylowerband);
If Price>0 then begin
mycash:=cash(0);
Lots1:=intpart(mycash/(price*multiplier*marginratio));
Lots2:=intpart((mycash*riskratio/100)/(atr*multiplier));
Lots:=max(1,min(Lots1, Lots2));
end
If lots>=1 then begin
buyshort(1,lots,limitr,price);
times:=1;
end
end
If holding<0 then begin
While low<=enterprice-atr/2 and times<4 do begin
price:=min(open,enterprice-atr/2);
Lots:=0;
If Price>0 then begin
Mycash:=cash(0);
Lots1:=intpart(mycash/(price*multiplier*marginratio));
Lots2:=intpart((mycash*riskratio/100)/(atr*multiplier));
Lots:=max(1,min(Lots1, Lots2));
end
If lots>=1 then begin
buyshort(1,lots,limitr,price);
times=times+1;
end
end
end
If holding>0 then begin
Price: =0
If entrylongcond then
Price:=min(open,exitlowerband);
If low<=enterprice-2*art and enterbars>=1 then
Price:=min(open,enterprice-2*atr);
If price>0 then
Sell(1,holding,limitr,price);
end
If holding<0 then begin
Price: =0
If exitshortcond then
Price:=max(open,exitupperband);
If high>= enterprice+2*art and enterbars>=1 then
Price:=max(open,enterprice+2*atr);
If Price>0 then
Sellshort(1,holdine,limitr,price);
end
盈亏:Asset-500000,noaxis,colorred,linethick2;