- 精华
- 0
- 在线时间
- 138 小时
- UID
- 117953
- 积分
- 126
- 帖子
- 66
- 阅读权限
- 40
- 注册时间
- 2013-4-10
- 最后登录
- 2016-4-22
- 精华
- 0
- UID
- 117953
- 积分
- 126
- 帖子
- 66
- 主题
- 10
- 阅读权限
- 40
- 注册时间
- 2013-4-10
- 最后登录
- 2016-4-22
|
stewen.net 发表于 2012-8-31 21:05
NEXTOPEN 和 SETEXITONCLOSE 是独立的函数吧,能把代码贴出来吗?
刚才复制后简单修改了下代码,发现里面是有问题的,这个代码止损全靠开多单的时候平空单,或者开空单的时候触发平多单,下面的止损和止盈根本没用。我希望版主们能再修改下,这其实是比较简单的模板,虽然简单,但是像我这样的新手极其希望有一篇好的例文能参考参考。
Params
Numeric shortLength(15);
Numeric longLength(90);
Numeric StopPoint(100);
Numeric ProfitPoint(300);
Vars
NumericSeries AvgClose1;
NumericSeries AvgClose2;
Numeric lots(1);
Numeric myExitPrice;
Begin
AvgClose1 = AverageFC(Close,shortLength); // 短均线
AvgClose2 = AverageFC(Close,longLength); // 长均线
If(Time > 0.0910 && Time < 0.1450) // 时间限制
{
If(MarketPosition !=1 && CrossOver(AvgClose1,AvgClose2)) // 当前无持仓或有空仓,才可以开多(会自动平空)
{
Buy(lots,open); // K线走完才发单
}
If(MarketPosition !=-1 && CrossUnder(AvgClose1,AvgClose2))// 当前无持仓或有多仓,才可以开空(会自动平多)
{
SellShort(lots,open);// K线走完才发单
}
}
// 止损
If(MarketPosition == 1)
{
If(Low < AvgEntryPrice - StopPoint * MinMove*PriceScale)
{
myExitPrice = AvgEntryPrice - (StopPoint+1) * MinMove*PriceScale;
myExitPrice = max(low,myExitPrice);
Sell(lots,myExitPrice);
}
}Else If(MarketPosition == -1)
{
If(High > AvgEntryPrice + StopPoint * MinMove*PriceScale)
{
myExitPrice = AvgEntryPrice + (StopPoint+1) * MinMove*PriceScale;
myExitPrice = min(high,myExitPrice);
BuyToCover(lots,myExitPrice);
}
}
// 止赢
If(MarketPosition == 1)
{
If(High > AvgEntryPrice + ProfitPoint * MinMove*PriceScale)
{
myExitPrice = AvgEntryPrice + ProfitPoint * MinMove*PriceScale;
Sell(lots,myExitPrice);
}
}Else If(MarketPosition == -1)
{
If( Low < AvgEntryPrice - ProfitPoint * MinMove*PriceScale)
{
myExitPrice = AvgEntryPrice - ProfitPoint* MinMove*PriceScale;
BuyToCover(lots,myExitPrice);
}
}
If(BarStatus == 2) // 收盘平仓
{
If(Time >= 0.1455 && MarketPosition != 0)
{
Sell;
BuyToCover;
}
}
End
我只是把nextopen换成了open,setexitonclose删掉了。这样才能完成编译。唯一有点疑惑的原来的setexitonclose原来是什么函数,会不会就是因为删除了它导致止损止损没用。 |
|