- 精华
- 0
- 在线时间
- 93 小时
- UID
- 11216
- 积分
- 254
- 帖子
- 35
- 阅读权限
- 50
- 注册时间
- 2010-5-30
- 最后登录
- 2010-11-18
- 精华
- 0
- UID
- 11216
- 积分
- 254
- 帖子
- 35
- 主题
- 6
- 阅读权限
- 50
- 注册时间
- 2010-5-30
- 最后登录
- 2010-11-18
|
本帖最后由 paozi84 于 2010-8-7 23:05 编辑
大概框架就是这样,但是为什么一调用程序了以后,在10点之前每个BAR上都会有买点?我在开仓位置是明明设置了Time>0.0915+nMins*0.0001。请高手指教!
params
Numeric nMins(45);
Vars
NumericSeries HighestOfMins;
NumericSeries MidOfMins;
NumericSeries lowestOfMins;
Numeric myprice;
Numericseries Higherafterentry;
Numericseries Lowerafterentry;
Numeric HV(0);
Numeric tstop(0);
BoolSeries bLongTrailingStoped;//多头止损/止盈标记
BoolSeries bshortTrailingStoped;//多头止损/止盈标记
Begin
If(Date != Date[1])
{
HighestOfMins = High;
lowestOfMins = Low;
}Else If(Time < 0.0915+nMins*0.0001)
{
HighestOfMins = max(high,HighestOfMins[1]);
lowestOfMins = min(Low,lowestOfMins[1]);
}Else
{
HighestOfMins = HighestOfMins[1];
lowestOfMins = lowestOfMins[1];
}
MidOfMins=(HighestOfMins+lowestOfMins)/2;
If(BarsSinceEntry == 1)
{
HigherAfterEntry = AvgEntryPrice;
LowerAfterEntry = HigherAfterEntry;
}
Else If(BarsSinceEntry > 1)
{
HigherAfterEntry = Max(HigherAfterEntry[1],High[1]);
LowerAfterEntry = Min(LowerAfterEntry[1],Low[1]);
}
Commentary("HigherAfterEntry="+Text(HigherAfterEntry));
Commentary("LowerAfterEntry="+Text(LowerAfterEntry));
If(MarketPosition==1)
HV=HigherAfterEntry-EntryPrice ;
If(MarketPosition==-1)
HV=Abs(LowerAfterEntry-EntryPrice);
If(BarStatus > 0)
{
bLongTrailingStoped = bLongTrailingStoped[1];
bShortTrailingStoped = bShortTrailingStoped[1];
}
Commentary("bLongTrailingStoped="+IIFString(bLongTrailingStoped,"True","False"));
Commentary("bShortTrailingStoped="+IIFString(bShortTrailingStoped,"True","False"));
//------------------开仓功能代码----------------------------------------------
If(MarketPosition!=1 && High>HighestOfMins && Time>0.0915+nMins*0.0001)
{
MyPrice = HighestOfMins;
If(Open > HighestOfMins) MyPrice = Open;
Buy(1,MyPrice);
}
If(MarketPosition!=-1 && low<lowestOfMins && Time>0.0915+nMins*0.0001)
{
MyPrice = lowestOfMins;
If(Open < lowestOfMins ) MyPrice = Open;
SellShort(1,MyPrice);
}
//------------------止损平仓功能代码----------------------------------------------
If(MarketPosition==1 && low<= MidOfMins)
{
MyPrice = MidOfMins;
If(Open < MidOfMins ) MyPrice = Open;
Sell(1,MyPrice);
}
If(MarketPosition==-1 && high>= MidOfMins)
{
MyPrice = MidOfMins;
If(Open > MidOfMins ) MyPrice = Open;
BuyToCover(1,MyPrice);
}
//------------------追踪止盈平仓功能代码----------------------------------------------
If(MarketPosition==1 && 10<=HV&&HV<20);
{ Tstop=5;
If(Low <= HigherAfterEntry - TStop);
{
MyPrice = HigherAfterEntry - TStop;
If(Open < MyPrice) MyPrice = Open;
Sell(1,MyPrice);
bLongTrailingStoped=True;
}
}
If(MarketPosition==-1 && 10<=HV && HV<20)
{ Tstop=5;
If(High>= HigherAfterEntry + TStop);
{
MyPrice = HigherAfterEntry + TStop;
If(Open >MyPrice) MyPrice = Open;
BuyToCover(1,MyPrice);
bshortTrailingStoped=True;
}
}
//------------------再次开仓功能----------------------------------------------
If(bLongTrailingStoped && MarketPosition==0 && High > HigherAfterEntry)
{
MyPrice = HigherAfterEntry ;
If(Open > MyPrice) MyPrice = Open;
Buy(1,MyPrice);
bLongTrailingStoped = False;
}
If(bShortTrailingStoped && MarketPosition==0 && Low < LowerAfterEntry)
{
MyPrice = LowerAfterEntry ;
If(Open < MyPrice) MyPrice = Open;
SellShort(1,MyPrice);
bShortTrailingStoped= False;
}
End
|
附件: 你需要登录才可以下载或查看附件。没有帐号?注册
|