设为首页收藏本站

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

多种止盈止损 [复制链接]

Rank: 5Rank: 5

精华
0
UID
15934
积分
681
帖子
188
主题
70
阅读权限
60
注册时间
2010-9-9
最后登录
2021-9-1
跳转到指定楼层
1#
发表于 2012-6-21 13:58:02 |只看该作者 |倒序浏览
   // 简称: 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

请管理员举一个简单使用的范例,谢谢!
天道酬勤,随遇而安
您需要登录后才可以回帖 登录 | 注册

bottom

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

GMT+8, 2024-4-24 00:22

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部