- 精华
- 0
- 在线时间
- 243 小时
- UID
- 222769
- 积分
- 175
- 帖子
- 104
- 阅读权限
- 40
- 注册时间
- 2015-11-7
- 最后登录
- 2021-2-26
- 精华
- 0
- UID
- 222769
- 积分
- 175
- 帖子
- 104
- 主题
- 41
- 阅读权限
- 40
- 注册时间
- 2015-11-7
- 最后登录
- 2021-2-26
|
满足条件1只减仓1手,条件2减仓1手,如何控制,谢谢
我这给减仓完了
Params
Numeric Length1(41); //长周期区间参数
Numeric Length2(3); //短周期区间参数
Numeric IPS(1.2); //保护止损波动率参数
Numeric AtrVal(20); //波动率参数
Numeric jx(107);
Numeric lots(5);
Numeric SubSet(8); // 减仓设置
Numeric lots1(1);
Vars
NumericSeries ProtectStopL;
NumericSeries ATR;
NumericSeries Upperband;
NumericSeries Lowerband;
NumericSeries Exitlong;
NumericSeries Exitshort;
NumericSeries ma;
Numeric L2;
Numeric L1;
Numeric Minpoint;
NumericSeries firstPrice; // 第一次开仓价格
NumericSeries LastPrice; // 最后一次开仓价格
Numeric AddSet(30); // 加仓设置
Numeric flag(0) ;
Begin
// 集合竞价和小节休息过滤
If(!CallAuctionFilter()) Return;
Minpoint = Minmove*PriceScale;
ATR = AvgTrueRange(AtrVal); //定义ATR
L1 = Max(Length1,Length2); //出场周期选择较大的区间参数
L2 = Min(Length1,Length2); //出场周期选择较小的区间参数
Upperband = Highest(High, L1); //长周期最高价区间
Lowerband = lowest(Low,L1); //长周期最低价区间
Exitlong = Lowest(Low,L2); //短周期最低价区间
Exitshort = Highest(high,L2); //短周期最高价区间
ma=Average(c,jx);
//系统入场
If(Marketposition == 0 and High >= Upperband[1] + Minpoint And Vol > 0 and c[1]>ma[1]) //价格大于长周期最高价区间入场做多
{
Buy(lots, Max(Open, Upperband[1] + 2*Minpoint));firstPrice=LastEntryPrice;
ProtectStopL = Entryprice - IPS*ATR[1];
}
//系统出场
If(MarketPosition == 1 and BarsSinceEntry >0 And Vol > 0)
{
If( Low <= ProtectStopL[1] and ProtectStopL[1] >= Exitlong[1]) //价格低于入场价以下一定ATR幅度止损
{
Sell (0,Min(Open-Minpoint,ProtectStopL[1]-Minpoint));
}
Else if (Low <= Exitlong[1] - Minpoint) //价格低于短周期最低价区间出场
{
Sell(0, Min( Open-Minpoint, Exitlong[1] - 2*Minpoint));
}
}
if( MarketPosition == 1 and h>= firstPrice + SubSet*MinPoint ) {flag=0;}// 减仓
if (flag==0)
// firstPrice = firstPrice + SubSet*MinPoint;
//if(Open >firstPrice) firstPrice = Open;
{ sell(lots1,firstPrice+SubSet*MinPoint-2*Minpoint);flag=flag+1;Commentary("flag1="+text(flag)); }
End
|
|