量化交易策略
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
//------------------------------------------------------------------------
// 简称: treesp
// 名称: treesp
// 类别: 公式应用
// 类型: 用户应用
// 输出:
//------------------------------------------------------------------------
Params
Numeric Lots(1);
Numeric Pcnt(0.6); //止损参数
Numeric MinERLength(20);
Numeric MaxERLength(32);
Numeric StartTime(920);
Numeric Endtime(1430);
Numeric Entrypcnt(5.90); //进场幅度
Numeric X(35); //趋势强度确认参数
Numeric jumppcnt(0.60); //跳空幅度
Numeric EntryAgainRate(0.5); //再入场比例
Numeric TrailStartPct(2); //启动止盈幅度
Numeric TrailPct(50); //保留利润幅度
Vars
NumericSeries ERLength(32);
Numeric Myprice;
NumericSeries ER;
NumericSeries BPoint;
NumericSeries SPoint;
NumericSeries LastProfit;
BoolSeries Strailon(False);
BoolSeries Ltrailon(False);
NumericSeries Newsstop;
NumericSeries Newlstop;
NumericSeries Sstop;
NumericSeries Lstop;
NumericSeries DayOpen;
NumericSeries LValue;
NumericSeries SValue;
NumericSeries LTradeCount;
NumericSeries STradeCount;
NumericSeries LEntryBand1;
NumericSeries SEntryBand1;
Numeric slip;
NumericSeries HigherAfterEntry;
NumericSeries LowerAfterEntry;
Begin
LEntryBand1 = HigherAfterEntry + Open*EntryAgainRate/100;
SEntryBand1 = LowerAfterEntry - Open*EntryAgainRate/100;
If(Date != Date[1])
{
LTradeCount = 0;
STradeCount = 0;
}Else
{
LTradeCount = LTradeCount[1];
STradeCount = STradeCount[1];
}
if(currentbar==0||date!=date[1]) //控制单日最大亏损次数为2次
{
DayOpen = open;
}
if(Date!=Date[1])
{//跳空的时候进场相对其他时候快一点
If(Abs(Open-Close[1])/Close[1]>jumppcnt/100)
{
ERLength=MinERLength;
}Else
{
ERLength=MaxERLength;
}
}
Commentary("ERLength"+Text(ERLength));
BPoint = Abs( Close - Close[ERLength] );
SPoint = Summation( Abs( Close - Close[1] ), ERLength );
ER=BPoint/SPoint;
//====================止损================================
Myprice=EntryPrice*(1-Pcnt/100);
If(MarketPosition==1 && low<=Myprice && BarsSinceEntry>0 && High<>Low )
{
Myprice=Min(open,EntryPrice*(1-Pcnt/100));
Sell(0, Myprice);
Commentary("做多止损");
}
Myprice=EntryPrice*(1+Pcnt/100);
If(MarketPosition==-1 && High>=Myprice && BarsSinceEntry>0 && High<>Low )
{
Myprice=Max(open,EntryPrice*(1+Pcnt/100));
BuyToCover(0, Myprice);
Commentary("做空止损");
}
//=========================收盘平仓=========================
If(MarketPosition==1 && 10000*Time>=1455 )
{
Myprice=open;
Sell(0,Myprice);
Commentary("收盘平仓");
}
If(MarketPosition==-1 && 10000*Time>=1455 )
{
Myprice=Open;
BuyToCover(0,MyPrice);
Commentary("收盘平仓");
}
//============================回撤止盈+
盈利不足时间离场====================
If(MarketPosition==-1)
{
LastProfit=(EntryPrice-C[1])*100/EntryPrice;
If(EntryPrice-Low>=TrailStartPct*EntryPrice/100)
{
STrailOn=True;
}
If(STrailOn)
{
NewSStop=EntryPrice-TrailPct*(EntryPrice-Low)/100;
SStop=Min(SStop,NewSStop);
Commentary("STrailOn is True");
}
If(BarsSinceEntry>0 And High>=Sstop[1] && High<>Low )
{
MyPrice=Max(Open,SStop[1]);
BuyToCover(0,Myprice);
Commentary("回撤平仓");
}
}
If(MarketPosition==1)
{
LastProfit=(Close[1]-EntryPrice)*100/EntryPrice;
If(High-EntryPrice>=TrailStartPct*EntryPrice/100)
{
LTrailOn=true;
}
If(LTrailOn)
{
NewLStop=EntryPrice+TrailPct*(High-EntryPrice)/100;
LStop=Max(LStop,NewLStop);
Commentary("LTrailOn is True");
}
If(BarsSinceEntry>0 And Low<=LStop[1] && High<>Low )
{
MyPrice=Min(Open,LStop[1]);
Sell(0,myprice);
Commentary("回撤平仓");
}
}
//===============================开仓=======================================
LValue=DayOpen+Close[1]*Entrypcnt/1000;
SValue=DayOpen-Close[1]*Entrypcnt/1000;
If( LTradeCount == 0 &&MarketPosition==0 && 10000*Time
&& Close[2]>Close[3] && High>=LValue
&& (Close[1] - Close[ERLength+1])>0 && ER[1]>X/100 and High>=High[1] )
{
Myprice = Max(Open,Max(high[1],LValue));
Buy(lots,myprice);
LTradeCount = LTradeCount + 1;
LTrailOn=False;
LStop=0;
}
If(STradeCount == 0 && MarketPosition==0 && 10000*Time
&& Close[2]
{
Myprice = Min(Open,Min(SValue,Low[1]));
SellShort(lots,myprice);
STradeCount = STradeCount + 1;
Strailon=False;
Sstop=Power(10, 10);
}
//------------------------------------------------------------------------------------------------
//记录入场后的最高价和最低价
//------------------------------------------------------------------------------------------------
If(MarketPosition == 1 && BarsSinceentry == 0)
{
HigherAfterEntry = Max(MyPrice, Close);
LowerAfterEntry = LowerAfterEntry[1];
}else If(MarketPosition == -1 && BarsSinceentry == 0)
{
LowerAfterEntry = Min(MyPrice, Close);
HigherAfterEntry = HigherAfterEntry[1];
}
else if((MarketPosition != 0 && BarsSinceentry >= 1))
{
HigherAfterEntry = Max(HigherAfterEntry[1], Close[1]);
LowerAfterEntry = Min(LowerAfterEntry[1], Close[1]);
}
//------------------------------------------------------------------------------------------------
//再入场
//------------------------------------------------------------------------------------------------
//多头再次入场
If(LTradeCount > 0 && MarketPosition==0 && 10000*time<=1430&
&10000*time>=920)
{
If(High > LEntryBand1 And LTradeCount < 2)
{
MyPrice = Max(Open, LEntryBand1);
Buy(1, MyPrice);
LTradeCount = LTradeCount + 1;
LTrailOn=False;
LStop=0;
Commentary("再次做多");
}
}
//空头再次入场
If(STradeCount > 0 && MarketPosition==0 && 10000*time<=1430&&10000*time>=920)
{
If(Low < SEntryBand1 And STradeCount < 2)
{
MyPrice = Min(Open, SEntryBand1);
SellShort(1, MyPrice);
STradeCount = STradeCount + 1;
Strailon=False;
Sstop=Power(10, 10);
Commentary("再次做空");
}
}
End
//------------------------------------------------------------------------
// 编译版本 GS2010.12.08
// 用户版本 2014/03/28 16:49
// 版权所有 zsqh16011550
// 更改声明 TradeBlazer Software保留对TradeBlazer平台
// 每一版本的TrabeBlazer公式修改和重写的权利
//------------------------------------------------------------------------