12
返回列表 发新帖
楼主: 金字塔客服
打印 上一主题 下一主题

[公式] 基于 金字塔平台 编写的一些经典交易系统案例

  [复制链接]
21
 楼主| 发表于 2011-12-9 17:36:42 | 显示全部楼层
置换移动均线系统

//////////////////////////////////////////////
runmode:0;

ma3x3:=ref(ma(close,3),3);
ma7x5:=ref(ma(close,7),5);
ma25x5:=ref(ma(close,25),5);

entrylongcond:=close>ma3x3 and ma3x3>ma7x5 and ma7x5>ma25x5;
exitlongcond:=ma3x3<MA7X5;

entryshortcond:=close<MA3X3
exitshortcond:=ma3x3>ma7x5;

if holding=0 then begin
if entrylongcond then
buy(1,1,limitr,close);

if entryshortcond then
buyshort(1,1,limitr,close);
end

if holding>0 then begin
if exitlongcond then
sell(1,holding,limitr,close);
end

if holding<0 then begin
if exitshortcond then
sellshort(1,holding,limitr,close);
end

盈亏:asset-500000,noaxis,coloryellow,linethick2;


/////////////////////////////////////////////
22
 楼主| 发表于 2011-12-9 17:38:05 | 显示全部楼层
肯特纳系统
//////////////////////////////////////////

runmode:0;
input:avglength(40),atrlength(40);
ma1:=ref(ma((high+low+close)/3,avglength),1);
upperband:=ma1+ref(ma(tr,atrlength),1);
lowerband:=ma1-ref(ma(tr,atrlength),1);

entrylongcond:=ma1>ref(ma1,1) and high>=upperband;
exitlongcond:=low<=ma1;

entryshortcond:=ma1<ref(ma1,1) and low<=lowerband;
exitshortcond:=high>=ma1;

if holding=0 then begin
if entrylongcond then
  buy(1,1,limitr,max(open,upperband));
end

if holding=0 then begin
if entryshortcond then
  buyshort(1,1,limitr,min(open,lowerband));
end

if holding>0 then begin
if exitlongcond then
  sell(1,holding,limitr,min(open,ma1));
end

if holding<0 then begin
if exitshortcond then
  sellshort(1,holding,limitr,max(open,ma1));
end

盈亏:asset-50000,noaxis,colorred,linethick2;



/////////////////////////////////////////
23
 楼主| 发表于 2011-12-9 17:39:28 | 显示全部楼层
布林强盗系统

//////////////////////////////////////

runmode:0;
input:bollingerlengths(50);
input:liqlength(50);
input:roccalclength(30);

mid:=ma(close,bollingerlengths);
upperband:=ref(mid+1.25*std(close,bollingerlengths),1);
lowerband:=ref(mid-1.25*std(close,bollingerlengths),1);

roccalc:=close-ref(close,roccalclength-1);
entrylongcond:=roccalc>0 and high>=upperband;
entryshortcond:=roccalc<0 and low<=lowerband;

if holding=0 then begin
if entrylongcond then
  buy(1,1,limitr,max(open,upperband));
end

if holding=0 then begin
if entryshortcond then
  buyshort(1,1,limitr,min(open,lowerband));
end

if holding>0 then begin
if entryshortcond then begin
  sell(1,holding,limitr,min(open,lowerband));
  buyshort(1,1,limitr,min(open,lowerband));
end
end

if holding<0 then begin
if entrylongcond then begin
  sellshort(1,holding,limitr,max(open,upperband));
  buy(1,1,limitr,max(open,lowerband));
end
end

if holding=0 then
liqdays:=liqlength;

if holding<>0 then begin
liqdays:=liqdays-1;
liqdays:=max(liqdays,10);
end

ma1:=ref(ma(close,liqdays),1);
if holding>0 then begin
if ma1<upperband and low<=ma1 then
  sell(1,holding,limitr,min(open,ma1));
end

if holding<0 then begin
if ma1>lowerband and high>=ma1 then
  sellshort(1,holding,limitr,max(open,ma1));
end

盈亏:asset-50000,noaxis,colorred,linethick2;



//////////////////////////////////////
24
 楼主| 发表于 2011-12-9 17:46:03 | 显示全部楼层
超级日内组合策略

/////////////////////////////////////////////
runmode:0;
input:waitperiodmins(30);
input:inittradesendtime(143000);
input:liqrevendtime(110000);
input:thrustprcnt1(0.3);
input:thrustprcnt2(0.6);
input:breakoutprcnt(0.25);
input:failedbreakoutprcnt(0.25);
input:protstopprcnt1(0.25);
input:protstopprcnt2(0.15);
input:protstopamt(3);
input:breakevenprcnt(0.5);
input:avgrnglength(10);
input:avgoclength(10);

