日内均线策略
/*刘老师好,有个自动化交易策略麻烦帮忙写下:
①期货主力合约(自动换月),当开盘后实时价格大于分时均线时,
多单买入当前权利金30%仓位内最大手数做多。
当实时价格跌破分时均线且在两个最小变动价格内时(最大滑点2),
反手做空,即平掉持仓多单,买入当前权利金30%仓位内最大手数做空单。

②期货主力合约(自动换月),当开盘后实时价格小于分时均线时,
空单买入当前权利金30%仓位内最大手数做空。
当实时价格上涨突破分时均线且在两个最小变动价格内时(最大滑点2),
反手做多,即平掉持仓空单,买入当前权利金30%仓位内最大手数做多单。*/

//期货主力合约,还要自动换月,那么图表标的肯定是888,策略单元设置主力映射,监控器每天同步进行换月。
//1分时均线的计算,使用比较小的周期,不要大于1分钟
//权利金可能是误用,这里指的应该是账户权益,或者可用资金
//2仓位管理,如何计算指定保证金数量的交易手数
//手数 = 开仓资金/(开仓价格*合约单位*合约点数*保证金率)
//价格如果跳空跌破均线减去两跳,难道不平仓吗?这里的描述看不明白逻辑
//按照价格跌破均线减去两跳,平仓。
Params
    Integer open_limit(5);
    integer my_equity(1000000);
    numeric open_rate(0.3);
    Numeric my_marg_rate(0.2);
    integer stop_set(2);
    
    
Vars
    Series<numeric> total_value;
    Series<numeric> total_vol;
    Series<numeric> settle_price;
    Series<numeric> index;
    integer lots;
Events
    OnBar(ArrayRef<Integer> indexes)
    {
        //成交市值/成交量<>最新价
        //成交市值/成交量<>今日所有k线收盘价的平均值
    
        if(TrueDate(0)<>truedate(1))
        {
            total_value = 0;
            total_vol = 0;
            index = 0;
        }
    
        index = index + 1;
        total_value = total_value + turnover;
        total_vol = total_vol + vol;
        settle_price = total_value / total_vol / (ContractUnit * BigPointValue);
        Commentary("当日累积成交市值:" + text(total_value));
        Commentary("当日累积成交量:" + text(total_vol));
        Commentary("当日成交均价:" + text(settle_price));
        Commentary("当日第" + text(index) + "根bar");
        PlotNumeric("sp", settle_price);
    
        If(index <= open_limit) return; //MaxBarsBack
    
        if(high >= settle_price[1] and MarketPosition<>1)
        {
            Numeric price;
            price = max(open, settle_price[1]);
            lots = my_equity*open_rate/(price*ContractUnit*BigPointValue*my_marg_rate);
            buy(lots, price);
        }
        if(MarketPosition==1 and low<=settle_price[1]-stop_set*minmove*pricescale)
        {
            Numeric price;
            price = max(open, settle_price[1]);
            lots = my_equity*open_rate/(price*ContractUnit*BigPointValue*my_marg_rate);
            sellshort(lots,min(open,settle_price[1]-stop_set*minmove*pricescale));
        }
    }

直播答疑邮件的开发需求。

不构成投资建议和指导

分时图日内均线求法?
关于日内均线最标准的写法
均线策略
均线策略出错
跨周期均线策略
双均线策略问题
双均线策略
均线策略的开平价格
均线对策略的控制问题
关于均线对策略指令的控制

策略亏损严重

这是配合直播的邮件答疑内容