wxxx 发表于 2012-10-13 00:37:27

stop单
//O[-1]表示次周期开盘价,因为交易指令是次周期停损单,那时开盘价已知,并非使用未来数据//Table 18.4  8指标组合策略—33% stop单进场
Variable: aa(0),bb(0),cc(0),dd(0),ee(0),ff(0),gg(0),hh(0);
IF MA(C,2)<MA(C,5)then aa:=1;
if MA(C,2)>MA(C,5)then aa:=-1;
if C>MA(C,40) then bb:=1;
if C<MA(C,40) then bb:=-1;
if HHVBars(C,50)>LLVBars(C,50) then cc:=1;
if HHVBars(C,50)<LLVBars(C,50) then cc:=-1;
if ((high-low)<MA((high-low),10)) and C>C or ((high-low)>MA((high-low),10)) and C<C then dd:=1;
if ((high-low)<MA((high-low),10)) and C<C or ((high-low)>MA((high-low),10)) and C>C then dd:=-1;
if C>(MA(H,15)+MA(L,15))/2 then ee:=1;
if C<(MA(H,15)+MA(L,15))/2 then ee:=-1;
if C<O and C<O then ff=1; else ff:=0;
if C>O and C>O then ff:=-1;
if L>L and L<LLV(L,3) and C>C  and C<Cthen gg=1; else gg:=0;
if H<H and H>HHV(H,3) and C<C and C>Cthen gg:=-1;
if HHV(L,3)-LLV(L,3)<=0.2*(HHV(H,3)-LLV(L,3)) then hh=1; else hh:=0;
if HHV(H,3)-LLV(H,3)<=0.2* (HHV(H,3)-LLV(L,3))then hh:=-1;
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,  '');
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,  '');
SetExitOnClose;//Table 18.5  8指标组合策略—33% stop单进场--+3-3
Variable: aa(0),bb(0),cc(0),dd(0),ee(0),ff(0),gg(0),hh(0);
IF MA(C,2)<MA(C,5)then aa:=1;
if MA(C,2)>MA(C,5)then aa:=-1;
if C>MA(C,40) then bb:=1;
if C<MA(C,40) then bb:=-1;
if HHVBars(C,50)>LLVBars(C,50) then cc:=1;
if HHVBars(C,50)<LLVBars(C,50) then cc:=-1;
if ((high-low)<MA((high-low),10)) and C>C or ((high-low)>MA((high-low),10)) and C<C then dd:=1;
if ((high-low)<MA((high-low),10)) and C<C or ((high-low)>MA((high-low),10)) and C>C then dd:=-1;
if C>(MA(H,15)+MA(L,15))/2 then ee:=1;
if C<(MA(H,15)+MA(L,15))/2 then ee:=-1;
if C<O and C<O then ff=1; else ff:=0;
if C>O and C>O then ff:=-1;
if L>L and L<LLV(L,3) and C>C  and C<Cthen gg=1; else gg:=0;
if H<H and H>HHV(H,3) and C<C and C>Cthen gg:=-1;
if HHV(L,3)-LLV(L,3)<=0.2*(HHV(H,3)-LLV(L,3)) then hh=1; else hh:=0;
if HHV(H,3)-LLV(H,3)<=0.2* (HHV(H,3)-LLV(L,3))then hh:=-1;
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,  '');
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,  '');
SetExitOnClose;金魔方暂不支持o[-1] 形势,先不贴图了,后面会支持吧。

wxxx 发表于 2012-10-13 00:41:59

limit单//Table 19.2  8指标组合策略—25% limit单进场
Variable: aa(0),bb(0),cc(0),dd(0),ee(0),ff(0),gg(0),hh(0);
IF MA(C,2)<MA(C,5)then aa:=1;
if MA(C,2)>MA(C,5)then aa:=-1;
if C>MA(C,40) then bb:=1;
if C<MA(C,40) then bb:=-1;
if HHVBars(C,50)>LLVBars(C,50) then cc:=1;
if HHVBars(C,50)<LLVBars(C,50) then cc:=-1;
if ((high-low)<MA((high-low),10)) and C>C or ((high-low)>MA((high-low),10)) and C<C then dd:=1;
if ((high-low)<MA((high-low),10)) and C<C or ((high-low)>MA((high-low),10)) and C>C then dd:=-1;
if C>(MA(H,15)+MA(L,15))/2 then ee:=1;
if C<(MA(H,15)+MA(L,15))/2 then ee:=-1;
if C<O and C<O then ff=1; else ff:=0;
if C>O and C>O then ff:=-1;
if L>L and L<LLV(L,3) and C>C  and C<Cthen gg=1; else gg:=0;
if H<H and H>HHV(H,3) and C<C and C>Cthen gg:=-1;
if HHV(L,3)-LLV(L,3)<=0.2*(HHV(H,3)-LLV(L,3)) then hh=1; else hh:=0;
if HHV(H,3)-LLV(H,3)<=0.2* (HHV(H,3)-LLV(L,3))then hh:=-1;
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,  '');
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,  '');
SetExitOnClose;//Table 19.3  8指标组合策略—25% Limit单进场--+3-3
Variable: aa(0),bb(0),cc(0),dd(0),ee(0),ff(0),gg(0),hh(0);
IF MA(C,2)<MA(C,5)then aa:=1;
if MA(C,2)>MA(C,5)then aa:=-1;
if C>MA(C,40) then bb:=1;
if C<MA(C,40) then bb:=-1;
if HHVBars(C,50)>LLVBars(C,50) then cc:=1;
if HHVBars(C,50)<LLVBars(C,50) then cc:=-1;
if ((high-low)<MA((high-low),10)) and C>C or ((high-low)>MA((high-low),10)) and C<C then dd:=1;
if ((high-low)<MA((high-low),10)) and C<C or ((high-low)>MA((high-low),10)) and C>C then dd:=-1;
if C>(MA(H,15)+MA(L,15))/2 then ee:=1;
if C<(MA(H,15)+MA(L,15))/2 then ee:=-1;
if C<O and C<O then ff=1; else ff=0;
if C>O and C>O then ff=-1;
if L>L and L<LLV(L,3) and C>C  and C<Cthen gg=1; else gg:=0;
if H<H and H>HHV(H,3) and C<C and C>Cthen gg:=-1;
if HHV(L,3)-LLV(L,3)<=0.2*(HHV(H,3)-LLV(L,3)) then hh=1; else hh:=0;
if HHV(H,3)-LLV(H,3)<=0.2* (HHV(H,3)-LLV(L,3))then hh:=-1;
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,  '');
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,  '');
SetExitOnClose;