variable:averagerange=0;
variable:averageocrange=0;
variable:cantrade=0;
variable:buyeasierday=false;
variable:selleasierday=false;
variable:buybopoint=0;
variable:sellbopoint=0;
variable:longbreakpt=0;
variable:shortbreakpt=0;
variable:longfbopoint=0;
variable:shortfbopoint=0;
variable:barcount=0;
variable:intrahigh=0;
variable:intralow=999999;
variable:buystoday=0;
variable:sellstoday=0;
variable:currtrdtype=0;
variable:longliqpoint=0;
variable:shortliqpoint=0;
variable:yesterdayocrrange=0;
variable:intratradehigh=0;
variable:intratradelow=999999;

m1:=ref(ma(callstock(stklabel,vthigh,6,0)-callstock(stklabel,vtlow,6,0),10),1);
m2:=ref(ma(abs(callstock(stklabel,vtopen,6,0)-callstock(stklabel,vtclose,6,0)),10),1);
m3:=ref(llv(low,3),1);
m4:=ref(hhv(high,3),1);

if date>ref(date,1) then begin
averagerange:=m1;
yesterdayocrrange:=abs(open-close);
averageocrange:=m2;
cantrade:=0;

if yesterdayocrrange<0.85*averageocrange then cantrade:=1;
buyeasierday:=false;
selleasierday:=false;

if callstock(stklabel,vtclose,6,-1)<=callstock(stklabel,vtclose,6,-2) then buyeasierday:=true;
if callstock(stklabel,vtclose,6,-1)>callstock(stklabel,vtclose,6,-2) then selleasierday:=true;

if buyeasierday then begin
  buybopoint:=callstock(stklabel,vtopen,6,0)+thrustprcnt1*averagerange;
  sellbopoint:=callstock(stklabel,vtopen,6,0)-thrustprcnt2*averagerange;
end

if selleasierday then begin
  sellbopoint:=callstock(stklabel,vtopen,6,0)-thrustprcnt1*averagerange;
  buybopoint:=callstock(stklabel,vtopen,6,0)+thrustprcnt2*averagerange;
end

longbreakpt:=callstock(stklabel,vthigh,6,-1)+breakoutprcnt*averagerange;
shortbreakpt:=callstock(stklabel,vtlow,6,-1)-breakoutprcnt*averagerange;
shortfbopoint:=callstock(stklabel,vthigh,6,-1)-failedbreakoutprcnt*averagerange;
longfbopoint:=callstock(stklabel,vtlow,6,-1)+failedbreakoutprcnt*averagerange;

barcount:=0;
intrahigh:=0;
intralow:=999999;
buystoday:=0;
sellstoday:=0;
currtrdtype:=0;
end

if high>intrahigh then intrahigh:=high;
if low<intralow then intralow:=low;

barcount:=barcount+1;
if barcount>waitperiodmins/datatype and cantrade=1 then begin
if holding=0 then begin
  intratradehigh:=0;
  intratradelow:=999999;
end

if holding>0 then begin
  intratradehigh:=max(intratradehigh,high);
  buystoday:=1;
end

if holding<0 then begin
  intratradelow:=min(intratradelow,low);
  sellstoday:=1;
end

if buystoday=0 and time<inittradesendtime then
  LBreakOut:buy(1,1,stop,buybopoint);
  
if sellstoday=0 and time<inittradesendtime then
  SBreakout:sellshort(1,1,stop,sellbopoint);
  
if intrahigh>longbreakpt and sellstoday=0 and time<inittradesendtime then
  SfailedBO:sellshort(1,1,stop,shortfbopoint);
  
if intralow<shortbreakpt and buystoday=0 and time<inittradesendtime then
  BfeiledBO:buy(1,1,stop,longfbopoint);
  
if holding>0 then begin
  longliqpoint:=enterprice-protstopprcnt1*averagerange;
  longliqpoint:=min(longliqpoint,enterprice-protstopamt);
  
  if ref(holding,1)<0 and enterbars>=1 and ref(high,1)>=shortliqpoint and shortliqpoint<shortfbopoint then
   currtrdtype:=-2;
  
  if currtrdtype=-2 then begin
   longliqpoint:=enterprice-protstopprcnt2*averagerange;
   longliqpoint:=min(longliqpoint,enterprice-protstopamt);
  end
  
  if intratradehigh>=enterprice+breakevenprcnt*averagerange then
   longliqpoint:=enterprice;
   
  if time>=inittradesendtime then
   longliqpoint:=max(longliqpoint,m3);
   
  if time<liqrevendtime and sellstoday=0 and longliqpoint<>enterprice and enterbars>=4 then begin
   LongLiqRev:sellshort(1,1,stop,longliqpoint);
  end else begin
   LongLiq:sell(1,1,stop,longliqpoint);
  end   
