- 精华
- 0
- 在线时间
- 57 小时
- UID
- 114160
- 积分
- 74
- 帖子
- 46
- 阅读权限
- 30
- 注册时间
- 2012-12-16
- 最后登录
- 2021-8-3
- 精华
- 0
- UID
- 114160
- 积分
- 74
- 帖子
- 46
- 主题
- 28
- 阅读权限
- 30
- 注册时间
- 2012-12-16
- 最后登录
- 2021-8-3
|
各位老师好,这是一个简单的双均线系统,它是以短期均线上穿或下穿长期均线时的那根K线的下一根K线的开盘价开仓或平仓的,我现在想实现的是如何在均线上穿或下穿时的那根K线的收盘前5分钟做一个判断,然后以最新的价格开仓或平仓,而不是等到下一根K线才开仓或平仓,不知道可不可以?该如何实现呢?
Params
Numeric Qty(1); // 交易手数
Numeric FastLength(5); // 短周期
Numeric SlowLength(10);// 长周期
Numeric PY(2); // 偏移委托
Numeric DelayTicks(30);// TICK计数
Vars
NumericSeries fastma;
NumericSeries slowma;
NumericSeries vTemp;
NumericSeries openstyle;
Numeric MinPoint;
Bool bLongCond;
Bool bShortCond;
Bool bOutLong;
Bool bOutShort;
Numeric LastBarTime;
Numeric TickCounter;
Begin
// 集合竞价和小节休息过滤
If(!CallAuctionFilter()) Return;
// Tick计数
LastBarTime = GetGlobalVar(0);
TickCounter = GetGlobalVar(1);
MinPoint == MinMove*PriceScale;
fastma = Average(Close,FastLength);
slowma = Average(Close,SlowLength);
PlotNumeric("fastma",fastma);
PlotNumeric("slowma",slowma);
bLongCond = fastma[1] > slowma[1]
And Close[1] > High[2]
And Close[1] > Max(fastma[1],slowma[1])
And Close[1] > Open[1];
bShortCond = fastma[1] < slowma[1]
And Close[1] < Low[2]
And Close[1] < Min(fastma[1],slowma[1])
And Close[1] < Open[1];
bOutLong = (Close[1] < Min(Low[2],Low[3]))
Or (Close[1] < Min(fastma[1],slowma[1]))
Or (fastma[1] < slowma[1]);
bOutShort = (Close[1] > Max(High[2],High[3])) Or (Close[1] > Max(fastma[1],slowma[1]))Or (fastma[1] > slowma[1]);
// 反手开仓
if (MarketPosition == -1 And bLongCond)
{
if(BarStatus != 2)
{
Buy(Qty,Open+PY*MinPoint);
}
if(BarStatus == 2)
{
BuyToCover(1,Open+PY*MinPoint);
If(TickCounter == 0) { TickCounter = 1; }
If(TickCounter < DelayTicks) { TickCounter = TickCounter + 1; }
Else
{
Buy(Qty,Open+PY*MinPoint);
}
}
SetGlobalVar(0,LastBarTime);
SetGlobalVar(1,TickCounter);
}
if (MarketPosition == 1 And bShortCond)
{
if(BarStatus != 2)
{
SellShort(Qty,Open-PY*MinPoint);
}
if(BarStatus == 2)
{
Sell(1,Open-PY*MinPoint);
If(TickCounter == 0) { TickCounter = 1; }
If(TickCounter < DelayTicks) { TickCounter = TickCounter + 1; }
Else
{
SellShort(Qty,Open-PY*MinPoint);
}
}
SetGlobalVar(0,LastBarTime);
SetGlobalVar(1,TickCounter);
}
// 开仓
if (MarketPosition == 0 And bLongCond)
{
Buy(Qty,Open+PY*MinPoint);
}
if (MarketPosition == 0 And bShortCond)
{
SellShort(Qty,Open-PY*MinPoint);
}
// 平多单
if(MarketPosition == 1 And BarsSinceEntry > 0)
{
if(bOutLong)
{
Sell(Qty,Open-PY*MinPoint);
}
}
// 平空单
if(MarketPosition == -1 And BarsSinceEntry > 0)
{
if(bOutShort)
{
BuyToCover(Qty,Open+PY*MinPoint);
}
}
End
|
|