wxxx 发表于 2012-10-23 16:50:55

//Table 28.4  年之月 月之日组合-日内系统
Input:n(10),p(4);
Variable: e(0),f(0),m(0);
m:=Month;
if m<>m and m=n then e:=1;
if m<>m and m=p then e:=-1;
if (Day>=21 or Day<6) then f:=1;
if (Day>=6 and Day<21) then f:=-1;
if  O[-1] <C and e+f=2 then Buy('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');
if  O[-1] >C and e+f=-2 then SellShort('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');
SetExitOnClose;
{
O[-1] <C 第二天低开
}//Table 28.5  Three Calendar Indicators Agree
Input:n(10),p(4);
Variable: e(0),f(0),x(0),u(0),g(0),m(0);
if C>O then e:=C-O;
if C<O then f:=O-C;
if (WeekDay=5 and C>C) or
(WeekDay=1 and C<C) or
(WeekDay=2 and HHV(e,2)<HHV(f,2)) or
(WeekDay=3 and HHV(e,3)<HHV(f,3)) or
(WeekDay=4 and HHV(e,4)<HHV(f,4)) then g:=1;
if (WeekDay=5 and C<C) or
(WeekDay=1 and C>C) or
(WeekDay=2 and HHV(e,2)>HHV(f,2)) or
(WeekDay=3 and HHV(e,3)>HHV(f,3)) or
(WeekDay=4 and HHV(e,4)>HHV(f,4)) then g:=-1;
m:=Month;
if m<>m and m=n then x:=1;
if m<>m and m=p then x:=-1;
if (Day>=21 or Day<6) then u:=1;
if (Day>=6 and Day<21) then u:=-1;
if x+u+g=3 then Buy('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');
if x+u+g<3 then Sell('', DEFAULT, 0, 0, OT_Market, OB_NextBar, '');
if x+u+g=-3 then SellShort('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');
if x+u+g>-3 then BuyToCover('', DEFAULT, 0, 0, OT_Market, OB_NextBar, '');

//Table 28.6  2 of 3 Calendar Signals—日内交易
Input:n(10),p(4);
Variable: e(0),f(0),x(0),u(0),g(0),m(0);
if C>O then e:=C-O;
if C<O then f:=O-C;
if (WeekDay=5 and C>C) or
(WeekDay=1 and C<C) or
(WeekDay=2 and HHV(e,2)<HHV(f,2)) or
(WeekDay=3 and HHV(e,3)<HHV(f,3)) or
(WeekDay=4 and HHV(e,4)<HHV(f,4)) then g:=1;
if (WeekDay=5 and C<C) or
(WeekDay=1 and C>C) or
(WeekDay=2 and HHV(e,2)>HHV(f,2)) or
(WeekDay=3 and HHV(e,3)>HHV(f,3)) or
(WeekDay=4 and HHV(e,4)>HHV(f,4)) then g:=-1;
m:=Month;
if m<>m and m=n then x:=1;
if m<>m and m=p then x:=-1;
if (Day>=21 or Day<6) then u:=1;
if (Day>=6 and Day<21) then u:=-1;
if  O[-1] <C and x+u+g>0 then Buy('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');
if  O[-1] >C and x+u+g<0 then SellShort('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');
SetExitOnClose;

wxxx 发表于 2012-10-23 17:03:31

//Table 29.1.  月之日,周之日和前面8个指标 组合.
Variable: aaa(0),bbb(0),ccc(0),e(0),f(0),g(0),xx(0),j(0),x(0),uuu(0);
if C>O then e=C-O; else e:=0;
if C<O then f=O-C; else f:=0;
if (WeekDay=5 and C>C ) or
(WeekDay=1 and C<C) or
(WeekDay=2 and HHV(e,2)<HHV(f,2)) or
(WeekDay=3 and HHV(e,3)<HHV(f,3)) or
(WeekDay=4 and HHV(e,4)<HHV(f,4)) then aaa:=1;
if (WeekDay=5 and C<C ) or
(WeekDay=1 and C>C) or
(WeekDay=2 and HHV(e,2)>HHV(f,2)) or
(WeekDay=3 and HHV(e,3)>HHV(f,3)) or
(WeekDay=4 and HHV(e,4)>HHV(f,4)) then aaa:=-1;
if (Day>=21 or Day<6) then bbb:=1;
if (Day>=6 and Day<21) then bbb:=-1;
IF MA(C,2)<MA(C,5)then g:=1;
if MA(C,2)>MA(C,5)then g:=-1;
if C>MA(C,40) then xx:=1;
if C<MA(C,40) then xx:=-1;
if HHVBars(C,50)>LLVBars(C,50) then j:=1;
if HHVBars(C,50)<LLVBars(C,50) then j:=-1;
if (KRange<MA(KRange,10)) and C>C or (KRange>MA(KRange,10)) and C<C then x:=1;
if (KRange<MA(KRange,10)) and C<C or (KRange>MA(KRange,10)) and C>C then x:=-1;
if C>(MA(H,15)+MA(L,15))/2 then uuu:=1;
if C<(MA(H,15)+MA(L,15))/2 then uuu:=-1;
if g+xx+j+x+uuu>0 then ccc:=1;
if g+xx+j+x+uuu<0 then ccc:=-1;
if aaa+bbb+ccc>0 then Buy('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');
if aaa+bbb+ccc<0 then SellShort('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');

仁心慧能 发表于 2012-10-23 19:41:34

谢谢 wxxx 朋友!很棒的分享!

ccirsi 发表于 2012-10-23 21:07:23

代码很多,慢慢学,谢谢!!!!!!!

wxxx 发表于 2012-10-24 08:25:22

