- 精华
- 1
- 在线时间
- 277 小时
- UID
- 42516
- 积分
- 1239
- 帖子
- 264
- 阅读权限
- 60
- 注册时间
- 2011-5-25
- 最后登录
- 2014-9-23
- 精华
- 1
- UID
- 42516
- 积分
- 1239
- 帖子
- 264
- 主题
- 31
- 阅读权限
- 60
- 注册时间
- 2011-5-25
- 最后登录
- 2014-9-23
|
本帖最后由 rookies 于 2012-7-20 21:27 编辑
日内加入止损和动态止盈
Params
Numeric PercentOfRange(0.5);
Numeric ExitOnCloseMins(14.50);
Numeric MinRange(0.002);
Numeric Lots(1);
Numeric StopPointUpper(1); //多头止损系数
Numeric StopPointLower(1); //空头止损系数
Numeric TakeStart(5); //动态浮盈系数
Numeric TakeStop(1); //动态止损系数
Vars
Numeric MyExitPrice;
Numeric DayOpen;
Numeric preDayRange;
Numeric UpperBand;
Numeric LowerBand;
Numeric MyPrice;
Numeric StopLine;
NumericSeries HigherAfterEntry;
NumericSeries LowerAfterEntry;
Begin
DayOpen = OpenD(0);
preDayRange = HighD(1)-LowD(1);
PreDayRange = Max(PreDayRange,DayOpen*MinRange);
UpperBand = DayOpen+PreDayRange*PercentOfRange;
LowerBand = DayOpen-PreDayRange*PercentOfRange;
PlotNumeric("UpperBand",UpperBand);
PlotNumeric("LowerBand",LowerBand);
If(MarketPosition!=1 && High>=UpperBand && Time<ExitOnCloseMins/100)
{
MyPrice = Max(UpperBand,Open);
Buy(Lots,MyPrice);
Return;
}
If(MarketPosition!=-1 && Low<=LowerBand &&Time<ExitOnCloseMins/100)
{
MyPrice = Min(LowerBand,Open);
SellShort(Lots,MyPrice);
Return;
}
}
//动态止损开始
If(MarketPosition<>0 && BarsSinceEntry==1)
{
HigherAfterEntry=AvgEntryPrice;
LowerAfterEntry=AvgEntryPrice;
}
Else If(BarsSinceEntry>1)
{
HigherAfterEntry=Max(HigherAfterEntry,High[1]);
LowerAfterEntry=Min(LowerAfterEntry,Low[1]);
}
If(MarketPosition==1)
{
If(HigherAfterEntry>=AvgEntryPrice+DayOpen*TakeStart*0.01)
{
StopLine=HigherAfterEntry-DayOpen*TakeStop*0.01;
}
Else
{
StopLine=UpperBand-DayOpen*StopPointUpper*0.01;
}
If(Low<=StopLine)
{
MyExitPrice=Min(StopLine,Open);
Sell(Lots,MyExitPrice);
}
}
If(MarketPosition==-1)
{
If(LowerAfterEntry<=AvgEntryPrice-DayOpen*TakeStart*0.01)
{
StopLine=LowerAfterEntry+DayOpen*TakeStop*0.01;
}
Else
{
StopLine=LowerBand+DayOpen*StopPointLower*0.01;
}
If(High>=StopLine)
{
MyExitPrice=Max(StopLine,Open);
BuyToCover(Lots,MyExitPrice);
}
}
If(Time==0.145500 && /*CurrentTime>0.145800 &&*/ MarketPosition<>0)
{
Sell(0,Close);
BuyToCover(0,Close);
}
End |
|