|
//交易策略
//关键点:浮动止损策略的运用
//突破今天开盘价+昨日波幅的10%,做多;
//跌破今天开盘价-昨日波幅的10%,做空
//多单时,从开仓后的最高点回落10%,平多。
//空单时,从开仓后的最低点上涨10%, 平空。
Params
Numeric EnryRate(0.1); //今日涨幅超过上日波动率*EntrRate是,建仓
Numeric ZhiSunPercnt(0.1); //浮动止损幅度
Numeric LeaveTime(0.145900); //离场时间
GlobalVars
Numeric Maxprice(0);
Numeric MinPrice(0);
Integer lastDate(0);
Begin
if(BarStatus == 2) Return;
Numeric lastDayDiff = HighD(1) - LowD(1); //昨日波幅
Numeric Line1 = OpenD(0) + lastDayDiff * EnryRate; //上轨
Numeric Line2 = OpenD(0) - lastDayDiff * EnryRate; //下轨
Numeric TodayOpen = OpenD(0);
PlotNumeric("BuyLine",Line1,0,RGB(255,50,50));
PlotNumeric("SellLine",Line2,0,RGB(50,255,50));
PlotNumeric("TodayOpen",TodayOpen,0,RGB(0,0,255));
if(Date != lastDate)
{ //新的一天开始
lastDate = Date;
Maxprice = Close;
MinPrice = Close;
}
if(MarketPosition ==0) //如果持平,且今天还没有开仓
{
if(Close > Line1 && CurrentTime<LeaveTime)
{
//突破今天开盘价+昨日波幅的10%,做多;
Buy(1,Q_AskPrice);
Maxprice = Close;
MinPrice = Close;
}
Else if(Close < Line2 && CurrentTime<LeaveTime)
{
//跌破今天开盘价-昨日波幅的10%,做空
SellShort(1,Q_BidPrice);
Maxprice = Close;
MinPrice = Close;
}
}
Else
{
Maxprice = Max(Maxprice,High);
MinPrice = Min(MinPrice,Low);
Print("Close:"+Text(Close) + "MinPrice:" + Text(MinPrice));
if(MarketPosition == 1)
{
//多单时,从最高点回落10%,平多
if( Close<Maxprice && abs( (Maxprice-Close)/(Maxprice-TodayOpen) ) > ZhiSunPercnt)
{
Sell(0,Q_BidPrice);
PlotText(Close,"止损");
}
}
Else if(MarketPosition == -1)
{
//空单时,从最低点上涨10%,平空
if( Close>MinPrice && abs( (Close-MinPrice)/(TodayOpen-MinPrice) )> ZhiSunPercnt)
{
BuyToCover(0,Q_AskPrice);
PlotText(Close,"止损");
}
}
}
//到达最后时间,离场
if(CurrentTime > LeaveTime)
{
if(MarketPosition == 1)
{
Sell(0,Q_BidPrice);
PlotText(Close,"离场");
}
Else if(MarketPosition == -1)
{
BuyToCover(0,Q_AskPrice);
PlotText(Close,"离场");
}
}
End
[attachimg]28811[/attachimg]
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册入住
x
|