设为首页收藏本站

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

如何表达:当K线满足条件con1之后的5根K线之内同时满足条件con2,则开仓 [复制链接]

Rank: 1

精华
0
UID
187472
积分
9
帖子
8
主题
1
阅读权限
10
注册时间
2014-5-26
最后登录
2015-4-30
跳转到指定楼层
1#
发表于 2014-7-12 07:48:00 |只看该作者 |倒序浏览
有哪位帅哥可以帮忙表达TB的一个编程,拜托了,一直写了很多很多次都编译不,需要变量可以自己定,我看得懂:
5分钟周期,当K线满足条件con1之后的5根K线之内同时满足条件con2,则开仓。
(备注:重点是表达5根K线之内,意思是满足条件con1之后的第一根K线,或第二根,或第三根,或第四根K线,或第五根K线,再次满足条件con2则开仓;

Rank: 3Rank: 3

精华
0
UID
116726
积分
166
帖子
57
主题
8
阅读权限
40
注册时间
2013-4-2
最后登录
2014-7-16
2#
发表于 2014-7-13 11:48:30 |只看该作者
仅看楼主描述写了一点代码, 如果知道策略上下文, 可能还可以简化写法.
  1. Params
  2.         Numeric CounterLimit(5);                    
  3. Vars
  4.         BoolSeries Con1(false);
  5.         BoolSeries Con2(false);
  6.         Bool Entry(false);
  7.         NumericSeries Counter(0); //计数器;
  8. Begin
  9.         //满足con1的k线将couter赋值为1;
  10.         if (Con1 and Counter[1] == 0)
  11.         {
  12.                 Counter = 1;
  13.         }
  14.        
  15.         //前一k线的计数器的数值未超限,则当前k线将计数器的值加一;
  16.         if(Counter[1] > 0 and Counter[1] < CounterLimit)
  17.         {
  18.                 Counter = Counter + 1;
  19.                
  20.                 //计数器范围内,满足con2,将开仓条件赋值为真;
  21.                 Entry = Counter <= CounterLimit and Con2;
  22.         }
  23.        
  24.         //计数器的值达到范围上限的k线未满足条件con2,初始化值Conter为0;
  25.         if(Counter == CounterLimit and !Con2)
  26.         {
  27.                 Counter = 0;
  28.         }
  29.        
  30. End
复制代码

使用道具 举报

Rank: 1

精华
0
UID
187472
积分
9
帖子
8
主题
1
阅读权限
10
注册时间
2014-5-26
最后登录
2015-4-30
3#
发表于 2014-7-14 14:15:01 |只看该作者
米小兔 发表于 2014-7-13 11:48
仅看楼主描述写了一点代码, 如果知道策略上下文, 可能还可以简化写法.

感谢帅哥的指点,我整个的策略是这样的,我以下的代码可以帮忙修改吗:1、做多条件:MACD 上穿0轴后完成后正值柱线不超过 5 根且价格在20期指数移动平均线上M个点处做多,分批出场策略:初步止损2手在entrprice-8*MinPoint,当价格上涨至entrprice+13*MinPoin时止盈1手,剩余1手若价格下落则在entryprice保本出场,若价格继续上涨则止盈设置在20期指数移动平均线下M个点;做空条件,MACD 下穿0轴后完成后负值柱线不超过 5 根且价格在20期指数移动平均线下方M个点处做空2手,分批出场策略:初步止损2手在entrprice+8*MinPoint,当价格下跌至entrprice-13*MinPoin时止盈1手,剩余1手若上涨则在entryprice保本出场,若价格继续下跌则止盈设置在20期指数移动平均线上M个点;



使用道具 举报

Rank: 3Rank: 3

精华
0
UID
116726
积分
166
帖子
57
主题
8
阅读权限
40
注册时间
2013-4-2
最后登录
2014-7-16
4#
发表于 2014-7-14 14:25:27 |只看该作者
加我QQ55297268

使用道具 举报

Rank: 1

精华
0
UID
187472
积分
9
帖子
8
主题
1
阅读权限
10
注册时间
2014-5-26
最后登录
2015-4-30
5#
发表于 2014-7-14 14:42:39 |只看该作者
米小兔 发表于 2014-7-13 11:48
仅看楼主描述写了一点代码, 如果知道策略上下文, 可能还可以简化写法.

Params
        Numeric FastLength(12);
        Numeric SlowLength(26);
        Numeric MACDLength(9);
        Numeric Length(20);//20日指数移动平均
        Numeric M(4);//进场必须距离20日指数移动平均的距离,目的是过滤假突破;剩余一半仓位距离20日指数平均的距离后出场
Vars
        NumericSeries MACDValue;
        Numeric AvgMACD;
        Numeric MACDDiff;
        Bool con1;
        Bool con2;
        Bool con3;
        Bool con4;
        Numeric MinPoint;
        NumericSeries EMA20;
        Numeric myEntryprice;//进场价格
        Numeric myExitPrice;
        NumericSeries a(0);
        NumericSeries b(0);
Begin
        MinPoint=MinMove*PriceScale;
        MinPoint = MinMove*PriceScale;
        EMA20=XAverage(Close, Length);
        PlotNumeric("EMA20",EMA20);
        MACDValue = XAverage( Close, FastLength ) - XAverage( Close, SlowLength ) ;       
        AvgMACD = XAverage(MACDValue,MACDLength);
        MACDDiff = MACDValue - AvgMACD;
        Commentary("MACD="+Text(MACDDiff));
        con1=(MACDDiff>0);
        con2=(high>=(EMA20[1]+M*MinPoint));
        con3=(MACDDiff<0);
        con4=(low<=(EMA20[1]-M*MinPoint));
        if(MarketPosition<>1 and (countif(con1,5))>=1 and  con2)
   {   
     
     myEntryprice=EMA20[1]+M*MinPoint;
         If(Open>myEntryprice)myEntryprice=Open;
     buy(1,myEntryprice);
      a=0;
               }
  if(MarketPosition==1)
{
  if(high>=entryprice+13*MinPoint and a==0)
  { myExitprice=entryprice+13*MinPoint;
   if(Open>entryprice+13*MinPoint)myExitprice=Open;
   sell(1,myExitPrice);
    a=1;
   }
   if(low<=entryPrice)  
     { myExitprice=entryprice;
    if(open<entryPrice)myExitPrice=entryPrice;
    sell(1,myExitPrice);
      }
   if(low<=entryPrice-8*MinPoint)
   {
     myExitprice=entryPrice-8*MinPoint;
     if(open<entryPrice-8*MinPoint)myExitprice=open;
     sell(0,myExitPrice);   
     }
   }


     If(MarketPosition<>-1 and  (countif(con3,5))>=1 and con4)
{   
        myEntryprice=EMA20[1]-M*MinPoint;
         If(Open<myEntryprice)myEntryprice=Open;
     SellShort(1,myEntryprice);
     
}

  
if(MarketPosition==-1)
{
  if(low<=entryprice-13*MinPoint and b==0)
  { myExitprice=entryprice-13*MinPoint;
   if(Open<entryprice-13*MinPoint)myExitprice=Open;
   buyToCover(1,myExitPrice);
    b=1;
   }
   if(high>=entryPrice)  
     { myExitprice=entryprice;
    if(open>entryPrice)myExitPrice=entryPrice;
    buyToCover(1,myExitPrice);
      }
   if(high>=entryPrice+8*MinPoint)
   {
     myExitprice=entryPrice+8*MinPoint;
     if(open<entryPrice+8*MinPoint)myExitprice=open;
     buyToCover(0,myExitPrice)  ;  
     }
   }


End

使用道具 举报

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

bottom

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

GMT+8, 2024-5-9 21:50

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部