欢迎您光临博庭社区!

 找回密码
 立即注册
楼主: wxxx

战胜金融期货市场(把小的市场优势整合成为强大的赚钱策略)   [复制链接]

Rank: 3Rank: 3

奉献奖

发表于 2012-10-13 00:37:27 |显示全部楼层
stop单
//O[-1]表示次周期开盘价,因为交易指令是次周期停损单,那时开盘价已知,并非使用未来数据
  1. //Table 18.4  8指标组合策略—33% stop单进场
  2. Variable: aa(0),bb(0),cc(0),dd(0),ee(0),ff(0),gg(0),hh(0);
  3. IF MA(C,2)<MA(C,5)then aa:=1;
  4. if MA(C,2)>MA(C,5)then aa:=-1;
  5. if C>MA(C,40) then bb:=1;
  6. if C<MA(C,40) then bb:=-1;
  7. if HHVBars(C,50)>LLVBars(C,50) then cc:=1;
  8. if HHVBars(C,50)<LLVBars(C,50) then cc:=-1;
  9. if ((high-low)<MA((high-low),10)) and C>C[1] or ((high-low)>MA((high-low),10)) and C<C[1] then dd:=1;
  10. if ((high-low)<MA((high-low),10)) and C<C[1] or ((high-low)>MA((high-low),10)) and C>C[1] then dd:=-1;
  11. if C>(MA(H,15)+MA(L,15))/2 then ee:=1;
  12. if C<(MA(H,15)+MA(L,15))/2 then ee:=-1;
  13. if C<O and C[1]<O[1] then ff=1; else ff:=0;
  14. if C>O and C[1]>O[1] then ff:=-1;
  15. if L>L[1] and L[1]<LLV(L,3)[2] and C>C[1]  and C[1]<C[2]then gg=1; else gg:=0;
  16. if H<H[1] and H[1]>HHV(H,3)[2] and C<C[1] and C[1]>C[2]then gg:=-1;
  17. if HHV(L,3)-LLV(L,3)<=0.2*(HHV(H,3)-LLV(L,3)) then hh=1; else hh:=0;
  18. if HHV(H,3)-LLV(H,3)<=0.2* (HHV(H,3)-LLV(L,3))then hh:=-1;
  19. if aa+bb+cc+dd+ee+ff+gg+hh>0 then Buy('', DEFAULT, O[-1] +0.33*MA((high-low),3), -1, OT_Stop, OB_NextBar,  '');
  20. if aa+bb+cc+dd+ee+ff+gg+hh<0 then SellShort('', DEFAULT, O[-1] -0.33*MA((high-low),3), -1, OT_Stop, OB_NextBar,  '');
  21. SetExitOnClose;
复制代码
  1. //Table 18.5  8指标组合策略—33% stop单进场--+3-3
  2. Variable: aa(0),bb(0),cc(0),dd(0),ee(0),ff(0),gg(0),hh(0);
  3. IF MA(C,2)<MA(C,5)then aa:=1;
  4. if MA(C,2)>MA(C,5)then aa:=-1;
  5. if C>MA(C,40) then bb:=1;
  6. if C<MA(C,40) then bb:=-1;
  7. if HHVBars(C,50)>LLVBars(C,50) then cc:=1;
  8. if HHVBars(C,50)<LLVBars(C,50) then cc:=-1;
  9. if ((high-low)<MA((high-low),10)) and C>C[1] or ((high-low)>MA((high-low),10)) and C<C[1] then dd:=1;
  10. if ((high-low)<MA((high-low),10)) and C<C[1] or ((high-low)>MA((high-low),10)) and C>C[1] then dd:=-1;
  11. if C>(MA(H,15)+MA(L,15))/2 then ee:=1;
  12. if C<(MA(H,15)+MA(L,15))/2 then ee:=-1;
  13. if C<O and C[1]<O[1] then ff=1; else ff:=0;
  14. if C>O and C[1]>O[1] then ff:=-1;
  15. if L>L[1] and L[1]<LLV(L,3)[2] and C>C[1]  and C[1]<C[2]then gg=1; else gg:=0;
  16. if H<H[1] and H[1]>HHV(H,3)[2] and C<C[1] and C[1]>C[2]then gg:=-1;
  17. if HHV(L,3)-LLV(L,3)<=0.2*(HHV(H,3)-LLV(L,3)) then hh=1; else hh:=0;
  18. if HHV(H,3)-LLV(H,3)<=0.2* (HHV(H,3)-LLV(L,3))then hh:=-1;
  19. if aa+bb+cc+dd+ee+ff+gg+hh>=3 then Buy('', DEFAULT, O[-1] +0.33*MA((high-low),3), -1, OT_Stop, OB_NextBar,  '');
  20. if aa+bb+cc+dd+ee+ff+gg+hh<=-3 then SellShort('', DEFAULT, O[-1] -0.33*MA((high-low),3), -1, OT_Stop, OB_NextBar,  '');
  21. SetExitOnClose;
