|
50金币
本帖最后由 湖北网迅 于 2012-10-1 07:57 编辑
这几天看了一本书,里面用TB设计的一个交易系统个人很看好,但是在编译时出错,错误是什么C0012,小括号匹配不正确。不知道什么原因。想请高人帮忙改成文华公式或者用TB编好?谢谢。书我上传,公式我贴出来。谢谢大家。
其实质就是一个短线上穿下穿长线时操作,但加了一个止损功能。
Params
Numeric Length1(5); //线一标准
Numeric Length2(21); //线二标准
Numeric TrailingStop(100);
Numeric Lots(1);
Numeric InitialStop(20); // 初始止损(千分之N)
Numeric BreakEvenStop(30); // 保本止损(千分之N)
Numeric TrailingStop(50); // 追踪止损(千分之N)
Numeric MinPoint;
Numeric MyPrice;
Vars
NumericSeries MA1;
NumericSeries MA2;
BoolSeries condBuy(false);
BoolSeries condSell(false);
NumericSeries HigherAfterEntry;
NumericSeries LowerAfterEntry;
NumericSeries HigherAfterEntry; // 多头盈利峰值价
NumericSeries LowerAfterEntry; // 空头盈利峰值价
Begin
If(BarsSinceEntry >= 1)
{
HigherAfterEntry = Max(HigherAfterEntry[1],High[1]);
LowerAfterEntry = Min(LowerAfterEntry[1],Low[1]);
}
MinPoint = MinMove * PriceScale;
MA1 = AverageFC(Close,Length1);
MA2 = AverageFC(Close,Length2);
condBuy = CrossOver(MA1,MA2);
condSell = CrossUnder(MA1,MA2);
If (condBuy[1]==true)
{
Buy(Lots,Open);
HigherAfterEntry = Open;
LowerAfterEntry = HigherAfterEntry;
}
If (condSell[1]==true)
{
SellShort(lots,Open);
HigherAfterEntry = Open;
LowerAfterEntry = Open;
}
Commentary("HigherAfterEntry="+Text(HigherAfterEntry));
Commentary("LowerAfterEntry="+Text(LowerAfterEntry));
If(MarketPosition==1)
{
If(Low <= HigherAfterEntry * (1 – TrailingStop/1000))
{
MyPrice = HigherAfterEntry * (1 – TrailingStop/1000);
If(Open < MyPrice) MyPrice = Open;
Sell(Lots,MyPrice);
}
}Else If(MarketPosition == -1)
{
If(High >= (LowerAfterEntry * (1 + TrailingStop / 1000)))
{
MyPrice = LowerAfterEntry * (1 + TrailingStop / 1000);
If(Open > MyPrice) MyPrice = Open;
BuyToCover(Lots,MyPrice);
}
}
End
|
|