开拓者期货期权程序化系统交易论坛

标题: 源码 KD2号模型,转载别人的 [打印本页]

作者: woomin1985    时间: 2013-2-15 23:04:49     标题: 源码 KD2号模型,转载别人的

本帖最后由 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

评测:回测就大把问题,感觉没啥存在的必要.
作者: 无心    时间: 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




作者: 天崖    时间: 2013-2-16 09:09:55

这个策略,用在哪个周期、哪个品种,收益比较好啊???
作者: TRANS-AM    时间: 2013-2-16 10:41:26

编一个好模型是个漫长的过程
作者: landwatcher    时间: 2013-2-24 15:01:23

能不能不用crossover(close 这种。。明显穿越




欢迎光临 开拓者期货期权程序化系统交易论坛 (http://bbs.tb18.net/) Powered by Discuz! X2