设为首页收藏本站

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

多种止盈止损的统一处理函数 [复制链接]

Rank: 7Rank: 7Rank: 7

精华
0
UID
926
积分
4317
帖子
167
主题
33
阅读权限
80
注册时间
2007-12-15
最后登录
2016-8-9
跳转到指定楼层
1#
发表于 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公式修改和重写的权利
//------------------------------------------------------------------------
已有 4 人评分威望 金钱 收起 理由
nestneptune + 2 赞一个!
woomin1985 + 2
zxl0724 + 1 赞一个!
tianlan203 + 66 谢谢向大家分享!

总评分: 威望 + 5  金钱 + 66   查看全部评分

Rank: 7Rank: 7Rank: 7

精华
0
UID
926
积分
4317
帖子
167
主题
33
阅读权限
80
注册时间
2007-12-15
最后登录
2016-8-9
2#
发表于 2009-4-19 16:25:59 |只看该作者
是用户函数,配合“较完善的日内交易系统框架”使用,注意返回值是“字符串”

使用道具 举报

Rank: 6Rank: 6

精华
0
UID
1896
积分
1979
帖子
117
主题
33
阅读权限
70
注册时间
2008-7-16
最后登录
2013-11-16
3#
发表于 2009-4-19 17:32:46 |只看该作者
离楼主很近
沙个发

使用道具 举报

Rank: 5Rank: 5

精华
0
UID
37
积分
719
帖子
96
主题
28
阅读权限
60
注册时间
2007-7-24
最后登录
2013-5-23
4#
发表于 2009-4-19 17:42:03 |只看该作者
顶楼主,
好久没有见到这么勇于共享的人了。

使用道具 举报

Rank: 4

精华
0
UID
4064
积分
286
帖子
40
主题
0
阅读权限
50
注册时间
2009-4-8
最后登录
2017-4-23
5#
发表于 2009-4-23 01:05:22 |只看该作者
顶一个,好贴!!! 顶一个,好贴!!!

使用道具 举报

Rank: 4

精华
0
UID
2423
积分
402
帖子
17
主题
6
阅读权限
50
注册时间
2008-9-22
最后登录
2019-3-30
6#
发表于 2009-4-27 21:11:21 |只看该作者
fish0451  偶像极的,一直顶你

使用道具 举报

Rank: 5Rank: 5

精华
0
UID
1517
积分
1441
帖子
350
主题
29
阅读权限
60
注册时间
2008-4-19
最后登录
2011-10-16
7#
发表于 2009-4-30 07:22:28 |只看该作者
//超时平仓--------------------------------------------------------------
                If(closeTime>100)
                {
                        If(Time>=0.0001*closeTime)         str = "超过清仓时间平仓";        
               
                }
====
看不懂。closeTime>100什么意思?
为什么不是Time>=1.0001*closeTime?

使用道具 举报

Rank: 5Rank: 5

精华
0
UID
1517
积分
1441
帖子
350
主题
29
阅读权限
60
注册时间
2008-4-19
最后登录
2011-10-16
8#
发表于 2009-4-30 07:23:34 |只看该作者
Numeric closeTime(1457); //持仓bar的时间超过此时间后清仓
》100,?

使用道具 举报

Rank: 5Rank: 5

精华
0
UID
1517
积分
1441
帖子
350
主题
29
阅读权限
60
注册时间
2008-4-19
最后登录
2011-10-16
9#
发表于 2009-4-30 07:24:14 |只看该作者
!= 的意思是《》吗?不等于

使用道具 举报

Rank: 5Rank: 5

精华
0
UID
1517
积分
1441
帖子
350
主题
29
阅读权限
60
注册时间
2008-4-19
最后登录
2011-10-16
10#
发表于 2009-4-30 07:34:24 |只看该作者
平仓指令是怎么实现的,用哪个函数?

使用道具 举报

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

bottom

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

GMT+8, 2024-5-12 09:03

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部