end  

if holding<0 then begin
  shortliqpoint:=enterprice+protstopprcnt1*averagerange;
  shortliqpoint:=max(shortliqpoint,enterprice+protstopamt);
  
  if ref(holding,1)<0 and enterbars>=1 and ref(low,1)<longliqpoint and longliqpoint>longfbopoint then
   currtrdtype:=2;
   
  if currtrdtype=2 then begin
   shortliqpoint:=enterprice+protstopprcnt2*averagerange;
   shortliqpoint:=max(shortliqpoint,enterprice+protstopamt);
  end
  
  if intratradelow<=enterprice-breakevenprcnt*averagerange then
   shortliqpoint:=enterprice;
   
  if time>=inittradesendtime then
   shortliqpoint:=min(shortliqpoint,m4);
   
  if time<liqrevendtime and buystoday=0 and shortliqpoint<>enterprice and enterbars>=4 then begin
   ShortLiqRev:buy(1,1,stop,shortliqpoint);
  end else begin
   ShortLiq:sellshort(1,1,stop,shortliqpoint);
  end   
end
end

if time>=closetime(0) then begin
sell(1,holding,limitr,close);
sellshort(1,holding,limitr,close);
end

盈亏:asset-500000,noaxis,coloryellow,linethick2;

/////////////////////////////////////////////


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册入住  

x
25
 楼主| 发表于 2011-12-9 17:47:52 | 显示全部楼层
期货废人 发表于 2011-12-9 17:41
不说明用法,列举出来有什么用呢?

请自己体会,
饭不该要有人喂才会吃的啊。
26
 楼主| 发表于 2011-12-9 17:50:10 | 显示全部楼层
本帖最后由 金字塔客服 于 2011-12-9 17:51 编辑

菲阿里突破
//////////////////////////////////////////

runmode:0;

variable:longtrade=0;
variable:shorttrade=0;
variable:stopline=0;

predayhigh:=callstock(stklabel,vthigh,6,-1);
predaylow:=callstock(stklabel,vtlow,6,-1);
predayrange:=(predayhigh-predaylow)*0.5;
predayrange:=round(predayrange/mindiff)*mindiff;

dayopen:=callstock(stklabel,vtopen,6,0);

trailingstop:=predayrange;

dist:=barslast(date>ref(date,1))+1;

myentrytime:=time<=145500;
myexittime:=time>=150000;

upperband:=ref(hhv(high,dist),1);
lowerband:=ref(llv(low,dist),1);

hh:=ref(high,1);
ll:=ref(low,1);

if holding=0 then begin
if myentrytime and dayopenpredaylow then begin
if high>=predayhigh and longtrade=0 then begin
buy(1,1,limitr,max(open,predayhigh));
longtrade:=1;
end

if low<=predaylow and shorttrade=0 then begin
buyshort(1,1,limitr,min(open,predaylow));
shorttrade:=1;
end
end

if myentrytime and dayopen>=predayhigh then begin
if dist>=4 and high>=upperband and longtrade=0 then begin
buy(1,1,limitr,max(open,upperband));
longtrade:=1;
end
end

if myentrytime and dayopen<=predaylow then begin
if dist>=4 and low<=lowerband and shorttrade=0 then begin
buyshort(1,1,limitr,min(open,lowerband));
shorttrade:=1;
end
end
end

if holding>0 and enterbars>=1 then begin
myexitprice:=0;

if stopline=0 then
stopline:=enterprice-trailingstop;

if hh-trailingstop>stopline then
stopline:=hh-trailingstop;

if low<=stopline then
myexitprice:=min(open,stopline);

if myexittime then
myexitprice:=close;

if myexitprice>0 then begin
sell(1,holding,limitr,myexitprice);
stopline:=0;
end
end

if holding<0 and enterbars>=1 then begin
myexitprice:=0;

if stopline=0 then
stopline:=enterprice+1000;

if ll+trailingstop<STOPLINE then="then"
stopline:=ll+trailingstop;

if high>=stopline then
myexitprice:=max(open,stopline);

if myexittime then
myexitprice:=close;

