设为首页收藏本站

 找回密码
 注册
查看: 1258|回复: 0
打印 上一主题 下一主题

在日K线的情况下如何实现收盘前开平仓 [复制链接]

Rank: 2

精华
0
UID
114160
积分
74
帖子
46
主题
28
阅读权限
30
注册时间
2012-12-16
最后登录
2021-8-3
跳转到指定楼层
1#
发表于 2015-9-9 05:58:04 |只看该作者 |倒序浏览
各位老师好,这是一个简单的双均线系统,它是以短期均线上穿或下穿长期均线时的那根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
您需要登录后才可以回帖 登录 | 注册

bottom

静态版|手机版|联系我们|交易开拓者 ( 粤ICP备07044698   

GMT+8, 2024-5-22 20:53

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部