开拓者TB的RangeBreak交易模型源码[开拓者公式]
- 咨询内容: 本帖最后由 rookies 于 2012-7-20 21:23 编辑
日内效果不如隔日来得好
Params
Numeric PercentOfRange(0.5); //突破系数
Numeric ExitOnCloseMins(14.55); //最后交易时间
Numeric MinRange(0.002); //开盘价的百分比
Numeric Lots(1); //开仓量
Vars
Numeric MyExitPrice;
Numeric DayOpen;
Numeric preDayRange;
Numeric UpperBand; //上轨
Numeric LowerBand; //下轨
Numeric MyPrice;
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) //开多条件 价格高于上轨,时间小于0.145500
{
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==1 && Low<LowerBand) //多头中如果下破下轨止损
{
MyExitPrice=Min(Open,LowerBand);
Sell(Lots,MyExitPrice);
Return;
}
If( MarketPosition==-1 && High>UpperBand) //空头中如果上穿上轨止损
{
MyExitPrice=Max(Open,UpperBand);
BuytoCover(Lots,MyExitPrice);
Return;
}
End
- TB技术人员: 本帖最后由 rookies 于 2012-7-21 11:25 编辑
隔日情况下,允许二次开仓,可以提高盈利率
Params
Numeric PercentOfRange(0.5);
Numeric ExitOnCloseMins(14.50);
Numeric MinRange(0.002);
Numeric Lots(1);
Numeric StopPointUpper(1);
Numeric StopPointLower(1);
Numeric Length(12);
Numeric TakeStart(0.1);
Numeric TakeStop(0.5);
Vars
Numeric LastTradeMins(14.00);
NumericSeries Ma;
Numeric MyExitPrice;
Numeric DayOpen;
Numeric preDayRange;
Numeric UpperBand;
Numeric LowerBand;
Numeric MyPrice;
Numeric StopLine;
BoolSeries UpperStoped;
BoolSeries LowerStoped;
NumericSeries HigherAfterEntry;
NumericSeries LowerAfterEntry;
String BoolSet;
Begin
Ma=Average(Close,Length);
DayOpen = OpenD(0);
preDayRange = HighD(1)-LowD(1);
PreDayRange = Max(PreDayRange,DayOpen*MinRange);
Commentary("DayOpen="+Text(DayOpen));
Commentary("preDayRange="+Text(preDayRange));
UpperBand = DayOpen+PreDayRange*PercentOfRange;
LowerBand = DayOpen-PreDayRange*PercentOfRange;
Commentary("UpperBand="+Text(DayOpen+PreDayRange*PercentOfRange));
Commentary("UpperBand="+Text(DayOpen-PreDayRange*PercentOfRange));
PlotNumeric("UpperBand",UpperBand);
PlotNumeric("LowerBand",LowerBand);
If(Date!=Date[1])
{
UpperStoped=True;
LowerStoped=True;
}
If(UpperStoped && LowerStoped)
{
If(MarketPosition!=1 && High>=UpperBand && Time<ExitOnCloseMins/100)
{
MyPrice = Max(UpperBand,Open);
Buy(Lots,MyPrice);
UpperStoped=False;
Return;
}
}
If(!UpperStoped)
{
If(MarketPosition!=1 && High>=UpperBand && High>=HigherAfterEntry && Time<ExitOnCloseMins/100)
{
MyPrice = Max(UpperBand,Open);
MyPrice = Max(HigherAfterEntry,MyPrice);
Buy(Lots,MyPrice);
PlotString("二次建仓","二次建仓");
Return;
}
If(LowerStoped && MarketPosition==1 && Low<=LowerBand && Time<ExitOnCloseMins/100)
{
MyPrice = Min(LowerBand,Open);
Sell(Lots,MyPrice);
LowerStoped=False;
PlotString("反向建仓","反向建仓");
Return;
}
}
If(UpperStoped && LowerStoped)
{
If(MarketPosition!=-1 && Low<=LowerBand &&Time<ExitOnCloseMins/100)// && Time<=ExitOnCloseMins/100)
{
MyPrice = Min(LowerBand,Open);
SellShort(Lots,MyPrice);
LowerStoped=False;
Return;
}
}
If(!LowerStoped)
{
If(MarketPosition!=-1 && Low<=LowerBand && Low<=LowerAfterEntry &&Time<ExitOnCloseMins/100)
{
MyPrice = Min(LowerBand,Open);
MyPrice = Min(LowerAfterEntry,MyPrice);
SellShort(Lots,MyPrice);
PlotString("二次建仓","二次建仓");
Return;
}
If(UpperStoped && MarketPosition==-1 && High>=UpperBand && Time<ExitOnCloseMins/100)
{
MyPrice = Max(UpperBand,Open);
BuyToCover(Lots,MyPrice);
UpperStoped=False;
PlotString("反向建仓","反向建仓");
Return;
}
}
End
- TB客服: 本帖最后由 rookies 于 2012-7-21 11:14 编辑
应学友要求 加入反向平仓和二次建仓 RU000 5分测试效果如图,如果做得更细一些的话会有更好的效果 15分上效果更好一些
- 网友回复: 本帖最后由 rookies 于 2012-7-21 11:25 编辑
加入动态止盈和止损
Params
Numeric PercentOfRange(0.5);
Numeric ExitOnCloseMins(14.50);
Numeric MinRange(0.002);
Numeric Lots(1);
Numeric StopPointUpper(1);
Numeric StopPointLower(1);
Numeric Length(12);
Numeric TakeStart(0.1);
Numeric TakeStop(0.5);
Vars
Numeric LastTradeMins(14.00);
NumericSeries Ma;
Numeric MyExitPrice;
Numeric DayOpen;
Numeric preDayRange;
Numeric UpperBand;
Numeric LowerBand;
Numeric MyPrice;
Numeric StopLine;
BoolSeries UpperStoped;
BoolSeries LowerStoped;
NumericSeries HigherAfterEntry;
NumericSeries LowerAfterEntry;
String BoolSet;
Begin
Ma=Average(Close,Length);
DayOpen = OpenD(0);
preDayRange = HighD(1)-LowD(1);
PreDayRange = Max(PreDayRange,DayOpen*MinRange);
Commentary("DayOpen="+Text(DayOpen));
Commentary("preDayRange="+Text(preDayRange));
UpperBand = DayOpen+PreDayRange*PercentOfRange;
LowerBand = DayOpen-PreDayRange*PercentOfRange;
Commentary("UpperBand="+Text(DayOpen+PreDayRange*PercentOfRange));
Commentary("UpperBand="+Text(DayOpen-PreDayRange*PercentOfRange));
PlotNumeric("UpperBand",UpperBand);
PlotNumeric("LowerBand",LowerBand);
If(Date!=Date[1])
{
UpperStoped=True;
LowerStoped=True;
}
If(UpperStoped && LowerStoped)
{
If(MarketPosition!=1 && High>=UpperBand && Time<ExitOnCloseMins/100)
{
MyPrice = Max(UpperBand,Open);
Buy(Lots,MyPrice);
UpperStoped=False;
Return;
}
}
If(!UpperStoped)
{
If(MarketPosition!=1 && High>=UpperBand && High>=HigherAfterEntry && Time<ExitOnCloseMins/100)
{
MyPrice = Max(UpperBand,Open);
MyPrice = Max(HigherAfterEntry,MyPrice);
Buy(Lots,MyPrice);
PlotString("二次建仓","二次建仓");
Return;
}
If(LowerStoped && MarketPosition==1 && Low<=LowerBand && Time<ExitOnCloseMins/100)
{
MyPrice = Min(LowerBand,Open);
Sell(Lots,MyPrice);
LowerStoped=False;
PlotString("反向建仓","反向建仓");
Return;
}
}
If(UpperStoped && LowerStoped)
{
If(MarketPosition!=-1 && Low<=LowerBand &&Time<ExitOnCloseMins/100)// && Time<=ExitOnCloseMins/100)
{
MyPrice = Min(LowerBand,Open);
SellShort(Lots,MyPrice);
LowerStoped=False;
Return;
}
}
If(!LowerStoped)
{
If(MarketPosition!=-1 && Low<=LowerBand && Low<=LowerAfterEntry &&Time<ExitOnCloseMins/100)
{
MyPrice = Min(LowerBand,Open);
MyPrice = Min(LowerAfterEntry,MyPrice);
SellShort(Lots,MyPrice);
PlotString("二次建仓","二次建仓");
Return;
}
If(UpperStoped && MarketPosition==-1 && High>=UpperBand && Time<ExitOnCloseMins/100)
{
MyPrice = Max(UpperBand,Open);
BuyToCover(Lots,MyPrice);
UpperStoped=False;
PlotString("反向建仓","反向建仓");
Return;
}
}
If(MarketPosition<>0 && BarsSinceEntry==1)
{
HigherAfterEntry=AvgEntryPrice;
LowerAfterEntry=AvgEntryPrice;
}
Else If(BarsSinceEntry>1)
{
HigherAfterEntry=Max(HigherAfterEntry,High[1]);
LowerAfterEntry=Min(LowerAfterEntry,Low[1]);
}
Commentary("HigherAfterEntry"+Text(HigherAfterEntry));
Commentary("LowerAfterEntry"+Text(LowerAfterEntry));
If(MarketPosition==1)
{
If(HigherAfterEntry>=AvgEntryPrice+DayOpen*TakeStart*0.01)
{
StopLine=HigherAfterEntry-DayOpen*TakeStop*0.01;
Commentary("StopLineHigherAftetEntry"+Text(StopLine));
}
Else
{
StopLine=UpperBand-DayOpen*StopPointUpper*0.01;
Commentary("StopLine"+Text(StopLine));
}
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;
Commentary("StopLineLowerAfterEntry"+Text(StopLine));
}
Else
{
StopLine=LowerBand+DayOpen*StopPointLower*0.01;
Commentary("StopLine"+Text(StopLine));
}
If(High>=StopLine)
{
MyExitPrice=Max(StopLine,Open);
BuyToCover(Lots,MyExitPrice);
}
}
End
- 网友回复:呵呵 沙发 刚准备 周末 研究点模型 你就来发了
有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友
可联系技术人员 QQ: 262069696 进行 有偿 编写!(不贵!点击查看价格!)
相关文章
-
没有相关内容