if myexitprice>0 then begin
sellshort(1,holding,limitr,myexitprice);
stopline:=0;
end
end

if myexittime then begin
longtrade:=0;
shorttrade:=0;
end

盈亏:asset-500000,noaxis,coloryellow,linethick2;

//////////////////////////////////////////

27
 楼主| 发表于 2011-12-9 17:53:10 | 显示全部楼层
心手合一 发表于 2011-12-9 17:49
其实有时候简单的才是最有效的。

萝卜青菜,各有所爱,
粥粉面饭,皆有所喜。
28
 楼主| 发表于 2011-12-20 15:18:09 | 显示全部楼层
为了支持金字塔全速发展,切实解决塔友实际困难
响应金字塔号召
特公布此模板

只要把此模板放在 模型的最后面,就可以后台全自动化交易了。
有个性化需求的,也可在此模板上的基础上定制。

runmode:0;
Globalvariable:hold=drawnull;
……//这里添加上你自己的模型

……//这里添加上你自己的模型
cc800988:=holding;//这句放在信号稳定的地方
drawtextex(1,1,800,0,'虚拟持仓为:'+numtostr(cc800988,0));//在图表上输入虚拟持仓以便监控
if not(islastbar) or workmode<>1 then exit;
xiadan800988:=cc800988-hold;
if xiadan800988>0.5 then begin
cang:=min(xiadan800988,abs(hold));
if hold<0 then begin
  tsellshort(1,cang,mkt,0,0,'800988'),allowrepeat;
  debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 平空 %.0f',cang);
end
cang:=xiadan800988+min(hold,0);
if cang>0 then begin
  tbuy(1,cang,mkt,0,0,'800988'),allowrepeat;
  debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 开多 %.0f',cang);
end
end
if xiadan800988<-0.5 then begin
cang:=min(abs(xiadan800988),abs(hold));
if hold>0 then begin
  tsell(1,cang,mkt,0,0,'800988'),allowrepeat;
  debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 平多 %.0f',cang);
end
cang:=abs(xiadan800988)-max(hold,0);
if cang>0 then begin
  tbuyshort(1,cang,mkt,0,0,'800988'),allowrepeat;
  debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 开空 %.0f',cang);
end
end
hold:=cc800988;





完整实例如下:
实例一、 K线走完模式的模型
Globalvariable:hold=drawnull;
cc800988:=holding;//这句放在信号稳定的地方

//蓝色部分改为你自己的模型(K线走完模型)
buycond:=count(c>o,2)=2;
sellcond:=count(c<o,2)=2;
if holding>0 and sellcond then sell(1,1,thisclose);
if holding<0 and buycond then sellshort(1,1,thisclose);
if holding=0 and buycond then buy(1,1,thisclose);
if holding=0 and sellcond then buyshort(1,1,thisclose);


drawtextex(1,1,800,0,'虚拟持仓为:'+numtostr(cc800988,0));//在图表上输入虚拟持仓以便监控
if not(islastbar) or workmode<>1 then exit;
xiadan800988:=cc800988-hold;
if xiadan800988>0.5 then begin
cang:=min(xiadan800988,abs(hold));
if hold<0 then begin
  tsellshort(1,cang,mkt,0,0,'800988'),allowrepeat;
  debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 平空 %.0f',cang);
end
cang:=xiadan800988+min(hold,0);
if cang>0 then begin
  tbuy(1,cang,mkt,0,0,'800988'),allowrepeat;
  debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 开多 %.0f',cang);
end
end
if xiadan800988<-0.5 then begin
cang:=min(abs(xiadan800988),abs(hold));
if hold>0 then begin
  tsell(1,cang,mkt,0,0,'800988'),allowrepeat;
  debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 平多 %.0f',cang);
end
cang:=abs(xiadan800988)-max(hold,0);
if cang>0 then begin
  tbuyshort(1,cang,mkt,0,0,'800988'),allowrepeat;
  debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 开空 %.0f',cang);
end
end
hold:=cc800988;




实例二、即时下单模型(固定时间间隔)
Globalvariable:hold=drawnull;
//蓝色部分改为你自己的模型
buycond:=h>ref(hhv(h,10),1);
sellcond:=l<ref(llv(l,10),1);
if holding>0 and sellcond then sell(1,1,market);
if holding<0 and buycond then sellshort(1,1,market);
if holding=0 and buycond then buy(1,1,market);
if holding=0 and sellcond then buyshort(1,1,market);

cc800988:=holding;//这句放在信号稳定的地方