复制代码
金魔方暂不支持o[-1] 形势,先不贴图了,后面会支持吧。

使用道具 举报

Rank: 3Rank: 3

奉献奖

发表于 2012-10-13 00:41:59 |显示全部楼层
limit单
  1. //Table 19.2  8指标组合策略—25% limit单进场
  2. Variable: aa(0),bb(0),cc(0),dd(0),ee(0),ff(0),gg(0),hh(0);
  3. IF MA(C,2)<MA(C,5)then aa:=1;
  4. if MA(C,2)>MA(C,5)then aa:=-1;
  5. if C>MA(C,40) then bb:=1;
  6. if C<MA(C,40) then bb:=-1;
  7. if HHVBars(C,50)>LLVBars(C,50) then cc:=1;
  8. if HHVBars(C,50)<LLVBars(C,50) then cc:=-1;
  9. if ((high-low)<MA((high-low),10)) and C>C[1] or ((high-low)>MA((high-low),10)) and C<C[1] then dd:=1;
  10. if ((high-low)<MA((high-low),10)) and C<C[1] or ((high-low)>MA((high-low),10)) and C>C[1] then dd:=-1;
  11. if C>(MA(H,15)+MA(L,15))/2 then ee:=1;
  12. if C<(MA(H,15)+MA(L,15))/2 then ee:=-1;
  13. if C<O and C[1]<O[1] then ff=1; else ff:=0;
  14. if C>O and C[1]>O[1] then ff:=-1;
  15. if L>L[1] and L[1]<LLV(L,3)[2] and C>C[1]  and C[1]<C[2]then gg=1; else gg:=0;
  16. if H<H[1] and H[1]>HHV(H,3)[2] and C<C[1] and C[1]>C[2]then gg:=-1;
  17. if HHV(L,3)-LLV(L,3)<=0.2*(HHV(H,3)-LLV(L,3)) then hh=1; else hh:=0;
  18. if HHV(H,3)-LLV(H,3)<=0.2* (HHV(H,3)-LLV(L,3))then hh:=-1;
  19. if aa+bb+cc+dd+ee+ff+gg+hh>0 then Buy('', DEFAULT, O[-1] -0.25*MA((high-low),3), 0, OT_Limit, OB_NextBar,  '');
  20. if aa+bb+cc+dd+ee+ff+gg+hh<0 then SellShort('', DEFAULT, O[-1] +0.25*MA((high-low),3), 0, OT_Limit, OB_NextBar,  '');
  21. SetExitOnClose;
