楼主: 金字塔客服
打印 上一主题 下一主题

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

  [复制链接]
41
发表于 2012-1-14 12:04:48 | 只看该作者
{:05:}{:05:}{:05:}{:05:}
42
发表于 2012-1-14 19:17:47 | 只看该作者
{:05:}{:05:}
43
发表于 2012-1-18 16:59:04 | 只看该作者
{:05:}{:05:}
44
 楼主| 发表于 2012-1-24 22:08:38 | 只看该作者
祝所有金字塔用户 爱好者 新春大吉 龙年大发!
45
 楼主| 发表于 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;



46
 楼主| 发表于 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;
47
发表于 2012-2-11 22:09:29 | 只看该作者
看到这些指标代码,就感觉头大啊,
48
 楼主| 发表于 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;



49
发表于 2012-2-17 15:03:39 | 只看该作者
请问大家有什么看法?我绝对喜欢这个帖子
50
发表于 2012-2-25 16:57:47 | 只看该作者
看来要好好补补编程 看不懂
51
发表于 2012-2-28 16:04:19 | 只看该作者
虚心学习,细心感悟,期路漫漫,执行当先。
52
发表于 2012-4-21 16:06:04 | 只看该作者
学习。{:soso_e100:}
53
发表于 2012-4-22 14:47:14 | 只看该作者
汗,都看花眼了
54
发表于 2012-4-23 21:24:10 | 只看该作者
顶!一定要顶!

55
发表于 2012-5-10 22:40:55 | 只看该作者
内包日外包日
56
发表于 2012-5-17 10:50:13 | 只看该作者
我在努力中
57
发表于 2012-5-17 23:19:48 | 只看该作者
晕死,在金字塔官方论坛都没看到有这么齐全的模版。。。。。。。。。。
58
发表于 2012-9-26 15:35:41 | 只看该作者
是不是自动化交易的啊。看不懂 还不太会用这个呢
59
发表于 2012-11-12 15:09:18 | 只看该作者
学习了!!!!!!!!!!!!!!!
60
发表于 2012-11-22 15:03:15 | 只看该作者
我绝对喜欢这个帖子
您需要登录后才可以回帖 登录 | 注册入住  

本版积分规则

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