drawtextex(1,1,800,0,'虚拟持仓为:'+numtostr(cc800988,0));//在图表上输入虚拟持仓以便监控
if not(islastbar) or workmode<>1 then exit;
xiadan800988:=cc800988-hold;
if xiadan800988>0.5 then begin
cang:=min(xiadan800988,abs(hold));
if hold<0 then begin
  tsellshort(1,cang,mkt,0,0,'800988'),allowrepeat;
  debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 平空 %.0f',cang);
end
cang:=xiadan800988+min(hold,0);
if cang>0 then begin
  tbuy(1,cang,mkt,0,0,'800988'),allowrepeat;
  debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 开多 %.0f',cang);
end
end
if xiadan800988<-0.5 then begin
cang:=min(abs(xiadan800988),abs(hold));
if hold>0 then begin
  tsell(1,cang,mkt,0,0,'800988'),allowrepeat;
  debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 平多 %.0f',cang);
end
cang:=abs(xiadan800988)-max(hold,0);
if cang>0 then begin
  tbuyshort(1,cang,mkt,0,0,'800988'),allowrepeat;
  debugfile('D:\800988.txt',numtostr(hold,0)+' '+numtostr(cc800988,0)+' 开空 %.0f',cang);
end
end
hold:=cc800988;

--------------------------------
leevolvo原创

29
 楼主| 发表于 2012-1-24 22:08:38 | 显示全部楼层
祝所有金字塔用户 爱好者 新春大吉 龙年大发!
30
 楼主| 发表于 2012-1-30 01:24:24 | 显示全部楼层