复制代码
  1. //Table 19.3  8指标组合策略—25% Limit单进场--+3-3
  2. Variable: aa(0),bb(0),cc(0),dd(0),ee(0),ff(0),gg(0),hh(0);
  3. IF MA(C,2)<MA(C,5)then aa:=1;
  4. if MA(C,2)>MA(C,5)then aa:=-1;
  5. if C>MA(C,40) then bb:=1;
  6. if C<MA(C,40) then bb:=-1;
  7. if HHVBars(C,50)>LLVBars(C,50) then cc:=1;
  8. if HHVBars(C,50)<LLVBars(C,50) then cc:=-1;
  9. if ((high-low)<MA((high-low),10)) and C>C[1] or ((high-low)>MA((high-low),10)) and C<C[1] then dd:=1;
  10. if ((high-low)<MA((high-low),10)) and C<C[1] or ((high-low)>MA((high-low),10)) and C>C[1] then dd:=-1;
  11. if C>(MA(H,15)+MA(L,15))/2 then ee:=1;
  12. if C<(MA(H,15)+MA(L,15))/2 then ee:=-1;
  13. if C<O and C[1]<O[1] then ff=1; else ff=0;
  14. if C>O and C[1]>O[1] then ff=-1;
  15. if L>L[1] and L[1]<LLV(L,3)[2] and C>C[1]  and C[1]<C[2]then gg=1; else gg:=0;
  16. if H<H[1] and H[1]>HHV(H,3)[2] and C<C[1] and C[1]>C[2]then gg:=-1;
  17. if HHV(L,3)-LLV(L,3)<=0.2*(HHV(H,3)-LLV(L,3)) then hh=1; else hh:=0;
  18. if HHV(H,3)-LLV(H,3)<=0.2* (HHV(H,3)-LLV(L,3))then hh:=-1;
  19. if aa+bb+cc+dd+ee+ff+gg+hh>=3 then Buy('', DEFAULT, O[-1] -0.25*MA((high-low),3), 0, OT_Limit, OB_NextBar,  '');
  20. if aa+bb+cc+dd+ee+ff+gg+hh<=-3 then SellShort('', DEFAULT, O[-1] +0.25*MA((high-low),3), 0, OT_Limit, OB_NextBar,  '');
  21. SetExitOnClose;
复制代码

使用道具 举报

Rank: 3Rank: 3

奉献奖

发表于 2012-10-14 22:26:30 |显示全部楼层
  1. //Table 20.3  8指标组合策略 66%止盈止损
  2. Variable: aa(0),bb(0),cc(0),dd(0),ee(0),ff(0),gg(0),hh(0);
  3. IF MA(C,2)<MA(C,5)then aa:=1;
  4. if MA(C,2)>MA(C,5)then aa:=-1;
  5. if C>MA(C,40) then bb:=1;
  6. if C<MA(C,40) then bb:=-1;
  7. if HHVBars(C,50)>LLVBars(C,50) then cc:=1;
  8. if HHVBars(C,50)<LLVBars(C,50) then cc:=-1;
  9. if ((high-low)<MA((high-low),10)) and C>C[1] or ((high-low)>MA((high-low),10)) and C<C[1] then dd:=1;
  10. if ((high-low)<MA((high-low),10)) and C<C[1] or ((high-low)>MA((high-low),10)) and C>C[1] then dd:=-1;
  11. if C>(MA(H,15)+MA(L,15))/2 then ee:=1;
  12. if C<(MA(H,15)+MA(L,15))/2 then ee:=-1;
  13. if C<O and C[1]<O[1] then ff=1; else ff:=0;
  14. if C>O and C[1]>O[1] then ff:=-1;
  15. if L>L[1] and L[1]<LLV(L,3)[2] and C>C[1]  and C[1]<C[2]then gg=1; else gg:=0;
  16. if H<H[1] and H[1]>HHV(H,3)[2] and C<C[1] and C[1]>C[2]then gg:=-1;
  17. if HHV(L,3)-LLV(L,3)<=0.2*(HHV(H,3)-LLV(L,3)) then hh=1; else hh:=0;
  18. if HHV(H,3)-LLV(H,3)<=0.2* (HHV(H,3)-LLV(L,3))then hh:=-1;
  19. if aa+bb+cc+dd+ee+ff+gg+hh>0 then Buy('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');
  20. Sell('', DEFAULT, O[-1] -0.66*MA((high-low),3), -1, OT_Stop, OB_NextBar, '');
  21. if aa+bb+cc+dd+ee+ff+gg+hh<0 then SellShort('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');
  22. BuyToCover('', DEFAULT, O[-1] +0.66*MA((high-low),3), -1, OT_Stop, OB_NextBar, '');
  23. SetExitOnClose;
复制代码
大家可以思考下下面2句的 O[-1] -0.66*MA((high-low),3)    O[-1] +0.66*MA((high-low),3)
Sell('', DEFAULT, O[-1] -0.66*MA((high-low),3), -1, OT_Stop, OB_NextBar, '');
BuyToCover('', DEFAULT, O[-1] +0.66*MA((high-low),3), -1, OT_Stop, OB_NextBar, '');
由于金魔方nthhighest类似的函数暂时没有实现,我们后面直接跳到24章。

