- 精华
- 0
- 在线时间
- 925 小时
- UID
- 4647
- 积分
- 1403
- 帖子
- 432
- 阅读权限
- 60
- 注册时间
- 2009-6-16
- 最后登录
- 2019-10-27
- 精华
- 0
- UID
- 4647
- 积分
- 1403
- 帖子
- 432
- 主题
- 31
- 阅读权限
- 60
- 注册时间
- 2009-6-16
- 最后登录
- 2019-10-27
|
花了一点时间学习了穿堂风老兄的版本,针对当前BAR内开平仓的问题,做了几处修改,基本上能运行了,优化后模型在IF000上能够获利。
现将修改后的贴出来供大家参考。再次感谢穿堂风兄,让我学到不少东西!
//------------------------------------------------------------------------
// 简称: atest0_
// 名称: 陈总课件_穿堂风修改_liq77再次修改
// 类别: 公式应用
// 类型: 用户应用
// 输出:
//------------------------------------------------------------------------
Params
Numeric Length1(10);
Numeric Length2(20);
Numeric Lots(1);
Numeric InitialStop(20); // 初始止损(千分之N)
Numeric BreakEvenStop(30); // 保本止损(千分之N)
Numeric TrailingStop(50); // 追踪止损(千分之N)
Vars
NumericSeries MA1;
NumericSeries MA2;
BoolSeries condBuy(false);
BoolSeries condSell(false);
Numeric MinPoint;
Numeric MyPrice;
NumericSeries HigherAfterEntry;
NumericSeries LowerAfterEntry;
BoolSeries bLongStoped(false);
BoolSeries bShortStoped(false);
Numeric StopLine;
Numeric StopLine1;
Numeric StopLine2;
Numeric StopLine3;
String strDate;
String strTime;
String TRADENAME;
Begin
if(condBuy==false and condSell==false )
{
condBuy=condBuy[1];
condSell=condSell[1];
}
if(BarStatus>0)
{
bLongStoped=bLongStoped[1]; //多头止损情况
bShortStoped=bShortStoped[1]; //空头止损情况
}
MinPoint=MinMove * PriceScale;
MA1=AverageFC(Close,Length1);
MA2=AverageFC(Close,Length2);
condBuy=CrossOver(MA1,MA2);
condSell=CrossUnder(MA1,MA2);
If(MarketPosition!=1 and condBuy[1]==true and bLongStoped==False)//初次进场做多
{
Buy(Lots,Open);
HigherAfterEntry=Open;
LowerAfterEntry=Open;
bLongStoped=False;//重置标志
bShortStoped=False;//重置标志
Commentary("Buy Firsttime at "+text(Open));
Commentary("HAE="+TEXT(HigherAfterEntry)+" LAE="+Text(LowerAfterEntry));
Commentary("bLongStoped="+IIFString(bLongStoped,"TRUE","FALSE"));
Commentary("bShortStoped="+IIFString(bShortStoped,"TRUE","FALSE"));
}
If(MarketPosition!=-1 and condSell[1]==true and bShortStoped==False)//初次进场做空
{
SellShort(lots,Open);
HigherAfterEntry=Open;
LowerAfterEntry=Open;
bLongStoped=False;//重置标志
bShortStoped=False;//重置标志
Commentary("SellShort Firsttime at "+text(Open));
Commentary("HAE="+TEXT(HigherAfterEntry)+" LAE="+Text(LowerAfterEntry));
Commentary("bLongStoped="+IIFString(bLongStoped,"TRUE","FALSE"));
Commentary("bShortStoped="+IIFString(bShortStoped,"TRUE","FALSE"));
}
If(BarsSinceEntry>=1)
{
HigherAfterEntry=Max(HigherAfterEntry[1],High[1]);
LowerAfterEntry=Min(LowerAfterEntry[1],Low[1]);
}
// Else
//{
// HigherAfterEntry=HigherAfterEntry[1];
// LowerAfterEntry=LowerAfterEntry[1];
// }
If(MarketPosition==1)//多头止损部分的代码
{
StopLine=EntryPrice * (1-InitialStop/1000);
If (HigherAfterEntry>=EntryPrice*(1+BreakEvenStop/1000))
{
StopLine=EntryPrice;
}
If (StopLine<HigherAfterEntry*(1-TrailingStop/1000))
{
StopLine=HigherAfterEntry*(1-TrailingStop/1000);
}
Commentary("止损价:"+Text(StopLine));
If(Low<=StopLine)// 止损触发
{
MyPrice=StopLine;
If(Open<MyPrice)
{
MyPrice=Open;
}
Sell(Lots,MyPrice);
bLongStoped=True; // 止损后设置标志
Commentary("Long Position Stoped at "+text(MyPrice));
}
}
If(MarketPosition==-1)//空头止损部分的代码
{
StopLine=EntryPrice*(1+InitialStop/1000);
If(LowerAfterEntry<=EntryPrice*(1-BreakEvenStop/1000))
StopLine=EntryPrice;
If(StopLine<LowerAfterEntry*(1+TrailingStop/1000))
StopLine=LowerAfterEntry*(1+TrailingStop/1000);
Commentary("止损价:"+Text(StopLine));
If(High>=StopLine)// 止损触发
{
MyPrice=StopLine;
If(Open>MyPrice)
{
MyPrice=Open;
}
BuyToCover(Lots,MyPrice);
bShortStoped=True; // 止损后设置标志
Commentary("Short Position Stoped at "+text(MyPrice));
}
}
IF(bLongStoped AND MarketPosition==0 AND H>HigherAfterEntry)//二次进场做多
{
MyPrice=HigherAfterEntry+MinPoint;
If(Open>MyPrice)
{
MyPrice=Open;
}
Buy(Lots,MyPrice);
bLongStoped=False;
HigherAfterEntry=AvgEntryPrice;
LowerAfterEntry=HigherAfterEntry;
Commentary("Buy Secondtime at "+text(Open));
Commentary("HAE="+TEXT(HigherAfterEntry)+" LAE="+Text(LowerAfterEntry));
Commentary("bLongStoped="+IIFString(bLongStoped,"TRUE","FALSE"));
Commentary("bShortStoped="+IIFString(bShortStoped,"TRUE","FALSE"));
Return;
}
If(bShortStoped AND MarketPosition==0 AND L<LowerAfterEntry)//二次进场做空
{
MyPrice=LowerAfterEntry - MinPoint;
If(Open<MyPrice)
{
MyPrice = Open;
}
SellShort(Lots,MyPrice);
bShortStoped=False;
LowerAfterEntry=AvgEntryPrice;
HigherAfterEntry=LowerAfterEntry;
Commentary("SellShort Secondtime at "+text(Open));
Commentary("HAE="+TEXT(HigherAfterEntry)+" LAE="+Text(LowerAfterEntry));
Commentary("bLongStoped="+IIFString(bLongStoped,"TRUE","FALSE"));
Commentary("bShortStoped="+IIFString(bShortStoped,"TRUE","FALSE"));
Return;
}
End
//------------------------------------------------------------------------
// 编译版本 GS2010.12.08
// 用户版本 2012/05/05 09:24
// 版权所有
// 更改声明 TradeBlazer Software保留对TradeBlazer平台
// 每一版本的TrabeBlazer公式修改和重写的权利
//------------------------------------------------------------------------ |
|