[交易系统]顾比倒数线策略
h11:=high;
l11:=low;
a:=ifelse(high>=ref(high,1)&&high>=ref(high,2)&&high>=ref(high,3) &&high>=ref(high,4)&&high>=ref(high,5),low,0);
b:=ifelse(low<=ref(low,1)&&low<=ref(low,2)&&low<=ref(low,3) &&low<=ref(low,4)&&low<=ref(low,5),high,888888);
p1:=ifelse(a>ref(l11,1),ref(l11,1),0);
p2:=ifelse(a>ref(l11,2)&&a<=ref(l11,1),ref(l,2),0);
p3:=ifelse(a>ref(l11,3)&&a<=ref(l11,1)&&a<=ref(l11,2),ref(l11,3),0);
p4:=ifelse(a>ref(l11,4)&&a<=ref(l11,1)&&a<=ref(l11,2)&&a<=ref(l11,3),ref(l11,4),0);
p5:=ifelse(a>ref(l11,5)&&a<=ref(l11,1)&&a<=ref(l11,2)&&a<=ref(l11,3)&&a<=ref(l11,4),ref(l11,5),0);
p6:=ifelse(a>ref(l11,6)&&a<=ref(l11,1)&&a<=ref(l11,2)&&a<=ref(l11,3)&&a<=ref(l11,4)&&a<=ref(l11,5),ref(l11,6),0);
p7:=ifelse(a>ref(l11,7)&&a<=ref(l11,1)&&a<=ref(l11,2)&&a<=ref(l11,3)&&a<=ref(l11,4)&&a<=ref(l11,5)&&a<=ref(l11,6),ref(l11,7),0);
p8:=ifelse(a>ref(l11,8)&&a<=ref(l11,1)&&a<=ref(l11,2)&&a<=ref(l11,3)&&a<=ref(l11,4)&&a<=ref(l11,5)&&a<=ref(l11,6)&&a<=ref(l11,7),ref(l11,8),0);
p9:=ifelse(a>ref(l11,9)&&a<=ref(l11,1)&&a<=ref(l11,2)&&a<=ref(l11,3)&&a<=ref(l11,4)&&a<=ref(l11,5)&&a<=ref(l11,6)&&a<=ref(l11,7)&&a<=ref(l11,8),ref(l11,9),0);
p10:=ifelse(a>ref(l11,10)&&a<=ref(l11,1)&&a<=ref(l11,2)&&a<=ref(l11,3)&&a<=ref(l11,4)&&a<=ref(l11,5)&&a<=ref(l11,6)&&a<=ref(l11,7)&&a<=ref(l11,8)&&a<=ref(l11,9),ref(l11,10),0);
aa:=p1+p2+p3+p4+p5+p6+p7+p8+p9+p10;
pp1:=ifelse(aa>ref(l11,1),ref(l11,1),0);
pp2:=ifelse(aa>ref(l11,2)&&aa<=ref(l11,1),ref(l11,2),0);
pp3:=ifelse(aa>ref(l11,3)&&aa<=ref(l11,1)&&aa<=ref(l11,2),ref(l11,3),0);
pp4:=ifelse(aa>ref(l11,4)&&aa<=ref(l11,1)&&aa<=ref(l11,2)&&aa<=ref(l11,3),ref(l11,4),0);
pp5:=ifelse(aa>ref(l11,5)&&aa<=ref(l11,1)&&aa<=ref(l11,2)&&aa<=ref(l11,3)&&aa<=ref(l11,4),ref(l11,5),0);
pp6:=ifelse(aa>ref(l11,6)&&aa<=ref(l11,1)&&aa<=ref(l11,2)&&aa<=ref(l11,3)&&aa<=ref(l11,4)&&aa<=ref(l11,5),ref(l11,6),0);
pp7:=ifelse(aa>ref(l11,7)&&aa<=ref(l11,1)&&aa<=ref(l11,2)&&aa<=ref(l11,3)&&aa<=ref(l11,4)&&aa<=ref(l11,5)&&aa<=ref(l11,6),ref(l11,7),0);
pp8:=ifelse(aa>ref(l11,8)&&aa<=ref(l11,1)&&aa<=ref(l11,2)&&aa<=ref(l11,3)&&aa<=ref(l11,4)&&aa<=ref(l11,5)&&aa<=ref(l11,6)&&aa<=ref(l11,7),ref(l11,8),0);
pp9:=ifelse(aa>ref(l11,9)&&aa<=ref(l11,1)&&aa<=ref(l11,2)&&aa<=ref(l11,3)&&aa<=ref(l11,4)&&aa<=ref(l11,5)&&aa<=ref(l11,6)&&aa<=ref(l11,7)&&aa<=ref(l11,8),ref(l11,9),0);
pp10:=ifelse(aa>ref(l11,10)&&aa<=ref(l11,1)&&aa<=ref(l11,2)&&aa<=ref(l11,3)&&aa<=ref(l11,4)&&aa<=ref(l11,5)&&aa<=ref(l11,6)&&aa<=ref(l11,7)&&aa<=ref(l11,8)&&aa<=ref(l11,9),ref(l11,10),0);
aaa:=pp1+pp2+pp3+pp4+pp5+pp6+pp7+pp8+pp9+pp10;
c11:=valuewhen(aaa>0,aaa);
t1:=ifelse(b<ref(h11,1),ref(h11,1),0);
t2:=ifelse(b<ref(h11,2)&&b>=ref(h11,1),ref(h11,2),0);
t3:=ifelse(b<ref(h11,3)&&b>=ref(h11,1)&&b>=ref(h11,2),ref(h11,3),0);
t4:=ifelse(b<ref(h11,4)&&b>=ref(h11,1)&&b>=ref(h11,2)&&b>=ref(h11,3),ref(h11,4),0);
t5:=ifelse(b<ref(h11,5)&&b>=ref(h11,1)&&b>=ref(h11,2)&&b>=ref(h11,3)&&b>=ref(h11,4),ref(h11,5),0);
t6:=ifelse(b<ref(h11,6)&&b>=ref(h11,1)&&b>=ref(h11,2)&&b>=ref(h11,3)&&b>=ref(h11,4)&&b>=ref(h11,5),ref(h11,6),0);
t7:=ifelse(b<ref(h11,7)&&b>=ref(h11,1)&&b>=ref(h11,2)&&b>=ref(h11,3)&&b>=ref(h11,4)&&b>=ref(h11,5)&&b>=ref(h11,6),ref(h11,7),0);
t8:=ifelse(b<ref(h11,8)&&b>=ref(h11,1)&&b>=ref(h11,2)&&b>=ref(h11,3)&&b>=ref(h11,4)&&b>=ref(h11,5)&&b>=ref(h11,6)&&b>=ref(h11,7),ref(h11,8),0);
t9:=ifelse(b<ref(h11,9)&&b>=ref(h11,1)&&b>=ref(h11,2)&&b>=ref(h11,3)&&b>=ref(h11,4)&&b>=ref(h11,5)&&b>=ref(h11,6)&&b>=ref(h11,7)&&b>=ref(h11,8),ref(h11,9),0);
t10:=ifelse(b<ref(h11,10)&&b>=ref(h11,1)&&b>=ref(h11,2)&&b>=ref(h11,3)&&b>=ref(h11,4)&&b>=ref(h11,5)&&b>=ref(h11,6)&&b>=ref(h11,7)&&b>=ref(h11,8)&&b>=ref(h11,9),ref(h11,10),0);
bb:=ifelse((t1+t2+t3+t4+t5+t6+t7+t8+t9+t10)=0,888888,t1+t2+t3+t4+t5+t6+t7+t8+t9+t10);
tt1:=ifelse(bb<ref(h11,1),ref(h11,1),0);
tt2:=ifelse(bb<ref(h11,2)&&bb>=ref(h11,1),ref(h11,2),0);
tt3:=ifelse(bb<ref(h11,3)&&bb>=ref(h11,1)&&bb>=ref(h11,2),ref(h11,3),0);
tt4:=ifelse(bb<ref(h11,4)&&bb>=ref(h11,1)&&bb>=ref(h11,2)&&bb>=ref(h11,3),ref(h11,4),0);
tt5:=ifelse(bb<ref(h11,5)&&bb>=ref(h11,1)&&bb>=ref(h11,2)&&bb>=ref(h11,3)&&bb>=ref(h11,4),ref(h11,5),0);
tt6:=ifelse(bb<ref(h11,6)&&bb>=ref(h11,1)&&bb>=ref(h11,2)&&bb>=ref(h11,3)&&bb>=ref(h11,4)&&bb>=ref(h11,5),ref(h11,6),0);
tt7:=ifelse(bb<ref(h11,7)&&bb>=ref(h11,1)&&bb>=ref(h11,2)&&bb>=ref(h11,3)&&bb>=ref(h11,4)&&bb>=ref(h11,5)&&bb>=ref(h11,6),ref(h11,7),0);
tt8:=ifelse(bb<ref(h11,8)&&bb>=ref(h11,1)&&bb>=ref(h11,2)&&bb>=ref(h11,3)&&bb>=ref(h11,4)&&bb>=ref(h11,5)&&bb>=ref(h11,6)&&bb>=ref(h11,7),ref(h11,8),0);
tt9:=ifelse(bb<ref(h11,9)&&bb>=ref(h11,1)&&bb>=ref(h11,2)&&bb>=ref(h11,3)&&bb>=ref(h11,4)&&bb>=ref(h11,5)&&bb>=ref(h11,6)&&bb>=ref(h11,7)&&bb>=ref(h11,8),ref(h11,9),0);
tt10:=ifelse(bb<ref(h11,10)&&bb>=ref(h11,1)&&bb>=ref(h11,2)&&bb>=ref(h11,3)&&bb>=ref(h11,4)&&bb>=ref(h11,5)&&bb>=ref(h11,6)&&bb>=ref(h11,7)&&bb>=ref(h11,8)&&bb>=ref(h11,9),ref(h11,10),0);
bbb:=tt1+tt2+tt3+tt4+tt5+tt6+tt7+tt8+tt9+tt10;
d:=valuewhen(bbb>0,bbb);
ud:=ifelse(close>d&&ref(close,1)<=d,1,ifelse(close<c11&&ref(close,1)>=c11,-3,0));
k:=valuewhen(ud<>0,ud);
g:=ifelse(k=1,c11,d),colorred;
g1:=valuewhen(islastbar,g);
tmp:=-k;
//tmp>0,spk;
//tmp<=0,bpk;

