设为首页收藏本站

 找回密码
 注册
查看: 3431|回复: 4
打印 上一主题 下一主题

源码 KD2号模型,转载别人的 [复制链接]

Rank: 2

精华
0
UID
114140
积分
94
帖子
53
主题
24
阅读权限
30
注册时间
2012-12-16
最后登录
2015-4-9
跳转到指定楼层
1#
发表于 2013-2-15 23:04:49 |只看该作者 |倒序浏览
本帖最后由 woomin1985 于 2013-2-19 23:52 编辑

//------------------------------------------------------------------------
// 简称: kd2
// 名称:
// 类别: 公式应用
// 类型: 用户应用
// 输出:
//------------------------------------------------------------------------
Params
        Numeric Length1(3);
        Numeric Length2(5);
        Numeric Length3(5);
        Numeric Lots(1);
Vars
        NumericSeries Value1;
        NumericSeries Value2;
        Numeric LowestValue;
        NumericSeries Value5;
        NumericSeries RSV;
        NumericSeries KValue;
        NumericSeries DValue;
        Numeric AvgVol5;
        NumericSeries CloseTmp1;
        NumericSeries CloseTmp2;
        NumericSeries RSIValue;
        NumericSeries PreLow;
        NumericSeries PreKValue;
        Numeric Lowest33Value;
        NumericSeries VarTmp1;
        NumericSeries VarTmp2;
        NumericSeries ZL;
        Numeric SH;

Begin
{   
        Value1 =XAverage(Close,Length1);
        Value2 =XAverage(Close,Length2);
        //取两条均线的值
        LowestValue = Lowest(Low,Length3);
        //取最低值
        Value5= (CLOSE-LowestValue)/(Highest(High,Length3)-LowestValue)*100;
        RSV =XAverage(Value5,3);
        KValue = XAverage(RSV,3);
        DValue =Average(KValue,3);
        PreKValue =KValue[1];
        PreLow =Low[1];
        AvgVol5 =Average(Vol,5);
        Lowest33Value= Lowest(Low,33);
        VarTmp1=((2*CLOSE+HIGH+LOW)/4 - Lowest33Value )/(Highest(High,33) - Lowest33Value) *100;
        ZL =XAverage(VarTmp1,17);
        VarTmp2 =0.667*ZL[1] + 0.333*ZL;
        SH =XAverage(VarTmp2,2);
        CloseTmp1 =Max(Close - Close[1], 0);
        CloseTmp2 =Abs(Close - Close[1]);
        RSIValue =WAverage(CloseTmp1,6)/WAverage(CloseTmp2,6) *100;
        //以上为KD部分只要如何换书写方式就可了,higest==hhv  lowest==llv   xAverager=ma      
        // Buy什么时做买入动作,条件

If((CrossOver(Close,Value1 ) && (KValue > DValue) &&(ZL>SH)) Or
   (CrossOver(Value1,Value2) && (ZL>SH) && (Vol> 1.25 * AvgVol5) && (KValue > DValue)) Or
   (CrossOver(KValue,DValue) && (Close > Value1) &&(ZL>SH)) Or        
   (CrossOver(RSIValue,70)))//条件
        {
               Buy(Lots,Close[1]);
        }
   //SellShort 什么作卖出动作
If((CrossOver(PreLow,Close) && (KValue > DValue ) && (SH>ZL)) Or
   (CrossOver(DValue,KValue) && (Close < Value1) &&(Value1 < Value2)) Or
   (CrossOver(PreKValue,KValue)&& (SH>ZL)))//条件
        {
               SellShort(Lots,Close[1]);
        }
  // Sell 什么做多平动作
        If(CrossOver(DValue,KValue)|| Close[1] < Value1 * 1.001)//条件
        {
                        Sell(Lots,Close[1]);
        }
        //BuyToCover什么进个做空平动作
        If(CrossOver(KValue,DValue)|| Close[1] > Value1 * 1.001)//条件
        {
               BuyToCover(Lots,Close[1]);
        }
}
End

评测:回测就大把问题,感觉没啥存在的必要.

Rank: 4

精华
0
UID
114056
积分
394
帖子
174
主题
10
阅读权限
50
注册时间
2012-12-13
最后登录
2013-10-31
2#
发表于 2013-2-16 08:57:23 |只看该作者
本帖最后由 无心 于 2013-2-16 09:03 编辑

随便改了改,策略没有什么价值
Params
         Numeric Length1(16);
         Numeric Length2(35);
         Numeric Length3(9);
         Numeric Lots(1);
