开拓者期货期权程序化系统交易论坛

标题: 小米,满足条件只减仓1手,实现不了,请帮忙 [打印本页]

作者: cts2015deng    时间: 2016-5-27 08:57:47     标题: 小米,满足条件只减仓1手,实现不了,请帮忙

满足条件1只减仓1手,条件2减仓1手,如何控制,谢谢
我这给减仓完了
Params
        Numeric Length1(41);                                                                //长周期区间参数
        Numeric Length2(3);                                                                //短周期区间参数
        Numeric IPS(1.2);                                                                                //保护止损波动率参数
        Numeric AtrVal(20);                                //波动率参数
        Numeric jx(107);
        Numeric lots(5);
          Numeric SubSet(8);         // 减仓设置
         Numeric lots1(1);
       
Vars
        NumericSeries ProtectStopL;
        NumericSeries ATR;
        NumericSeries Upperband;
        NumericSeries Lowerband;
        NumericSeries Exitlong;
        NumericSeries Exitshort;
        NumericSeries ma;
        Numeric L2;
        Numeric L1;
        Numeric Minpoint;
        NumericSeries firstPrice;   // 第一次开仓价格
    NumericSeries LastPrice;    // 最后一次开仓价格
    Numeric AddSet(30);         // 加仓设置
   
        Numeric flag(0) ;
       
Begin

        // 集合竞价和小节休息过滤
        If(!CallAuctionFilter()) Return;
       
        Minpoint = Minmove*PriceScale;
    ATR = AvgTrueRange(AtrVal);                                                     //定义ATR
        L1 = Max(Length1,Length2);                                                     //出场周期选择较大的区间参数
        L2 = Min(Length1,Length2);                                                     //出场周期选择较小的区间参数
        Upperband = Highest(High, L1);                                             //长周期最高价区间
        Lowerband = lowest(Low,L1);                                                       //长周期最低价区间
        Exitlong = Lowest(Low,L2);                                                     //短周期最低价区间
        Exitshort = Highest(high,L2);                                             //短周期最高价区间
        ma=Average(c,jx);
        //系统入场
        If(Marketposition == 0 and High >= Upperband[1] + Minpoint And Vol > 0  and c[1]>ma[1])             //价格大于长周期最高价区间入场做多
        {
                Buy(lots, Max(Open, Upperband[1] + 2*Minpoint));firstPrice=LastEntryPrice;
                ProtectStopL = Entryprice - IPS*ATR[1];
        }
       
        //系统出场
        If(MarketPosition == 1 and BarsSinceEntry >0 And Vol > 0)
        {
                If( Low <= ProtectStopL[1] and ProtectStopL[1] >= Exitlong[1])  //价格低于入场价以下一定ATR幅度止损
                {
                        Sell (0,Min(Open-Minpoint,ProtectStopL[1]-Minpoint));
                }
                Else if (Low <= Exitlong[1] - Minpoint)                    //价格低于短周期最低价区间出场
                {
                        Sell(0, Min( Open-Minpoint, Exitlong[1] - 2*Minpoint));
                }
        }
if( MarketPosition == 1 and  h>= firstPrice + SubSet*MinPoint ) {flag=0;}// 减仓
        if (flag==0)
           // firstPrice = firstPrice + SubSet*MinPoint;
            //if(Open >firstPrice) firstPrice = Open;
           { sell(lots1,firstPrice+SubSet*MinPoint-2*Minpoint);flag=flag+1;Commentary("flag1="+text(flag)); }
        
End

作者: 小米    时间: 2016-5-27 10:12:46

平仓手数不要写为0啊。。改为你想要的1手
作者: cts2015deng    时间: 2016-5-27 10:33:33

我的想法是开仓5手,盈利8跳后减仓1手,下面的不对,是比如盈利8跳减仓1手,不停的减仓减完了,而且还偷价了,全部平在最高价了

if( MarketPosition == 1 and  h>= firstPrice + SubSet*MinPoint ) {flag=0;}// 减仓
        if (flag==0)
            // firstPrice = firstPrice + SubSet*MinPoint;
             //if(Open >firstPrice) firstPrice = Open;
            { sell(lots1,firstPrice+SubSet*MinPoint-2*Minpoint);flag=flag+1;Commentary("flag1="+text(flag)); }




欢迎光临 开拓者期货期权程序化系统交易论坛 (http://bbs.tb18.net/) Powered by Discuz! X2