- 精华
- 0
- 在线时间
- 478 小时
- UID
- 110324
- 积分
- 340
- 帖子
- 257
- 阅读权限
- 50
- 注册时间
- 2012-5-4
- 最后登录
- 2014-12-20
- 精华
- 0
- UID
- 110324
- 积分
- 340
- 帖子
- 257
- 主题
- 51
- 阅读权限
- 50
- 注册时间
- 2012-5-4
- 最后登录
- 2014-12-20
|
小米 发表于 2013-5-21 16:45
应该是你的某个 if( )语句后面无意中加上了” ; “ 分号吧??
去掉分号再编译。 ...
就是这个模型,请小米版主斧正。谢谢
Params
Numeric length1(10);
Numeric length2(20);
Numeric ATRlength(20); //ATR周期
Numeric trailstop(3); //跟踪止损乘数
Numeric lost(1);
Vars
NumericSeries ma1;
NumericSeries ma2;
NumericSeries ATRvalue; //ATR周期内的平均有效值
NumericSeries Highestafterentry; //开仓后出现的最高价
NumericSeries lowestafterentry; //开仓后出现的最低价
Numeric stopline; //跟踪止损设置
Numeric myexitprice;
BoolSeries blongstoped(False); //多头控制再次进仓设置
BoolSeries bshontstoped(False); //空头控制再次进场设置
Begin
ATRvalue=AvgTrueRange(ATRlength);
ma1=AverageFC(close,length1);
ma2=AverageFC(close,length2);
Commentary("ATRvalue="+text(ATRvalue));
PlotNumeric("MA1",MA1);
PlotNumeric("MA2",MA2);
If(!blongstoped And MarketPosition!=1 and ma1[1]>ma2[1])
{
Buy(lost,open);
bshontstoped=false;
}
If(!bshontstoped and MarketPosition<>-1 And ma1[1]<ma2[1])
{
SellShort(lost,open);
blongstoped=False;
}
If(blongstoped and MarketPosition<>1 and High>=Highestafterentry)
{
Buy(lost,max(open,highestafterentry));
blongstoped=false;
}
If(bshontstoped and MarketPosition<>-1 and low<=lowestafterentry)
{
SellShort(lost,Min(open,lowestafterentry));
bshontstoped=False;
}
If(MarketPosition==1 and barssinceentry==0)
highestafterentry=high;
If(MarketPosition==1 and BarsSinceEntry>=1)
highestafterentry=Max(highestafterentry,high);
If(MarketPosition==-1 and BarsSinceEntry==0)
lowestafterentry=low;
If(marketposition==-1 and barssinceentry>=1)
lowestafterentry=Min(lowestafterentry,low);
If(MarketPosition==1 and BarsSinceEntry>=1)
{
stopline=highestafterentry[1]-trailstop*ATRvalue[1];//跟踪止损
If(low<=stopline)
{
myexitprice=Min(open,stopline);
Sell(lost,myexitprice);
blongstoped=True;
Commentary("跟踪止损"+text(myexitprice));
}
}Else if(marketposition==-1 and barssinceentry>=1)
{
stopline=lowestafterentry+trailstop*ATRvalue[1];//跟踪止损
if(high>=stopline)
{
myexitprice=Max(Open,stopline);
BuyToCover(lost,myexitprice);
bshontstoped=True;
Commentary("跟踪止损"+text(myexitprice));
}
}
End |
|