開拓者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 進行 有償 編寫!(不貴!點擊查看價格!)
相關文章
-
沒有相關內容