if holding=0 then begin
if tmp<=0 then
  buy(1,1,limitr,close);
end

if holding=0 then begin
if tmp>0 then
  buyshort(1,1,limitr,close);  
end

if holding>0 then begin
if tmp>0 then begin
  sell(1,holding,limitr,close);
  buyshort(1,1,limitr,close);
end
end

if holding<0 then begin
if tmp<=0 then begin
  sellshort(1,holding,limitr,close);
  buy(1,1,limitr,close);
end
end
   
收益:asset,noaxis,colorred;
次数:totaltrade,linethick0;
胜率:percentwin,linethick0;
连亏:maxseqloss,linethick0;
连赢:maxseqwin,linethick0;



31
 楼主| 发表于 2012-2-5 18:24:50 | 显示全部楼层
以下源自 黑洞

交易分钟数 := OPENMINUTES(TIME) , LINETHICK0 ;
{当日均价}
当日周期 := IF(LLV(DAY,0)=HHV(DAY,0),0,BARSLAST(DAY<>REF(DAY,1))+1),LINETHICK0 ;
当日均价 := SUM(AMOUNT,当日周期)/SUM(VOL,当日周期)/手;{IF(SUM(VOL,当日周期)=0,OPEN,SUM((OPEN+HIGH+LOW+CLOSE)/4*VOL,当日周期)/SUM(VOL,当日周期))} ,LINETHICK2 ,COLORWHITE ;
{计价取值}
昨结取值 := SETVAL(DAY<>REF(DAY,1),0,0,INTPART(REF(当日均价,1)-MOD(REF(当日均价,1),5))),LINETHICK2 ;
上日结算 := VALUEWHEN(昨结取值>REF(昨结取值,1),昨结取值)  ,LINETHICK0  ;
开盘取值 := SETVAL(DAY<>REF(DAY,1),0,0,OPEN),LINETHICK2 ;
当日开盘 := VALUEWHEN(开盘取值>REF(开盘取值,1),开盘取值)  ,LINETHICK1  ;
今日开盘 := IF(当日数据,DYNAINFO( 4),当日开盘)  ,LINETHICK0 ,COLORWHITE ;
{盈利锁定}
开盘净值 := REF(ASSET,交易分钟数),LINETHICK1 ;
盈利目标 := ASSET/开盘净值-1 ,LINETHICK0 ;
{外内盘差}
当前秒控 := MOD(DYNAINFO(207),100) ,LINETHICK0 ;
{开盘高低}
开盘高价 := REF(HIGH,交易分钟数-1) ,LINETHICK1 ,COLORRED ;
开盘低价 := REF(LOW,交易分钟数-1) ,LINETHICK1 ,COLORGREEN ;
昨持仓 := REF(持仓量,交易分钟数) ,COLORWHITE ,LINETHICK1;
增仓 := 持仓量-昨持仓 ,LINETHICK1;
32
 楼主| 发表于 2012-2-15 11:41:22 | 显示全部楼层