wxxx 发表于 2012-10-14 22:26:30

//Table 20.3  8指标组合策略 66%止盈止损
Variable: aa(0),bb(0),cc(0),dd(0),ee(0),ff(0),gg(0),hh(0);
IF MA(C,2)<MA(C,5)then aa:=1;
if MA(C,2)>MA(C,5)then aa:=-1;
if C>MA(C,40) then bb:=1;
if C<MA(C,40) then bb:=-1;
if HHVBars(C,50)>LLVBars(C,50) then cc:=1;
if HHVBars(C,50)<LLVBars(C,50) then cc:=-1;
if ((high-low)<MA((high-low),10)) and C>C or ((high-low)>MA((high-low),10)) and C<C then dd:=1;
if ((high-low)<MA((high-low),10)) and C<C or ((high-low)>MA((high-low),10)) and C>C then dd:=-1;
if C>(MA(H,15)+MA(L,15))/2 then ee:=1;
if C<(MA(H,15)+MA(L,15))/2 then ee:=-1;
if C<O and C<O then ff=1; else ff:=0;
if C>O and C>O then ff:=-1;
if L>L and L<LLV(L,3) and C>C  and C<Cthen gg=1; else gg:=0;
if H<H and H>HHV(H,3) and C<C and C>Cthen gg:=-1;
if HHV(L,3)-LLV(L,3)<=0.2*(HHV(H,3)-LLV(L,3)) then hh=1; else hh:=0;
if HHV(H,3)-LLV(H,3)<=0.2* (HHV(H,3)-LLV(L,3))then hh:=-1;
if aa+bb+cc+dd+ee+ff+gg+hh>0 then Buy('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');
Sell('', DEFAULT, O[-1] -0.66*MA((high-low),3), -1, OT_Stop, OB_NextBar, '');
if aa+bb+cc+dd+ee+ff+gg+hh<0 then SellShort('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');
BuyToCover('', DEFAULT, O[-1] +0.66*MA((high-low),3), -1, OT_Stop, OB_NextBar, '');
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章。

wxxx 发表于 2012-10-16 10:46:13

24章的代码又用到了 o[-1]的写法,本想跳过这章,直到今天问了金魔方的开发人员,确认以后会支持这种写法。{周期:1分钟}
Variable:e(0),f(0),g(0),j(0);
e:=(H-O);
f:=(O-L);
g:=MA(e,5);
j:=MA(f,5);
if Time>=84500 and Time<145500 then Buy('', DEFAULT, O[-1] -j, 0, OT_Limit, OB_NextBar,  '');
if Time=150000 then Sell('', DEFAULT, 0, 0, OT_Market, OB_NextBar, '');
if Time>=84500 and Time<145500 then SellShort('', DEFAULT, O[-1] +g, 0, OT_Limit, OB_NextBar,  '');
if Time=150000 then BuyToCover('', DEFAULT, 0, 0, OT_Market, OB_NextBar, '');
{注意,mc的time与金魔方的time有点区别
}

wxxx 发表于 2012-10-16 16:33:37

//table 25.1 周线区间突破
Buy('', DEFAULT, O[-1] +KRange, -1, OT_Stop, OB_NextBar,  '');
SellShort('', DEFAULT, O[-1] -KRange, -1, OT_Stop, OB_NextBar,  '');//Table 25.4  1.5倍日线区间突破
Input: q(1.5),n(25);
if C>MA(C,n) then Buy('', DEFAULT, O[-1] +(q*(high-low)), -1, OT_Stop, OB_NextBar,  '');
Sell('', DEFAULT, O[-1] -(q*(high-low)), -1, OT_Stop, OB_NextBar, '');
if C<MA(C,n) then SellShort('', DEFAULT, O[-1] -(q*(high-low)), -1, OT_Stop, OB_NextBar,  '');
BuyToCover('', DEFAULT, O[-1] +(q*(high-low)), -1, OT_Stop, OB_NextBar, '');

可以看到table 25.1策略用到了公共函数KRange, 我们看到其源码就是high-low,我们可以替换table 25.4里的high-low成KRange.

jrtj 发表于 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日均线。

jrtj 发表于 2012-10-18 13:01:17

40天均值收盘价,应该使用递减循环语句求得40天均值收盘价。

jrtj 发表于 2012-10-18 13:02:05

量化需要精确,不是大慨。

jrtj 发表于 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;

也是错误的

jrtj 发表于 2012-10-18 13:04:30

是2天均值,不是2日均线
页: 1 2 [3] 4 5 6 7 8 9 10 11 12
查看完整版本: 战胜金融期货市场(把小的市场优势整合成为强大的赚钱策略)