您现在的位置:程序化交易>> 期货公式>> 交易开拓者(TB)>> 开拓者公式>>正文内容

开拓者夹板交易策略源码(振荡交易模型)[开拓者公式]

  • 内容: 夹板在实盘中是一个很常见的运用,用于吃住震荡行情。它有个上轨和一个下轨,行情突破上轨就做空;突破下轨就做多,在上下轨之间来回吃。

    OpenCoverFor2Lines函数代码

     

  • 源码:

    1. // 返回值: 1:有所动作,0:没有动作

    2. // 返回值为非零时,把当前要建立的头寸大小和方向写入needPosition,把以什么价格去建立该头寸写入needPrice

    3. // 返回值: 1:有所动作,0:没有动作

    4. // 返回值为非零时,把当前要建立的头寸大小和方向写入needPosition,把以什么价格去建立该头寸写入needPrice

    5.  

    6. Params

    7.         Numeric         currentPosition(0);                // 当前头寸,可正可负

    8.         Numeric        firstLots(0);

    9.  

    10.         Numeric         wantShort(120);                // 开空仓位置

    11.         Numeric         wantLong(8);                         // 开多仓位置

    12.        

    13.         Numeric        wantStopShort(0);                // 空头止损的位置

    14.         Numeric        wantStopLong(0);                // 多头止损的位置

    15.  

    16.        

    17.         // 注意:以下两个都是引用变量!!!!

    18.         NumericRef        needPosition;    // 经过计算后的当前头寸,正数:建立多仓,负数:建立空仓,零:平光所有头寸

    19.         NumericRef needPrice;              // 建立needPosition时的价格

    20.        

    21. Vars

    22.         Numeric                         tem;

    23.        

    24. Begin

    25.  

    26.         // 14:55:00平掉当日所有头寸

    27.         if(time >= 0.1455 && currentPosition != 0)

    28.         {

    29.                 needPosition = 0;

    30.                 needPrice = close ;

    31.                 return 1;

    32.         }

    33.         if(currentPosition == 0)

    34.         {

    35.                 // 无仓,准备侍机开仓

    36.                 if(close <= wantLong)

    37.                 {

    38.                         // 多头 www.cxh99.com

    39.                         needPosition = firstLots;

    40.                         needPrice = wantLong;

    41.                         return 1;

    42.                 }

    43.                 if(close >= wantShort)

    44.                 {

    45.                         // 空头

    46.                         needPosition = -1 * firstLots;

    47.                         needPrice = wantShort;

    48.                         return 1;

    49.                

    50.                 }

    51.                 return 0;

    52.         }

    53.        

    54.         if(currentPosition > 0)

    55.         {

    56.                 // 持多仓,准备止损或反转

    57.                 if(close >= wantShort)

    58.                 {

    59.                         // 反转

    60.                         needPosition = -1 * firstLots;

    61.                         needPrice = wantShort;

    62.                         return 1;

    63.                 }

    64.                

    65.                 if(close <= wantStopLong)

    66.                 {

    67.                         // 止损

    68.                         needPosition = 0;

    69.                         needPrice = wantStopLong;

    70.                         return 1;

    71.                        

    72.                 }

    73.                 return 0;

    74.         }

    75.         if(currentPosition < 0)

    76.         {

    77.                 // 持空仓,准备止损或反转

    78.                 if(close <= wantLong)

    79.                 {

    80.                         // 反转

    81.                         needPosition = firstLots;

    82.                         needPrice = wantLong;

    83.                         return 1;

    84.                 }

    85.                

    86.                 if(close >= wantStopShort)

    87.                 {

    88.                         // 止损

    89.                         needPosition = 0;

    90.                         needPrice = wantStopShort;

    91.                         return 1;

    92.                        

    93.                 }

    94.                 return 0;

    95.         }

    96.           return 0;

    97. End
    98. // 来源: www.cxh99.com
       

 

有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友

可联系技术人员 QQ: 262069696  点击在线交流进行 有偿 编写!不贵!点击查看价格!

 


【字体: 】【打印文章】【查看评论

相关文章

    没有相关内容