设为首页收藏本站

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

请版主看看陈总讲课的这段程序为什么我总调不通? [复制链接]

Rank: 4

精华
0
UID
35247
积分
410
帖子
79
主题
36
阅读权限
50
注册时间
2011-4-24
最后登录
2013-1-10
跳转到指定楼层
1#
发表于 2011-6-30 11:57:13 |只看该作者 |倒序浏览
本帖最后由 kongwei1107 于 2011-6-30 12:04 编辑

陈总这月在深圳招商证券讲课时的课件中,举了一个趋势交易的例子。因陈总没有给出最后完整的程序,我在课后学习和琢磨这个例子时,自己按陈总的课件,复原了程序,但总是调不通。

以CF1201 30分钟周期,从2011年1月1日开始的交易测试为例,总是只执行一次交易,后面的就不执行了,更谈不上二次进场了。



请版主看看问题出在哪里.谢谢。

源码如下:

Params                                                
        Numeric Length1(10);
        Numeric Length2(20);
        Numeric Lots(1);   
        Numeric InitialStop(20);                          // 初始止损(千分之N)
        Numeric BreakEvenStop(30);                  // 保本止损(千分之N)
        Numeric TrailingStop(50);                        // 追踪止损(千分之N)
         
Vars                                                   
        NumericSeries MA1;                           
        NumericSeries MA2;
        BoolSeries condBuy(false);
        BoolSeries condSell(false);
        Numeric MinPoint;
        Numeric MyPrice;
        NumericSeries HigherAfterEntry;
        NumericSeries LowerAfterEntry;
        BoolSeries bLongStoped(false);
        BoolSeries bShortStoped(false);
        Numeric StopLine;
        Numeric StopLine1;
        Numeric StopLine2;
        Numeric StopLine3;
        String strDate;
        String strTime;
        String TRADENAME;