使用金字塔PEL语言实现的SAR算法,可以加工用户特定的移动止损功能.


//sar是个很有用的处理止损功能的函数,由于算法特殊,普通的软件的公式系统是无法进行描述的,这里我们将向大家展示金字塔PEL语言强大的算法描述功能,可以简单实现SAR算法功能。此外,用户可以通过该公式算法,加入自己的代码,进行特定的实盘操作。

INPUT:CYC(10,1,100,2);
RUNMODE:0; //使用逐周期运行模式

//保证variable声明的变量都尽量在公式的最前面,防止带有IF语句的分支执行影响变量的初始化
variable:Step = 2 / 100; //步长
variable:fMax = 20 / 100; //最大值

variable:sarx=0;
variable:Trend=0;
variable:EP=0;
variable:AF=0;

//计算高点低点的值放到IF前面,防止前面语句直接退出导致最前CYC个周期的数据无法统计到
highprice:=ref(hhv(high,cyc),1);
lowPrice:=ref(llv(low,cyc),1);

原始SAR:SAR(10,2,20);

if barpos <= Cyc then
exit;//不到CYC的统计周期,直接退出等待下个周期再做判断
if barpos = cyc+1 then
begin
af:=Step;
ep:=-1;
if (high[barpos]-high[barpos-1])+(low[barpos]-low[barpos-1]) > 0 then
begin
  //看跌
  Trend:= -1;
  sarx:=highprice;
end
else
begin
  //看涨
  Trend:= 1;
  sarx:=lowPrice;
end
GOTO ENDANDSHOW;//跳转到末尾直接显示
End
//判断出这些日子数据的上涨,或者下跌
if Trend > 0 then
begin
//是否为跳转标志
if ep > 0 then
begin
  sarx:=lowPrice;
  EP:=-1;
  GOTO ENDANDSHOW;//跳转到末尾直接显示
end

//如果今日最高价大于前N的最高价,加速因子需要增加
if high > highprice then
begin
  af := af+step;
  if af > fmax then
    af := fmax;
end

fsar := sarx + af * (highprice - sarx);
//是否跳转
if fsar > low then
begin
  trend:=-1;
  ep:=1;
  af:=step;
end
sarx:=fsar;
end
else
begin
if ep > 0 then
begin
  sarx:=highprice;
  ep:=-1;
  GOTO ENDANDSHOW; //跳转到末尾直接显示
end

//看跌
if low < lowPrice then
begin
  af := af + step;
  if af > fmax then
    af := fmax;
end

fsar := sarx + af * (lowprice-sarx);

//是否跳转
if fSar < High then
begin
  Trend := 1;
  EP := 1;
  AF := Step;
end
sarx := fSar;
end
//显示变量
ENDANDSHOW@; //此为语句标号,GOGO语句可以用这个标号直接跳转到这里
ShowSar:sarx;



您需要登录后才可以回帖 登录 | 注册入住  

本版积分规则

易家网  ©2015-2023  郑州期米信息技术有限公司版权所有  豫公网安备 41010502005136号 豫ICP备16010300号