- 精华
- 0
- 在线时间
- 386 小时
- UID
- 15934
- 积分
- 681
- 帖子
- 188
- 阅读权限
- 60
- 注册时间
- 2010-9-9
- 最后登录
- 2021-9-1
- 精华
- 0
- UID
- 15934
- 积分
- 681
- 帖子
- 188
- 主题
- 70
- 阅读权限
- 60
- 注册时间
- 2010-9-9
- 最后登录
- 2021-9-1
|
// 简称: 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
请管理员举一个简单使用的范例,谢谢! |
|