Begin  
        if(condBuy==false and condSell==false )
                {
                        condBuy=condBuy[1];
                        condSell=condSell[1];
                }
        if(BarStatus>0)
                {
                        bLongStoped=bLongStoped[1];                        //多头止损情况
                        bShortStoped=bShortStoped[1];                //空头止损情况
                }
                                                                                               
        MinPoint=MinMove * PriceScale;
        MA1=AverageFC(Close,Length1);              
        MA2=AverageFC(Close,Length2);               
        condBuy=CrossOver(MA1,MA2);
        condSell=CrossUnder(MA1,MA2);
       
        If(MarketPosition!=1 and condBuy[1]==true and bLongStoped==False)//初次进场做多
                {
                        Buy(Lots,Open);
                       
                        HigherAfterEntry=Open;
                        LowerAfterEntry=Open;
                       
                        bLongStoped=False;//重置标志
                        bShortStoped=False;//重置标志
               
                        Commentary("Buy Firsttime at "+text(Open));
                        Commentary("HAE="+TEXT(HigherAfterEntry)+" LAE="+Text(LowerAfterEntry));
                        Commentary("bLongStoped="+IIFString(bLongStoped,"TRUE","FALSE"));
                        Commentary("bShortStoped="+IIFString(bShortStoped,"TRUE","FALSE"));               
                }
        If(MarketPosition!=-1 and condSell[1]==true and bShortStoped==False)//初次进场做空
                {
                        SellShort(lots,Open);
                       
                        HigherAfterEntry=Open;
                        LowerAfterEntry=Open;
                       
                        bLongStoped=False;//重置标志
                        bShortStoped=False;//重置标志
       
                        Commentary("SellShort Firsttime at "+text(Open));
                        Commentary("HAE="+TEXT(HigherAfterEntry)+" LAE="+Text(LowerAfterEntry));
                        Commentary("bLongStoped="+IIFString(bLongStoped,"TRUE","FALSE"));
                        Commentary("bShortStoped="+IIFString(bShortStoped,"TRUE","FALSE"));
                }
        If(BarsSinceEntry>=1)
                {
                        HigherAfterEntry=Max(HigherAfterEntry[1],High[1]);
                        LowerAfterEntry=Min(LowerAfterEntry[1],Low[1]);
                }
        Else
                {
                        HigherAfterEntry=HigherAfterEntry[1];
                        LowerAfterEntry=LowerAfterEntry[1];
                }
        If(MarketPosition==1)//多头止损部分的代码
                {
                        StopLine=EntryPrice * (1-InitialStop/1000);       
                        If (HigherAfterEntry>=EntryPrice*(1+BreakEvenStop/1000))        StopLine=EntryPrice;
                        If (StopLine<HigherAfterEntry*(1-TrailingStop/1000))              StopLine=HigherAfterEntry*(1-TrailingStop/1000);
                              
                                               Commentary("止损价:"+Text(StopLine));        
               
                        If(Low<=StopLine)// 止损触发
                                {
                                        MyPrice=StopLine;
                                        If(Open<MyPrice)            MyPrice=Open;
                                        Sell(Lots,MyPrice);
                                       
                                        bLongStoped=True;                // 止损后设置标志
                               
                                        Commentary("Long Position Stoped at "+text(MyPrice));
                                }
                }
        If(MarketPosition==-1)//空头止损部分的代码
                {
                        StopLine=EntryPrice*(1+InitialStop/1000);
                        If(LowerAfterEntry<=EntryPrice*(1+BreakEvenStop/1000))               StopLine=EntryPrice;
                        If(StopLine>LowerAfterEntry*(1+TrailingStop/1000))               StopLine=LowerAfterEntry*(1+TrailingStop/1000);
                                       
                        Commentary("止损价:"+Text(StopLine));
               
                        If(High>=StopLine)// 止损触发
                                {
                                        MyPrice=StopLine;
                                        If(Open>MyPrice)      MyPrice=Open;
                                        Sell(Lots,MyPrice);
                                       
                                        bLongStoped=True;                // 止损后设置标志
       
                                        Commentary("Short Position Stoped at "+text(MyPrice));
                                }
                }
        IF(bLongStoped AND MarketPosition==0 AND H>HigherAfterEntry)//二次进场做多
                {
                        MyPrice=HigherAfterEntry+MinPoint;
                        If(Open>MyPrice)
                                MyPrice=Open;
                       
                        Buy(Lots,MyPrice);
                       
                        bLongStoped=False;
                       
                        HigherAfterEntry=AvgEntryPrice;
                        LowerAfterEntry=HigherAfterEntry;
               
                        Commentary("Buy Secondtime at "+text(Open));
                        Commentary("HAE="+TEXT(HigherAfterEntry)+" LAE="+Text(LowerAfterEntry));
                        Commentary("bLongStoped="+IIFString(bLongStoped,"TRUE","FALSE"));
                        Commentary("bShortStoped="+IIFString(bShortStoped,"TRUE","FALSE"));
                       
                        Return;
                }
        If(bShortStoped AND MarketPosition==0 AND L<LowerAfterEntry)//二次进场做空
                {
                        MyPrice=LowerAfterEntry - MinPoint;
                        If(Open<MyPrice) MyPrice = Open;
                       
                        SellShort(Lots,MyPrice);
                       
                        bShortStoped=False;
               
                        HigherAfterEntry=AvgEntryPrice;
                        LowerAfterEntry=HigherAfterEntry;
                       
                        Commentary("SellShort Secondtime at "+text(Open));
                        Commentary("HAE="+TEXT(HigherAfterEntry)+" LAE="+Text(LowerAfterEntry));
                        Commentary("bLongStoped="+IIFString(bLongStoped,"TRUE","FALSE"));
                        Commentary("bShortStoped="+IIFString(bShortStoped,"TRUE","FALSE"));
                       
                        Return;
                }
End
附件: 你需要登录才可以下载或查看附件。没有帐号?注册
期货新手

Rank: 10Rank: 10Rank: 10

精华
0
UID
20842
积分
931
帖子
382
主题
2
阅读权限
255
注册时间
2010-12-3
最后登录
2022-2-15
2#
发表于 2011-6-30 22:07:13 |只看该作者
回复 1# kongwei1107