使用道具 举报

Rank: 3Rank: 3

奉献奖

发表于 2012-10-16 10:46:13 |显示全部楼层
24章的代码又用到了 o[-1]的写法,本想跳过这章,直到今天问了金魔方的开发人员,确认以后会支持这种写法。
  1. {周期:1分钟}
  2. Variable:e(0),f(0),g(0),j(0);
  3. e:=(H-O);
  4. f:=(O-L);
  5. g:=MA(e,5);
  6. j:=MA(f,5);
  7. if Time>=84500 and Time<145500 then Buy('', DEFAULT, O[-1] -j, 0, OT_Limit, OB_NextBar,  '');
  8. if Time=150000 then Sell('', DEFAULT, 0, 0, OT_Market, OB_NextBar, '');
  9. if Time>=84500 and Time<145500 then SellShort('', DEFAULT, O[-1] +g, 0, OT_Limit, OB_NextBar,  '');
  10. if Time=150000 then BuyToCover('', DEFAULT, 0, 0, OT_Market, OB_NextBar, '');
复制代码
{注意,mc的time与金魔方的time有点区别
}

使用道具 举报

Rank: 3Rank: 3

奉献奖

发表于 2012-10-16 16:33:37 |显示全部楼层
  1. //table 25.1 周线区间突破
  2. Buy('', DEFAULT, O[-1] +KRange, -1, OT_Stop, OB_NextBar,  '');
  3. SellShort('', DEFAULT, O[-1] -KRange, -1, OT_Stop, OB_NextBar,  '');
复制代码
  1. //Table 25.4  1.5倍日线区间突破
  2. Input: q(1.5),n(25);
  3. if C>MA(C,n) then Buy('', DEFAULT, O[-1] +(q*(high-low)), -1, OT_Stop, OB_NextBar,  '');
  4. Sell('', DEFAULT, O[-1] -(q*(high-low)), -1, OT_Stop, OB_NextBar, '');
  5. if C<MA(C,n) then SellShort('', DEFAULT, O[-1] -(q*(high-low)), -1, OT_Stop, OB_NextBar,  '');
  6. BuyToCover('', DEFAULT, O[-1] +(q*(high-low)), -1, OT_Stop, OB_NextBar, '');
复制代码


可以看到table 25.1策略用到了公共函数KRange, 我们看到其源码就是high-low,我们可以替换table 25.4里的high-low成KRange.
附件: 你需要登录才可以下载或查看附件。没有帐号?立即注册

使用道具 举报

Rank: 6Rank: 6

激情奖

发表于 2012-10-18 12:59:40 |显示全部楼层
05.if C>MA(C,40) then bb:=1;
06.if C<MA(C,40) then bb:=-1;
原文是:如果收盘价大于40天均值的收盘价,那么我们就在第二天开盘价买入,在收盘价出场。
这样表达是错误的。
还有是指40天均值收盘价,不是你所谓的40日均线。
追求的基调是快乐投资

使用道具 举报

Rank: 6Rank: 6

激情奖

发表于 2012-10-18 13:01:17 |显示全部楼层
40天均值收盘价,应该使用递减循环语句求得40天均值收盘价。
追求的基调是快乐投资

使用道具 举报

Rank: 6Rank: 6

激情奖

发表于 2012-10-18 13:02:05 |显示全部楼层
量化需要精确,不是大慨。
追求的基调是快乐投资

使用道具 举报

Rank: 6Rank: 6

激情奖

发表于 2012-10-18 13:03:55 |显示全部楼层
03.IF MA(C,2)<MA(C,5)then aa:=1;

04.if MA(C,2)>MA(C,5)then aa:=-1;

也是错误的
追求的基调是快乐投资

使用道具 举报

Rank: 6Rank: 6

激情奖

发表于 2012-10-18 13:04:30 |显示全部楼层
是2天均值,不是2日均线
追求的基调是快乐投资

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

bottom

Archiver|http://www.patiosoft.com

GMT+8, 2017-12-11 08:25 , Processed in 0.049402 second(s), 9 queries .

花生网 Copyrigh©2012

和讯信息科技有限公司 ALL Rights Reserved 版权所有 复制必究

回顶部