runmode:0;
input:riskratio(1,0,2,1);
input:atrlength(20,5,40,5);
input:period1(20,5,60,5);
input:period2(55,5,60,5);
input:period3(10,5,60,5);
variable:times:=0;
if barpos=1 then begin
preenteryprice:=0;
prebreakoutfailure:=false;
end
if barpos<=period1 then exit;
if date<1110104 then exit;
begin
if stricmp(marketlabel,'sq')=0 then
label:=strleft(stklabel,2);
if stricmp(marketlabel,'dq')=0 then
label:=strleft(stklabel,1);
if stricmp(marketlabel,'zq')=0 then
label:=strleft(stklabel,2);
if stricmp(marketlabel,'zj')=0 then
label:=strleft(stklabel,2);
if stricmp(label,'cf')=0 then begin
marginratio:=0.17;
commission:=12;
tradeable:=true;
end
if not(tradeable) then exit;
end
begin
atr:=trimprice(ref(ma(tr,atrlength),1));
topband1:=ref(hhv(high,period1),1)+mindiff;
botband1:=ref(llv(low,period1),1)-mindiff;
topband2:=ref(hhv(high,period2),1)+mindiff;
botband2:=ref(llv(low,period2),1)-mindiff;
topband3:=ref(hhv(high,period3),1)+mindiff;
botband3:=ref(llv(low,period3),1)-mindiff;
enterlongcond1:=high>=topband1;
enterlongprice1:=max(open,topband1);
entershortcond1:=low<=botband1;
entershortprice1:=min(open,botband1);
enterlongcond2:=high>=topband2;
enterlongprice2:=max(open,topband2);
entershortcond2:=low<=botband2;
entershortprice2:=min(open,botband2);
exitlongcond:=low<=botband3;
exitlongprice:=min(open,botband3);
exitshortcond:=high>=topband3;
exitshortprice:=max(open,topband3);
end
if holding=0 then begin
price:=0;
lots:=0;
if enterlongcond1 and prebreakoutfailure then
price:=enterlongprice1;
if enterlongcond2 then
price:=enterlongprice2;
if price>0 then begin
mycash:=cash(0);
lots1:=intpart(mycash/(price*multiplier*marginratio));
if riskratio=0 then begin
lots:=lots1;
end else begin
lots2:=intpart(mycash*0.01*riskratio/(atr*multiplier));
lots:=min(lots1,lots2);
end
end
if lots>=1 then begin
buy(1,lots,limitr,price);
times:=1;
prebreakoutfailure:=false;
end
end
if holding=0 then begin
price:=0;
lots:=0;
if entershortcond1 and prebreakoutfailure then
price:=entershortprice1;
if entershortcond2 then
price:=entershortprice2;
if price>0 then begin
mycash:=cash(0);
lots1:=intpart(mycash/(price*multiplier*marginratio));
if riskratio=0 then begin
lots:=lots1;
end else begin
lots2:=intpart(mycash*0.01*riskratio/(atr*multiplier));
lots:=min(lots1,lots2);
end
end
if lots>=1 then begin
buyshort(1,lots,limitr,price);
times:=1;
prebreakoutfailure:=false;
end
end
if holding>0 then begin
while high>=enterprice+0.5*atr and times<=4 do begin
price:=max(open,enterprice+0.5*atr);
lots:=0;
if price>0 then begin
mycash:=cash(0);
lots1:=intpart(mycash/(price*multiplier*marginratio));
if riskratio=0 then begin
lots:=lots1;
end else begin
lots2:=intpart(mycash*0.01*riskratio/(atr*multiplier));
lots:=min(lots1,lots2);
end
end
if lots>=1 then begin
buy(1,lots,limitr,price);
times:=times+1;
end
end
price:=0;
if exitlongcond then
price:=exitlongprice;
if low<=enterprice-2*atr and enterbars<>0 then begin
price:=min(open,enterprice-2*atr);
prebreakoutfailure:=true;
end
if price>0 then
sell(1,holding,limitr,price);
end
if holding<0 then begin
while low<=enterprice-0.5*atr and times<=4 do begin
price:=min(open,enterprice-0.5*atr);
lots:=0;
if price>0 then begin
mycash:=cash(0);
lots1:=intpart(mycash/(price*multiplier*marginratio));
if riskratio=0 then begin
lots:=lots1;
end else begin
lots2:=intpart(mycash*0.01*riskratio/(atr*multiplier));
lots:=min(lots1,lots2);
end
end
if lots>=1 then begin
buyshort(1,lots,limitr,price);
times:=times+1;
end
end
price:=0;
if exitshortcond then
price:=exitshortprice;
if high>=enterprice+2*atr and enterbars<>0 then begin
price:=max(open,enterprice+2*atr);
prebreakoutfailure:=true;
end
if price>0 then
sellshort(1,holding,limitr,price);
end
为何没有信号呢?
runmode: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)+mindiff;
entrylowerband:=ref(llv(low,entryperiod),1)-mindiff;
exitupperband:=ref(hhv(high,exitperiod),1)+mindiff;
exitlowerband:=ref(llv(low,exitperiod),1)-mindiff;
entrylongcond:=high>=entryupperband;
entryshortcond:=low<=entrylowerband;
exitlongcond:=low<=exitlowerband;
exitshortcond:=high>=exitupperband;
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 entryshortcond 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 exitlongcond then
price:=min(open,exitlowerband);
if low<=enterprice-2*atr 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*atr and enterbars>=1 then
price:=max(open,enterprice+2*atr);
if price>0 then
sellshort(1,holding,limitr,price);
end
盈亏:asset-500000,noaxis,colorred,linethick2;
哪个高手,能够加上注释那就好极了!