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

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

作者: 13522213793    时间: 2010-8-11 09:56: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
作者: zyloogle    时间: 2011-2-2 17:02:54

不错,有点新东西.
止盈比止损难点.
作者: ww123    时间: 2011-4-22 13:17:48


作者: ww123    时间: 2011-4-22 13:22:32

在这里加你的
作者: haomai01    时间: 2011-5-27 19:50:44

请问能不能写的明白一些,请问怎么用在V4的交易系统里面,怎么引用这个用户函数,请版主帮助回答
作者: rookies    时间: 2011-6-9 17:16:58

怎么样调用这个函数啊?




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