Params
numeric lots(1);
numeric save(20);
numeric holdpoint(0.3);//震荡系数在hold之下的时候判定为震荡才开仓
Vars
Series<Numeric> upline;
Series<Numeric> downline;
Series<Numeric> midline;
Series<Numeric> upline_; // 中间线
Series<Numeric> downline_; //中间线
Series<Numeric> band;
Series<Bool> con1;
Series<Bool> con2;
Series<Numeric> minpoint;
Series<Numeric> avgvlue1;
Series<Numeric> avgvlue2;
Series<Numeric> hold;
Events
OnBar(ArrayRef<Integer> indexs)
{
midline = AverageFC(close,26);
band = StandardDev(close,26,2);
upline = midline + 2*band;
downline =midline -2*band;
PlotNumeric("upline",highest(upline,3));
PlotNumeric("dowmline",lowest(downline,3));
upline_=Highest(upline,3);
downline_=lowest(downline,3);
//过滤掉波动大的行情
avgvlue1=AverageFC(close,30);
avgvlue2=AverageFC(close,60);
hold=Abs(avgvlue1 - avgvlue2)/Close*100;
//开仓条件判断
con1=Close[1]<downline_[1] And close >downline_ And Close>Open;
con2=close[1]>upline_[1] and Close <upline_ and close <Open;
If(MarketPosition<>1 And con1[1] And hold[1]<=holdpoint) //避免未来函数
{
Buy(lots,Open);
Commentary("多单进场");
}
If(MarketPosition <> -1 And con2[1] And hold[1]<=holdpoint) //避免未来函数
{
SellShort(lots,Open);
Commentary("空单进场");
}
If(MarketPosition ==1 and Close[1]<AvgEntryPrice - save*minpoint And BarsSinceEntry>0)
{
Sell(lots,Open);
Commentary("多单止损出场");
}
If(MarketPosition==-1 And Close[1]>AvgEntryPrice + save*minpoint And BarsSinceEntry>0)
{
BuyToCover(lots,Open);
Commentary("空单止损出场");
}
If(MarketPosition==1 and high[1]>=upline)
{
sell(0,Open);
Commentary("多单出线止盈");
}
If(MarketPosition==-1 and low[1]<=downline)
{
BuyToCover(0,Open);
Commentary("空单出现止盈");
}//多单固定止盈
If(MarketPosition==1 And Close[1]>AvgEntryPrice+save*minpoint*1.2 and BarsSinceEntry>0)
{
sell(0,Open);
Commentary("多单止盈出场");
}
If(MarketPosition==-1 And Close[1]<AvgEntryPrice-save*minpoint*1.2 and BarsSinceEntry>0)
{
BuyToCover(0,Open);
Commentary("空单止盈出场");
}
if(MarketPosition==1 And hold[1]>0.4 and BarsSinceEntry>0 and close[1]<AvgEntryPrice)
{
sell(lots,Open);
Commentary("波动过大,目前亏损状态出场");
}
if(MarketPosition==-1 And hold[1]>0.4 and BarsSinceEntry>0 and close[1]>AvgEntryPrice)
{
BuyToCover(lots,Open);
Commentary("波动过大,目前亏损状态出场");
}
你好,楼主,可以加个V吗?我有几个策略可以交换学习吗?
原来如此,万分感谢。
你还知道感谢啊 不错啊
少一个大括号,也就是说大括号不匹配,,在最后加一个大括号