Vars
         NumericSeries Value1;
         NumericSeries Value2;
         NumericSeries LowestValue;
         NumericSeries Value5;
         NumericSeries RSV;
         NumericSeries KValue;
         NumericSeries DValue;
         NumericSeries AvgVol5;
         NumericSeries CloseTmp1;
         NumericSeries CloseTmp2;
         NumericSeries RSIValue;
         NumericSeries PreLow;
         NumericSeries PreKValue;
         NumericSeries Lowest33Value;
         NumericSeries VarTmp1;
         NumericSeries VarTmp2;
         NumericSeries ZL;
         NumericSeries SH;
Begin
         Value1 =XAverage(Close,Length1);
         Value2 =XAverage(Close,Length2);
         //取两条均线的值
         LowestValue = Lowest(Low,Length3);
         //取最低值
         Value5= (CLOSE-LowestValue)/(Highest(High,Length3)-LowestValue)*100;
         RSV =XAverage(Value5,3);
         KValue = XAverage(RSV,3);
         DValue =Average(KValue,3);
         PreKValue =KValue[1];
         PreLow =Low[1];
         AvgVol5 =Average(Vol,5);
         Lowest33Value= Lowest(Low,33);
         VarTmp1=((2*CLOSE+HIGH+LOW)/4 - Lowest33Value )/(Highest(High,33) - Lowest33Value) *100;
         ZL =XAverage(VarTmp1,17);
         VarTmp2 =0.667*ZL[1] + 0.333*ZL;
         SH =XAverage(VarTmp2,2);
         CloseTmp1 =Max(Close - Close[1], 0);
         CloseTmp2 =Abs(Close - Close[1]);
         RSIValue =WAverage(CloseTmp1,6)/WAverage(CloseTmp2,6) *100;
         //以上为KD部分只要如何换书写方式就可了,,higest ==hhv lowest==llv   xAverager=ma      
         // Buy什么时做买入动作,条件
                 
                 
         If((Close[1]>Value1[1] and Close[2]<Value1[2]  && KValue[1] > DValue[1] && ZL[1]>SH[1]) or
             (Value1[1]>Value2[1] and Value1[2]<Value2[2]  && ZL[1]>SH[1] && Vol[1]> 1.25 * AvgVol5[1] && KValue[1] > DValue[1]) Or
             (KValue[1]>DValue[1] and KValue[2]<DValue[2] && Close[1] > Value1[1] && ZL[1]>SH[1]) Or
             (RSIValue[1]>70 and RSIValue[2]<70))//条件
         {
                Buy(Lots,open+MinMove*PriceScale);
         }
         
         //SellShort 什么作卖出动作
         If((PreLow[1]>Close[1] and PreLow[2]<Close[2] && KValue[1] > DValue[1]  && SH>ZL) Or
             (DValue[1]>KValue[1] and DValue[2]<KValue[2] && Close[1] < Value1[1] && Value1[1] < Value2[1]) Or
             (PreKValue[1]>KValue[1] and PreKValue[2]<KValue[2] && SH[1]>ZL[1]))//条件
         {
                SellShort(Lots,open-MinMove*PriceScale);
         }
         
         // Sell 什么做多平仓动作
         If((DValue[1]>KValue[1] and DValue[2]<KValue[2]) or Close[1] < Value1 [1]* 1.001)//条件
         {
                Sell(Lots,open-MinMove*PriceScale);;
         }
         
         //BuyToCover什么做空平仓动作
         If((KValue[1]>DValue[1] and KValue[2]<DValue[2]) or Close[1] > Value1[1] * 1.001)//条件
         {
                BuyToCover(Lots,open+MinMove*PriceScale);
         }
End



使用道具 举报

Rank: 5Rank: 5

精华
0
UID
73474
积分
1249
帖子
695
主题
30
阅读权限
60
注册时间
2011-10-22
最后登录
2015-11-6
3#
发表于 2013-2-16 09:09:55 |只看该作者
这个策略,用在哪个周期、哪个品种,收益比较好啊???

使用道具 举报

Rank: 3Rank: 3

精华
0
UID
112423
积分
147
帖子
105
主题
3
阅读权限
40
注册时间
2012-9-10
最后登录
2018-2-26
4#
发表于 2013-2-16 10:41:26 |只看该作者
编一个好模型是个漫长的过程

使用道具 举报

Rank: 3Rank: 3

精华
0
UID
104190
积分
162
帖子
65
主题
2
阅读权限
40
注册时间
2012-3-12
最后登录
2013-7-17
5#
发表于 2013-2-24 15:01:23 |只看该作者
能不能不用crossover(close 这种。。明显穿越

使用道具 举报

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

bottom

静态版|手机版|联系我们|交易开拓者 ( 粤ICP备07044698   

GMT+8, 2024-5-4 01:23

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部