|
//15分钟突破
//两个参数:
//1。运行在1分钟线上,就设置为 15;运行在5分钟线上,就设置为3
//2.离场时间,股指:0.1529,其他0.1459
//------------------------------------------------------------------------
// 类别: 交易指令
// 类型: 用户应用
//------------------------------------------------------------------------
Params
Integer StaticsBarCount(3); //统计阶段K线根数
Numeric LeaveTime(0.1459); //离场时间
GlobalVars
Numeric Min15High(0); //开盘15分钟的最高价
Numeric Min15Low(1000000); //开盘15分钟的最低价
Numeric EntryBarHigh(-1); //进场时K线的最高价
Numeric EntryBarLow(-1); //进场时K线的最低价
Integer EntryBarIdx(-1); //进场时的K线索引值
bool bHaveInit(False);
Vars
//局部变量定义
Begin
Integer TodayBars = BarsSinceToday + 1;
if(TodayBars ==1) //当天第一根K线重新初始化
{
if(!bHaveInit)
{
Min15High = 0;
Min15Low = 1000000;
bHaveInit = True;
}
}
Else
{
bHaveInit = False;
}
if(TodayBars <= StaticsBarCount) //前15分钟只做统计
{
Min15High = Max(High,Min15High); //前15分钟的最高价
Min15Low = Min(Low,Min15Low); //前15分钟的最低价
}
Else//15分钟后开始交易
{
if(A_BuyPosition + A_SellPosition == 0 && Time<LeaveTime) //当前没有持仓,判断是否开仓
{
if(Q_Close > Min15High)
{
Buy(1,Q_AskPrice); //以申卖价开1手多仓
EntryBarIdx = CurrentBar;
EntryBarHigh = High;
EntryBarLow = Low;
}
Else if(Q_Close < Min15Low)
{
SellShort(1,Q_BidPrice); //以申买价开1手空仓
EntryBarIdx = CurrentBar;
EntryBarLow = Low;
EntryBarHigh = High;
}
}
Else //存在持仓,判断是否止损
{
if(CurrentTime>=LeaveTime) //到达离场时间
{
if(A_BuyPosition>0)
{
Sell(0,Q_BidPrice); //卖出,平多仓
PlotText(Close,"闭市离场");
}
if(A_SellPosition >0)
{
BuyToCover(0,Q_AskPrice);//买入,平空仓
PlotText(Close,"闭市离场");
}
}
Else
{
//时间小于离场时间,判断止损
if(CurrentBar == EntryBarIdx) //进场K线还没有走完
{
EntryBarHigh = High;
EntryBarLow = Low;
if(A_BuyPosition>0 && Q_Close<Low[1])
{
Sell(0,Q_BidPrice); //卖出,平多仓
PlotText(Close,"止损");
Print('11');
}
if(A_SellPosition >0 && Q_Close>High[1])
{
BuyToCover(0,Q_AskPrice);//买入,平空仓
PlotText(Close,"止损");
Print('22');
}
}
Else
{
if(A_BuyPosition>0 && Q_Close<EntryBarLow)
{
Sell(0,Q_BidPrice); //卖出,平多仓
PlotText(Close,"止损");
}
if(A_SellPosition >0 && Q_Close>EntryBarHigh)
{
BuyToCover(0,Q_AskPrice);//买入,平空仓
PlotText(Close,"止损");
}
}
}
}
}
PlotNumeric("多头突破线",Min15High,0,RGB(255,0,255));
PlotNumeric("多头止损线",EntryBarLow,0,RGB(100,0,100));
PlotNumeric("空头突破线",Min15Low,0,RGB(0,255,0));
PlotNumeric("空头止损线",EntryBarHigh,0,RGB(0,100,0));
End
|
|