这个例子的源代码,课后有很多朋友都拷贝了,如果需要,留下您的Email,回头发给您。

使用道具 举报

Rank: 5Rank: 5

精华
0
UID
12330
积分
838
帖子
254
主题
15
阅读权限
60
注册时间
2010-6-16
最后登录
2017-4-25
3#
发表于 2011-7-1 06:55:27 |只看该作者
回复  kongwei1107

这个例子的源代码,课后有很多朋友都拷贝了,如果需要,留下您的Email,回头发给您。 ...
追涨杀跌 发表于 2011-6-30 22:07


能发给我一份么?不胜感激!
邮箱:1042219259@qq.com

使用道具 举报

Rank: 6Rank: 6

精华
0
UID
1041
积分
1642
帖子
448
主题
133
阅读权限
70
注册时间
2008-1-9
最后登录
2016-12-26
4#
发表于 2011-7-1 08:38:16 |只看该作者
是否能给我一份 不胜感激
speed_stock@163.com

使用道具 举报

Rank: 4

精华
0
UID
35247
积分
410
帖子
79
主题
36
阅读权限
50
注册时间
2011-4-24
最后登录
2013-1-10
5#
发表于 2011-7-1 09:42:44 |只看该作者
回复 2# 追涨杀跌

太好了。

我没时间到会去听,接着又到了美国,看着别人发给我的课件复原程序,总是有问题。

请给我发到:kongwei@262.net

再次感谢你。
期货新手

使用道具 举报

Rank: 2

精华
0
UID
46929
积分
60
帖子
26
主题
12
阅读权限
30
注册时间
2011-6-13
最后登录
2012-12-25
6#
发表于 2011-7-1 10:00:03 |只看该作者
非常感谢,请发到xumaoan@163.com
虚怀若谷 处变不惊

使用道具 举报

Rank: 10Rank: 10Rank: 10

精华
0
UID
20842
积分
931
帖子
382
主题
2
阅读权限
255
注册时间
2010-12-3
最后登录
2022-2-15
7#
发表于 2011-7-1 10:34:58 |只看该作者
回复 6# 期货迷007

太好了。

我没时间到会去听,接着又到了美国,看着别人发给我的课件复原程序,总是有问题。

请给我发到:kongwei@262.net

再次感谢你。


已经给所有留了Email的朋友都发了。kongwei1107,我发邮件时,QQ的邮件系统提示262.net是个错误的域名,我估计有可能是您输错了,我尝试着改成了263.net,如果没收到,告诉一声。

使用道具 举报

Rank: 1

精华
0
UID
48530
积分
5
帖子
2
主题
0
阅读权限
10
注册时间
2011-6-20
最后登录
2011-7-18
8#
发表于 2011-7-1 11:19:32 |只看该作者
陈总你好。能发给我一份吗?感激。tianxiangbo@egoldbank.cn
期货dt进化论。

使用道具 举报

Rank: 1

精华
0
UID
48530
积分
5
帖子
2
主题
0
阅读权限
10
注册时间
2011-6-20
最后登录
2011-7-18
9#
发表于 2011-7-1 11:22:23 |只看该作者
陈总你好。能发给我一份吗?感激。tianxiangbo@egoldbank.cn
期货dt进化论。

使用道具 举报

Rank: 5Rank: 5

精华
0
UID
15958
积分
1290
帖子
155
主题
22
阅读权限
60
注册时间
2010-9-9
最后登录
2021-1-25
10#
发表于 2011-7-1 13:32:04 |只看该作者
本帖最后由 穿堂风 于 2011-7-1 13:40 编辑

