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

标题: 多种止盈止损的统一处理函数 [打印本页]

作者: fish0451    时间: 2009-4-19 16:25:03     标题: 多种止盈止损的统一处理函数

//------------------------------------------------------------------------
// 简称: DoPosition
// 名称: 处理持仓部位
// 类别: 用户函数
// 类型: 用户函数
// 输出: 字符串
//------------------------------------------------------------------------

Params
        Numeric         tradState(0);                // 当前头寸,1=多,-1=空
        Numeric    tradCyc(0);                        // 持仓周期数
        Numeric         curProfit(0);                //持仓当前浮动盈亏
        Numeric         maxProfit(0);                //持仓最大浮盈
       
        Numeric stopLoss(0); //盈利低于此值时止损,为0不判断
        Numeric stopProfis(0); //盈利高于此值时止赢,为0不判断
       
        Numeric tracProfis(0); //盈利高于此值后执行追踪止赢,为0不判断
        Numeric tracLoss(0); //追踪止盈的回撤值,为0不判断,盈利超过tracProfis后,从最大浮赢回撤tracLoss后止盈       
       
        Numeric returnProfis(0); //盈利高于此值后执行回撤止赢,为0不判断       
               
        Numeric minProfis(0); //持仓bar数超过maxHoles后,盈利依然小于此值平仓,为0不判断       
        Numeric maxHolds(0);//最多持仓bar数,为0不判断
       
        Numeric closeTime(1457); //持仓bar的时间超过此时间后清仓

Vars
        String str(" ");
Begin

        //-------------------------------处理持仓-------------------------------------------
        if(tradState != 0 )
        {               
                //价格止损:亏损超过stopLoss-------------------------------------------------
                If(stopLoss>0)
                {
                        If(curProfit<=(0-stopLoss) )        str = "止损平仓";       
                }
               
                //时间止损:持仓超过maxHolds后最大浮动盈亏在正负minProfis之间------------------------------
                If(minProfis>0 And maxHolds>0)
                {
                        If(curProfit<=minProfis And tradCyc>=maxHolds )        str = "超时未达盈利平仓";                               
                }               
                //超时平仓--------------------------------------------------------------
                If(closeTime>100)
                {
                        If(Time>=0.0001*closeTime)         str = "超过清仓时间平仓";       
               
                }
                //停板平仓-----------------------------------------------
                If(BarStatus==2)
                {
                        if(High==Q_UpperLimit() Or Low==Q_LowerLimit())        str = "停板平仓";       
                }
                Else
                {
                        if(High==Low And High==Close And High[1]==Low[1] And High[2]==Low[2])        str = "停板平仓";                                       
                }

                //价格止盈:盈利超过stopProfis-----------------------------------------------
                If(stopProfis>0)
                {
                        If(curProfit>=stopProfis )        str = "止盈平仓";                       
                }
               
                //跟踪止盈:盈利超过tracProfis后回撤超过tracLoss平仓---------------------------
                If(tracLoss>0 And tracProfis>0)
                {
                        If((maxProfit-curProfit)>=tracLoss And maxProfit>tracProfis)        str = "跟踪止盈平仓";                       
                }
                //回撤止盈:盈利超过returnProfis后回撤平仓-------------------------------------
                If(returnProfis>0 And maxProfit>0.9*returnProfis)
                {
                        If(maxProfit>0.9*returnProfis And maxProfit<=1.1*returnProfis And curProfit<=0.1*maxProfit)        str = "盈利回撤止盈平仓1倍90%";       
                       
                        If(maxProfit>1.1*returnProfis And maxProfit<=2*returnProfis And curProfit<=0.5*maxProfit)        str = "盈利回撤止盈平仓1-2倍50%";       
                       
                        If(maxProfit>2*returnProfis And maxProfit<=3*returnProfis And curProfit<=0.6*maxProfit)        str = "盈利回撤止盈平仓2-3倍40%";                       
                       
                        If(maxProfit>3*returnProfis And maxProfit<=4*returnProfis And curProfit<=0.7*maxProfit)        str = "盈利回撤止盈平仓3-4倍30%";               
                       
                        If(maxProfit>4*returnProfis And maxProfit<=5*returnProfis And curProfit<=0.8*maxProfit)        str = "盈利回撤止盈平仓4-5倍20%";               

                        If(maxProfit>6*returnProfis And curProfit<=0.9*maxProfit)        str = "盈利回撤止盈平仓大于6倍10%";                                                
                       
                }       
        }
        Return str;
End

//------------------------------------------------------------------------
// 编译版本        GS2004.06.12
// 用户版本        2009/04/15 21:11
// 版权所有        fish0451
// 更改声明        TradeBlazer Software保留对TradeBlazer平台
//                        每一版本的TrabeBlazer公式修改和重写的权利
//------------------------------------------------------------------------
作者: fish0451    时间: 2009-4-19 16:25:59

是用户函数,配合“较完善的日内交易系统框架”使用,注意返回值是“字符串”
作者: bluefox    时间: 2009-4-19 17:32:46

离楼主很近
沙个发
作者: fcotrader    时间: 2009-4-19 17:42:03

顶楼主,
好久没有见到这么勇于共享的人了。
作者: 简单    时间: 2009-4-23 01:05:22

顶一个,好贴!!! 顶一个,好贴!!!
作者: zfjizy    时间: 2009-4-27 21:11:21

fish0451  偶像极的,一直顶你
作者: 捕快    时间: 2009-4-30 07:22:28

//超时平仓--------------------------------------------------------------
                If(closeTime>100)
                {
                        If(Time>=0.0001*closeTime)         str = "超过清仓时间平仓";        
               
                }
====
看不懂。closeTime>100什么意思?
为什么不是Time>=1.0001*closeTime?
作者: 捕快    时间: 2009-4-30 07:23:34

Numeric closeTime(1457); //持仓bar的时间超过此时间后清仓
》100,?
作者: 捕快    时间: 2009-4-30 07:24:14

!= 的意思是《》吗?不等于
作者: 捕快    时间: 2009-4-30 07:34:24

平仓指令是怎么实现的,用哪个函数?
作者: 捕快    时间: 2009-4-30 07:35:09

这个函数是不是用来记录交易指令的而不是发出交易指令的?
作者: zyxsir    时间: 2012-6-21 13:53:40

请问怎样使用这个函数?
作者: tufeiyige    时间: 2012-7-6 10:04:54

好东西  谢谢
作者: 道勤    时间: 2012-7-6 14:12:13

非常不错,十分感谢~!
作者: shanzi168    时间: 2012-12-21 20:20:59

非常感谢!!!!!!!!!!!!!
作者: zxl0724    时间: 2012-12-30 19:14:37

还没看懂

作者: bingxue    时间: 2013-2-20 21:43:15

mark.
作者: topgun0791    时间: 2016-6-22 15:54:59

niu B




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