//table 30.1.  Dow-Spoo Perpetual 道琼斯-标准普尔
Variable: g(0);
if  c/CloseD(1)>(data2.Close/(data2.CloseD(1))) then g=1;
if  c/CloseD(1)<(data2.Close/(data2.CloseD(1))) then g=-1;
if  g>0 then Buy('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');
if  g<0 then SellShort('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');
{
我们可以在主图上叠加hs300的数据,交易 期指,这样,代码中data2就是hs300的数据
}
目前发现金魔方data2函数还不支持 引用 CloseD,OpenD,HighD 等.

wxxx 发表于 2012-10-24 15:38:03

38楼的策略  Table 28.1  Index Month of the Year Indicator
我在后面提了点疑问,说分析下策略的成交时间。

看第一笔的成交时间  2010/07/02,与我们的策略逻辑不同(从5月2日开始做空)。
通过问金魔方开发人员,发现是这个设置的原因。




公式计算需引用之前最大周期数  50
我们发现7月2号是第52根K线(日线周期上)。

这下明白了。

wxxx 发表于 2012-10-25 20:53:03

接下来的几章,讲的都是日内交易。//Table 31.2  相对本周期的开盘价进场
{
应用周期:分钟周期
OpenD(0)就是 Open
}
Input:x(9.3),y(15.15);
if Time=(x*10000) and C>OpenD(0) then Buy('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');
if Time=(y*10000) then Sell('', DEFAULT, 0, 0, OT_Close, OB_ThisBar, '');
if Time=(x*10000) and C<OpenD(0) then SellShort('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');
if Time=(y*10000) then BuyToCover('', DEFAULT, 0, 0, OT_Close, OB_ThisBar, '');
看下图的成交明细,我们发现,都是在第二次反向开仓的同时平仓。
通过测试发现,金魔方有这个特性:某交易指令开仓时,如果已有反向持仓,先自动平掉该持仓再开新仓
其实,我们把这个策略用在国内的股指期货上反映不了该书要表达的意思,因为策略里是15:15平仓,而股指期货15:15正好收盘了,所以,我们把该策略的参数y改成 如15.10就可以实现该策略要表达的日内交易的意思了。

wxxx 发表于 2012-10-25 21:12:02

//Table 31.3  2条K线一致和开盘价—60分钟周期
Input:b(10.3),x(14.3);
if Time>=(b*10000) and Time<(x*10000) and C>OpenD(0) and C>OpenD(0) and C>C then Buy('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');
if Time=(x*10000) then Sell('', DEFAULT, 0, 0, OT_Market, OB_NextBar, '');
if Time>=(b*10000) and Time<(x*10000)and C<OpenD(0) and C<OpenD(0) and C<C then SellShort('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');
if Time=(x*10000) then BuyToCover('', DEFAULT, 0, 0, OT_Market, OB_NextBar, '');

wxxx 发表于 2012-10-26 16:31:07

//Table 31.4  上午休息,下午进场出场


Input:x(13.00),y(15.00);
if Time=(x*10000) and  C>OpenD(0) then Buy('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');
if Time<((y+0.01)*10000) and Time>=(y*10000) then Sell('', DEFAULT, 0, 0, OT_Close, OB_ThisBar, '');
if Time=(x*10000) and  C<OpenD(0) then SellShort('', DEFAULT, 0, 0, OT_Market, OB_NextBar,  '');
if Time<((y+0.01)*10000) and Time>=(y*10000) then BuyToCover('', DEFAULT, 0, 0, OT_Close, OB_ThisBar, '');
{
mc中time精确到分钟,而金魔方精确到秒
}

wxxx 发表于 2012-10-26 19:48:09

//Fig 32.2  用于美大豆的交易
Input:q(2),n(20),y(0.5),z(0.4),u(0.1);
Variable:x(0),mp(0),rr(0),xx(0);
if MA(KRange,5)>=q*MA(KRange,n) then x=1; else x:=0;
mp:=MarketPosition;
rr:=HHV(H,n)-LLV(L,n);
if HHV(H,n)-C<=u*rr then xx=1; else xx:=0;
if x+xx>=1 then Buy('', DEFAULT, O[-1] +KRange, -1, OT_Stop, OB_NextBar,  '');
if mp=1 then Sell('', DEFAULT, O[-1] +y*rr, 0, OT_Limit, OB_NextBar, '');
if mp=1 then Sell('', DEFAULT, O[-1] -z*rr, -1, OT_Stop, OB_NextBar, '');
//if mp=1 then Sell('', DEFAULT, L-KRange, -1, OT_Stop, OB_NextBar, '');
if x+xx<1 then SellShort('', DEFAULT, O[-1] -KRange, -1, OT_Stop, OB_NextBar,  '');
if mp=-1 then BuyToCover('', DEFAULT, O[-1] -y*rr, 0, OT_Limit, OB_NextBar, '');
if mp=-1 then BuyToCover('', DEFAULT, O[-1] +z*rr, -1, OT_Stop, OB_NextBar, '');
{
两种情况确定买入和卖出:
1,过去20天内的最高价减去收盘价等于或小于20天振幅的10%;
2, 5天的平均振幅至少是前面20天振幅均值的2倍(20天的均值从
   25天前开始到6天前---不包括最近5天的日期)。

如果满足了2者中的任意一条,用stop类型的订单买入,买入价设置
为开盘价加前一天的振幅,做空价则为开盘价减同样的振幅。
止盈目标为第二天的开盘价加上20天振幅的50%
止损点为开盘价减去振幅的40%(这里并不一定亏损出场)。

代码第11行,书中貌似没提到以 L-KRange 止损,所以我注释了。
}
页: 1 2 3 4 [5] 6 7 8 9 10 11 12 13
查看完整版本: 战胜金融期货市场(把小的市场优势整合成为强大的赚钱策略)