策略逻辑与图表不符

策略思路:日线作为图层2前一日5、10均线多头,做多采用基准仓位,做空采用基准仓位的一半;前一日5、10均线空头,做空采用基准仓位,做多采用基准仓位的一半。20分钟多头作为图层1,快线ema40,慢线ma180,20分钟空头作为图层2,快线ema35,慢线ma180。

20号胶2025.7.8日21:00这个开平仓,应该增加165的空头啊,明显存在问题,不该平了又开,实在排查不出原因,请协助解决。

图形与编码逻辑不符
图表策略与A函数策略的衔接
图表信号与策略逻辑不一致
图表与A函数
程序的回测发单与账户的实际发单不符
图表信号与策略报告不匹配
计算出来的值完全不符合逻辑
请问委托价格与成交价格之间的逻辑
bool函数逻辑与不正确,求解惑
请教一下图表策略与实盘策略对应的机理

//------------------------------------------------------------------------

// 简称: LSD_CrossCycleDualEmaMa

// 名称: 跨周期混合双均线双向多头0图层策略

// 类别: 策略应用

// 类型: 用户应用

// 输出: Void

//------------------------------------------------------------------------

Params

   Numeric LengthFast00(5);//0图层短周期参数

   Numeric LengthSlow00(20);//0图层长周期参数

   Numeric LengthFast01(5);//1图层短周期参数

   Numeric LengthSlow01(20);//1图层长周期参数

   Numeric LengthFast2(5);//日线短周期参数

   Numeric LengthSlow2(10);//日线长周期参数

   Numeric TotalCapital(4000000);//拟投入该策略本次交易的最大资金,单位元

Vars

   Series<Numeric> EMAFast00;

   Series<Numeric> MASlow00;

   Series<Numeric> EMAFast01;

   Series<Numeric> MASlow01;

   Series<Numeric> MAFast2;

   Series<Numeric> MASlow2;

   Series<Numeric> MinPositionLots;

   Series<Numeric> FundPositionLots;

   

Events

   

   OnInit()

   {

       Range[0:DataCount - 1]

       {

           AddDataFlag(Enum_Data_RolloverBackWard());   //设置后复权

           AddDataFlag(Enum_Data_RolloverRealPrice());  //真实价格

           AddDataFlag(Enum_Data_AutoSwapPosition());  //自动换仓

           AddDataFlag(Enum_Data_IgnoreSwapSignalCalc());  //忽略换仓信号计算

       }

       

       Numeric i;

       Numeric result = 1;    

       for i = 0 to DataSourceSize - 1

       {

           result = result * data[i].BarExistStatus;

       }

       If(result <> 1) Return;//数据未到齐,终止本次运行,等待下次

   }

   

   OnBar(ArrayRef<Integer> indexs)

   {

       EMAFast00 = XAverage(Close, LengthFast00);

       MASlow00 = Average(Close, LengthSlow00);

   

       Data1.EMAFast01 = Data1.XAverage(Data1.Close, LengthFast01);

       Data1.MASlow01 = Data1.Average(Data1.Close, LengthSlow01);

   

       Data2.MAFast2 = Data2.Average(Data2.Close, LengthFast2);

       Data2.MASlow2 = Data2.Average(Data2.Close, LengthSlow2);

   

       PlotNumeric("EMAFast00", EMAFast00);

       PlotNumeric("MASlow00", MASlow00);

       Data1.PlotNumeric("Data1.EMAFast01", Data1.EMAFast01);

       Data1.PlotNumeric("Data1.MASlow01", Data1.MASlow01);

       Data2.PlotNumeric("Data2.MAFast2", Data2.MAFast2);

       Data2.PlotNumeric("Data2.MASlow2", Data2.MASlow2);

       

       MinPositionLots = 0.5 * Max(1, IntPart(TotalCapital / (Open / Rollover *ContractUnit *BigPointValue * MarginRatio)));

   

       If(MarketPosition <> 1 And Data2.MAFast2[1] >= Data2.MASlow2[1] And EMAFast00[2] < MASlow00[2] And EMAFast00[1] >= MASlow00[1])

       {

           FundPositionLots = 2 * MinPositionLots;

           Buy(FundPositionLots, Open);

       }

   

       If(MarketPosition <> 1 And Data2.MAFast2[1] < Data2.MASlow2[1] And EMAFast00[2] < MASlow00[2] And EMAFast00[1] >= MASlow00[1])

       {

           FundPositionLots = MinPositionLots;

           Buy(FundPositionLots, Open);

       }

   

       If(MarketPosition <> 1 And Data2.MAFast2[1] >= Data2.MASlow2[1] And Data1.EMAFast01[2] < Data1.MASlow01[2] And Data1.EMAFast01[1] >= Data1.MASlow01[1] And EMAFast00[1] >= MASlow00[1])

       {

           FundPositionLots = 2 * MinPositionLots;

           Buy(FundPositionLots, Open);

       }

   

       If(MarketPosition <> 1 And Data2.MAFast2[1] < Data2.MASlow2[1] And Data1.EMAFast01[2] < Data1.MASlow01[2] And Data1.EMAFast01[1] >= Data1.MASlow01[1] And EMAFast00[1] >= MASlow00[1])

       {

           FundPositionLots = MinPositionLots;

           Buy(FundPositionLots, Open);

       }

   

       If(MarketPosition == 1 and BarsSinceEntry > 0  And EMAFast00[2] >= MASlow00[2] And EMAFast00[1] < MASlow00[1])

       {

           Sell(0, Open);

       }

   

       If(MarketPosition <> -1 And Data2.MAFast2[1] < Data2.MASlow2[1] And Data1.EMAFast01[2] > Data1.MASlow01[2] And Data1.EMAFast01[1] < Data1.MASlow01[1])

       {

           FundPositionLots = 2 * MinPositionLots;

           SellShort(FundPositionLots, Open);

       }

   

       If(MarketPosition <> -1 And Data2.MAFast2[1] > Data2.MASlow2[1] And Data1.EMAFast01[2] > Data1.MASlow01[2] And Data1.EMAFast01[1] < Data1.MASlow01[1])

       {

           FundPositionLots = MinPositionLots;

           SellShort(FundPositionLots, Open);

       }

   

       If(MarketPosition <> -1 And Data2.MAFast2[1] < Data2.MASlow2[1] And EMAFast00[2] > MASlow00[2] And EMAFast00[1] < MASlow00[1] And Data1.EMAFast01[1] <= Data1.MASlow01[1])

       {

           FundPositionLots = 2 * MinPositionLots;

           SellShort(FundPositionLots, Open);

       }

   

       If(MarketPosition <> -1 And Data2.MAFast2[1] > Data2.MASlow2[1] And EMAFast00[2] > MASlow00[2] And EMAFast00[1] < MASlow00[1] And Data1.EMAFast01[1] <= Data1.MASlow01[1])

       {

           FundPositionLots = MinPositionLots;

           SellShort(FundPositionLots, Open);

       }

   

       If(MarketPosition == -1 and BarsSinceEntry > 0 And Data1.EMAFast01[2] <= Data1.MASlow01[2] And Data1.EMAFast01[1] > Data1.MASlow01[1])

       {

           BuyToCover(0, Open);

       }

   }


//------------------------------------------------------------------------

// 编译版本    2025/11/11 82721

// 版权所有    winter110

// 更改声明    TradeBlazer Software保留对TradeBlazer平台

//            每一版本的TradeBlazer策略修改和重写的权利

//------------------------------------------------------------------------