- 精华
- 0
- 在线时间
- 183 小时
- UID
- 2423
- 积分
- 402
- 帖子
- 17
- 阅读权限
- 50
- 注册时间
- 2008-9-22
- 最后登录
- 2019-3-30
- 精华
- 0
- UID
- 2423
- 积分
- 402
- 帖子
- 17
- 主题
- 6
- 阅读权限
- 50
- 注册时间
- 2008-9-22
- 最后登录
- 2019-3-30
|
试着写了一下,没有用穿越模式,可能效果有些不同
有不对之处请高手指出!
Params
Numeric avgLength(40);
Numeric atrLength(40);
Numeric LongLots(1); // 开多仓的手数
Numeric ShortLots(1); // 开空仓的手数
Vars
Numeric MinPoint; // 最小变动单位
NumericSeries upBand(0);
NumericSeries dnBand(0);
NumericSeries liquidPoint(0);
NumericSeries movAvgVal(0);
Numeric MyPrice; // 临时价格
Begin
MinPoint = MinMove*PriceScale;
movAvgVal = Average((High + Low + Close)/3,avgLength);
upBand = movAvgVal+AvgTrueRange(atrLength);
dnBand = movAvgVal-AvgTrueRange(atrLength);
liquidPoint = Average(((High + Low + Close)/3),40);
If(MarketPosition!=1 && movAvgVal>movAvgVal[1]&&High>=upBand+minpoint)
{ MyPrice = upBand+minpoint;
If(Open > MyPrice) MyPrice = Open;
Buy(LongLots,MyPrice);
}
else If(MarketPosition!=-1 && movAvgVal<movAvgVal[1]&&Low<=dnBand-minpoint)
{ MyPrice = dnBand-minpoint;
If(Open < MyPrice) MyPrice = Open;
SellShort(ShortLots,MyPrice);
}
//持仓处理
If(MarketPosition == 1 )
{If(Low <= liquidPoint) // 跟踪止损退出
{
MyPrice =liquidPoint;
If(Open < MyPrice) MyPrice = Open;
Sell(LongLots,MyPrice);
Return;
}
} Else If(MarketPosition == -1)
{
If( High >= liquidPoint) // 跟踪止损退出
{
MyPrice = liquidPoint;
If(Open > MyPrice) MyPrice = Open;
BuyToCover(ShortLots,MyPrice);
Return;
}
}
End |
|