我改了下,全部贴出来吧
  1. Params                                                
  2.         Numeric Length1(10);
  3.         Numeric Length2(20);
  4.         Numeric Lots(1);   
  5.         Numeric InitialStop(20);                          // 初始止损(千分之N)
  6.         Numeric BreakEvenStop(30);                  // 保本止损(千分之N)
  7.         Numeric TrailingStop(50);                        // 追踪止损(千分之N)
  8.          
  9. Vars                                                   
  10.         NumericSeries MA1;                           
  11.         NumericSeries MA2;
  12.         BoolSeries condBuy(false);
  13.         BoolSeries condSell(false);
  14.         Numeric MinPoint;
  15.         Numeric MyPrice;
  16.         NumericSeries HigherAfterEntry;
  17.         NumericSeries LowerAfterEntry;
  18.         BoolSeries bLongStoped(false);
  19.         BoolSeries bShortStoped(false);
  20.         Numeric StopLine;
  21.         Numeric StopLine1;
  22.         Numeric StopLine2;
  23.         Numeric StopLine3;
  24.         String strDate;
  25.         String strTime;
  26.         String TRADENAME;

  27. Begin  
  28.         if(condBuy==false and condSell==false )
  29.         {
  30.                 condBuy=condBuy[1];
  31.                 condSell=condSell[1];
  32.         }
  33.         if(BarStatus>0)
  34.         {
  35.                 bLongStoped=bLongStoped[1];                        //多头止损情况
  36.                 bShortStoped=bShortStoped[1];                //空头止损情况
  37.         }
  38.                                                                                                 
  39.         MinPoint=MinMove * PriceScale;
  40.         MA1=AverageFC(Close,Length1);              
  41.         MA2=AverageFC(Close,Length2);               
  42.         condBuy=CrossOver(MA1,MA2);
  43.         condSell=CrossUnder(MA1,MA2);
  44.         
  45.         If(MarketPosition!=1 and condBuy[1]==true and bLongStoped==False)//初次进场做多
  46.         {
  47.                 Buy(Lots,Open);
  48.                         
  49.                 HigherAfterEntry=Open;
  50.                 LowerAfterEntry=Open;
  51.                         
  52.                 bLongStoped=False;//重置标志
  53.                 bShortStoped=False;//重置标志
  54.                
  55.                 Commentary("Buy Firsttime at "+text(Open));
  56.                 Commentary("HAE="+TEXT(HigherAfterEntry)+" LAE="+Text(LowerAfterEntry));
  57.                 Commentary("bLongStoped="+IIFString(bLongStoped,"TRUE","FALSE"));
  58.                 Commentary("bShortStoped="+IIFString(bShortStoped,"TRUE","FALSE"));               
  59.         }
  60.         If(MarketPosition!=-1 and condSell[1]==true and bShortStoped==False)//初次进场做空
  61.         {
  62.                 SellShort(lots,Open);
  63.                         
  64.                 HigherAfterEntry=Open;
  65.                 LowerAfterEntry=Open;
  66.                         
  67.                 bLongStoped=False;//重置标志
  68.                 bShortStoped=False;//重置标志
  69.         
  70.                 Commentary("SellShort Firsttime at "+text(Open));
  71.                 Commentary("HAE="+TEXT(HigherAfterEntry)+" LAE="+Text(LowerAfterEntry));
  72.                 Commentary("bLongStoped="+IIFString(bLongStoped,"TRUE","FALSE"));
  73.                 Commentary("bShortStoped="+IIFString(bShortStoped,"TRUE","FALSE"));
  74.         }
  75.         If(BarsSinceEntry>=1)
  76.         {
  77.                 HigherAfterEntry=Max(HigherAfterEntry[1],High[1]);
  78.                 LowerAfterEntry=Min(LowerAfterEntry[1],Low[1]);
  79.         }
  80.         Else
  81.         {
  82.                 HigherAfterEntry=HigherAfterEntry[1];
  83.                 LowerAfterEntry=LowerAfterEntry[1];
  84.         }
  85.         If(MarketPosition==1)//多头止损部分的代码
  86.         {
  87.                 StopLine=EntryPrice * (1-InitialStop/1000);        
  88.                 If (HigherAfterEntry>=EntryPrice*(1+BreakEvenStop/1000))
  89.                 {
  90.                         StopLine=EntryPrice;
  91.                 }
  92.                 If (StopLine<HigherAfterEntry*(1-TrailingStop/1000))
  93.                 {
  94.                         StopLine=HigherAfterEntry*(1-TrailingStop/1000);
  95.                 }
  96.                               
  97.                 Commentary("止损价:"+Text(StopLine));        
  98.                
  99.                 If(Low<=StopLine)// 止损触发
  100.                 {
  101.                         MyPrice=StopLine;
  102.                         If(Open<MyPrice)
  103.                         {
  104.                                 MyPrice=Open;
  105.                         }
  106.                         Sell(Lots,MyPrice);
  107.                                        
  108.                         bLongStoped=True;                // 止损后设置标志
  109.                                 
  110.                         Commentary("Long Position Stoped at "+text(MyPrice));
  111.                 }
  112.         }
  113.         If(MarketPosition==-1)//空头止损部分的代码
  114.         {
  115.                 StopLine=EntryPrice*(1+InitialStop/1000);
  116.                 If(LowerAfterEntry<=EntryPrice*(1+BreakEvenStop/1000))               StopLine=EntryPrice;
  117.                 If(StopLine>LowerAfterEntry*(1+TrailingStop/1000))               StopLine=LowerAfterEntry*(1+TrailingStop/1000);
  118.                                        
  119.                 Commentary("止损价:"+Text(StopLine));
  120.                
  121.                 If(High>=StopLine)// 止损触发
  122.                 {
  123.                         MyPrice=StopLine;
  124.                         If(Open>MyPrice)
  125.                         {
  126.                                 MyPrice=Open;
  127.                         }
  128.                         BuyToCover(Lots,MyPrice);
  129.        
  130.                         bShortStoped=True;                // 止损后设置标志
  131.         
  132.                         Commentary("Short Position Stoped at "+text(MyPrice));
  133.                 }
  134.         }
  135.         IF(bLongStoped AND MarketPosition==0 AND H>HigherAfterEntry)//二次进场做多
  136.         {
  137.                 MyPrice=HigherAfterEntry+MinPoint;
  138.                 If(Open>MyPrice)
  139.                 {
  140.                         MyPrice=Open;
  141.                 }
  142.                         
  143.                 Buy(Lots,MyPrice);
  144.                         
  145.                 bLongStoped=False;
  146.                         
  147.                 HigherAfterEntry=AvgEntryPrice;
  148.                 LowerAfterEntry=HigherAfterEntry;
  149.                
  150.                 Commentary("Buy Secondtime at "+text(Open));
  151.                 Commentary("HAE="+TEXT(HigherAfterEntry)+" LAE="+Text(LowerAfterEntry));
  152.                 Commentary("bLongStoped="+IIFString(bLongStoped,"TRUE","FALSE"));
  153.                 Commentary("bShortStoped="+IIFString(bShortStoped,"TRUE","FALSE"));
  154.                         
  155.                 Return;
  156.         }
  157.         If(bShortStoped AND MarketPosition==0 AND L<LowerAfterEntry)//二次进场做空
  158.         {
  159.                 MyPrice=LowerAfterEntry - MinPoint;
  160.                 If(Open<MyPrice)
  161.                 {
  162.                         MyPrice = Open;
  163.                 }
  164.                         
  165.                 SellShort(Lots,MyPrice);
  166.                         
  167.                 bShortStoped=False;
  168.                
  169.                 HigherAfterEntry=AvgEntryPrice;
  170.                 LowerAfterEntry=HigherAfterEntry;
  171.                         
  172.                 Commentary("SellShort Secondtime at "+text(Open));
  173.                 Commentary("HAE="+TEXT(HigherAfterEntry)+" LAE="+Text(LowerAfterEntry));
  174.                 Commentary("bLongStoped="+IIFString(bLongStoped,"TRUE","FALSE"));
  175.                 Commentary("bShortStoped="+IIFString(bShortStoped,"TRUE","FALSE"));
  176.                         
  177.                 Return;
  178.         }
  179. End
复制代码
我一生在纸上,被风吹乱

使用道具 举报

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

bottom

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

GMT+8, 2024-5-19 05:17

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部