shawaverage 发表于 2021-7-20 16:29:33

请求编写套利加仓代码

考虑交易螺纹与热卷的价差(RB-HC),条件是,当价差低于-300,做多价差(当前只考虑这个方向做法),同时,每隔固定比例(初始价差的1%)进行加仓,比如-300建仓1组,-270再次建仓一组,以此类推。如果价差有利先升后跌,触及初始进入的价差点位,则平仓部分仓位,比如价差上冲-270达到-260后,再次回落到-270,则平仓一组,如果继续回落到-300,则再次平仓一组,以此类推。  我自己编写的代码,加仓部分进行循环处理,写的不好,没达到自己想要的效果。哪位大侠有空帮忙写下。谢谢

自己写的部分代码

FirstEntryCon =CrossOver(JC,-300);
    MinPoint = Data0.MinMove*Data0.PriceScale;
        OPRICE=Data0.O-Data1.O;
        LPRICE=Data0.L-Data1.L;
    If(Data0.MarketPosition==0 AND Data1.MarketPosition==0 )
    {
        If(FirstEntryCon)
        {
            firstPrice = Data0.Close-Data1.Close;
                        Commentary("firstPrice"+Text(firstPrice));
                    LastPrice = firstPrice;
                        Commentary("LastPrice"+Text(LastPrice));
            Data0.Buy(1, Data0.OPEN);
                        Data1.SellShort(1,Data1.OPEN);
                       
        }
    }else If(Data0.MarketPosition==1 AND Data1.MarketPosition==-1) // 有多仓的情况
    {
        While(CurrentEntries < 4 && JC>= LastPrice + AddSet) // 加仓
        {
            LastPrice =LastPrice + AddSet;
                        PlotNumeric("LastPrice",LastPrice);
                        Commentary("LastPrice"+Text(LastPrice));
      
                        if(JC> LastPrice)
           {
                        LastPrice = JC;
                        PlotNumeric("LastPrice",LastPrice);
                        }
           Data0.Buy(1, Data0.O);
                   Data1.SellShort(1,Data1.O);
                 
        }
               
                /*
                FOR i= Length downTO 1
                {
                LastPrice=LastPrice;
                Commentary("LP"+Text(LastPrice));
                }
                */
页: [1]
查看完整版本: 请求编写套利加仓代码