我在测试一个跨周期的交易策略公式,大周期是1H,小周期是15M,同一个公式,同一个工作区,一开始我在TBQ里进行测试和参数优化,但导出公式和工作区,再导入TBQ3,发现策略报告里的净利润数值差别很大,各个策略单元的数据也不同,而且实际测试下来,TBQ3里开空单的,到了TBQ里可能就不开仓。我不太方便把代码贴出来,因为是我花钱购买来的代码,但是想问一下TBQ3和TBQ里对多周期执行的优化比较大吗?有什么潜在的机制会造成这个问题吗?
TBQ策略报告:

TBQ3策略报告:

是TBQ3的跨周期运行机制更好,回测结果和策略报告结果更准确吗?
这两个版本主要的区别是体现在执行自动交易上,回测一般是不会有区别的
这个要分析原因就必须有源代码,仔细比较两边测试报告的异同,查看是哪里计算结果有不一样
我把简化过的代码发给你,因为我花了几万块钱买的(可能被坑了),不太愿意直接给完整代码。但是我试过简化过的代码也能复现问题。如果可能的话,如果你本地也复现了问题,可以让你们的研发看看是不是个问题。
//------------------------------------------------------------------------
// 简称: TE_MultipleTimeframes
// 名称: 测试版MultipleTimeframes
// 类别: 公式应用
// 类型: 用户应用
// 输出: Void
//------------------------------------------------------------------------
Params
Numeric Length(60); //均线周期
//MACD参数
Numeric FastLength(12); //MACD快速周期
Numeric SlowLength(26); //MACD慢速周期
Numeric MACDLength(9); //MACD平滑周期
//其他参数
Numeric HalfProfit(3); // 盈利3%后减半仓
Numeric ATRPeriod(14); // ATR计算周期
Numeric StopLossMultiplier(2.0); // 止损倍数
Numeric Lots(1); //开仓手数
Vars
//MACD变量
Global Numeric Diff;
Global Numeric Dea;
Series<Numeric> MACDValue;
Series<Numeric> MAValue;
Global Bool condLong1;
Global Bool condLong2;
Global Bool condLong3;
Global Bool condShort1;
Global Bool condShort2;
Global Bool condShort3;
Global Bool condLong;
Global Bool condShort;
Global Numeric HighAfterEntry;
Global Numeric LowAfterEntry;
// 大周期MACD变量
Global Numeric MainFastLength(12); //大周期MACD快速周期
Global Numeric MainSlowLength(26); //大周期MACD慢速周期
Global Numeric MainMACDLength(9); //大周期MACD平滑周期
Global Numeric MainDiff;
Global Numeric MainDea;
Global Numeric MainMACDValue;
Global Numeric HighestMainMACDValueInBar;
Global Numeric LowestMainMACDValueInBar;
Defs
//此处添加公式函数
Events
OnBarOpen(ArrayRef<Integer> indexs)
{
// 计算大周期MACD指标
Range[0:0]
{
//计算MACD
MainDiff = XAverage(Open, MainFastLength) - XAverage(Open, MainSlowLength);
MainDea = XAverage(MainDiff, MainMACDLength);
MainMACDValue = 2 * (MainDiff - MainDea);
HighestMainMACDValueInBar = MainMACDValue;
LowestMainMACDValueInBar = MainMACDValue;
}
}
OnBar(ArrayRef<Integer> indexs)
{
// 计算大周期MACD指标
Range[0:0]
{
//计算MACD
MainDiff = XAverage(Close, MainFastLength) - XAverage(Close, MainSlowLength);
MainDea = XAverage(MainDiff, MainMACDLength);
MainMACDValue = 2 * (MainDiff - MainDea);
HighestMainMACDValueInBar = Max(MainMACDValue, HighestMainMACDValueInBar);
LowestMainMACDValueInBar = Min(MainMACDValue, LowestMainMACDValueInBar);
}
Range[1:1]
{
//计算均线
MAValue = AverageFC(Close, Length);
//计算MACD
Diff = XAverage(Close, FastLength) - XAverage(Close, SlowLength);
Dea = XAverage(Diff, MACDLength);
MACDValue = 2 * (Diff - Dea);
//计算多头开仓条件
condLong1 = Close[1] > Close[2] And Close[2] > Close[3] And Close[3] > Close[4];
condLong2 = MACDValue[1] > 0;
condLong3 = HighestMainMACDValueInBar > 0;
condLong = condLong1 And condLong2 And condLong3;
//计算空头开仓条件
condShort1 = Close[1] < Close[2] And Close[2] < Close[3] And Close[3] < Close[4];
condShort2 = MACDValue[1] < 0;
condShort3 = LowestMainMACDValueInBar < 0;
condShort = condShort1 And condShort2 And condShort3;
// 多头开仓或反手
If (condLong)
{
If (MarketPosition == 0) // 没仓位,多头开仓
{
Buy(Lots, Open);
}
If (MarketPosition == -1) // 有空单,空头平仓
{
BuyToCover(Lots, Open);
}
}
// 空头开仓或反手
If (condShort)
{
If (MarketPosition == 0) // 没仓位,空头开仓
{
SellShort(Lots, Open);
}
If (MarketPosition == 1) // 有多单,多头平仓
{
Sell(Lots, Open);
}
}
If (MarketPosition == 1)
{
If (BarsSinceEntry == 0)
HighAfterEntry = Open;
Else
HighAfterEntry = Max(Open, HighAfterEntry);
}
If (MarketPosition == -1)
{
If (BarsSinceEntry == 0)
LowAfterEntry = Open;
Else
LowAfterEntry = Min(Open, LowAfterEntry);
}
}
}策略单元XML导出文件
<?xml version="1.0" encoding="utf-8"?>
<App>
<TradeUnit xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" UnitName="沪铝加权0" PreFix="1H_15M" UnitVersion="1.0.0.0" TradeLock="false" RunLock="false" Expand="false" RefUnitID="">
<Goods>
<G RefID="3ace5a05-389e-461a-aa2d-95e35884f339" lBeginTime="0" lEndTime="0">
<GoodsSetting Source="User" Display="On" GoodsName="沪铝加权0">
<DataRangeSetting FinishedStart="0" FinishedEnd="0" SampleValue="1000" SampleRangeUnit="Day" SampleUnitValue="1" EnableSampleEndDate="false">
<DataRange RangeType="BEGINEND" RangeUnit="0" RangeValue="20200106090000000" Term="Hour" NValue="1" EnableNValue="false">
<GoodsKey Goods="al000" Category="CategoryFutures" Exchange="SHFE" nCodeID="-8983285507050605926" />
</DataRange>
</DataRangeSetting>
<TradeSetting LongMargin="9" ShortMargin="9" CurrentPercent="0" MarginFlag="PercentOfTotalAccount" CommissionFlag="PercentOfTotalAccount" CommissionOpen="1.5" CommissionClose="1.5" CommissionCloseToday="1.5" SlipPointMode="PointByNum" SlipPointValue="2" />
<MappingSetting MappingMode="D0ToMain">
<MappingGoods />
</MappingSetting>
<DelegateSetting EnableMarketPrice="true" OrderPriceType="ORDER_PRICE_OPP" MarketStep="10" />
<AimSetting AimType="Speculate" />
<KChartGoodsDataSetting eFormerRights="None" eKChartDataRange="All" EnableCC="false" EnableKCutTradeTime="false" KCutTradeTimeFlag="Normal" EnableKCutShowEndTime="false" DataSourceType="ByUser" IsAutoSwapPosition="false" />
<GoodsLineSetting KLineType="Hollow" CurrentKLineStyle="Nagative" Is3DStyle="false">
<NagativeLineStyle KLineStyle="Nagative" KLineColorHtml="#FFFF5858" />
<PositiveLineStyle KLineStyle="Positive" KLineColorHtml="#FF00FFFF" />
<NShadowLineStyle KLineStyle="NShadow" KLineColorHtml="#FFFF5858" />
<PShadowLineStyle KLineStyle="PShadow" KLineColorHtml="#FF00FFFF" />
</GoodsLineSetting>
<AlgoTradeSetting EnableAlgo="false" HaveInited="false">
<Template TemplateName="tempTemplate" RunMinNum="10" bSingleOrHandicap="true" SingleNum="1" SingleRange="1" HandicapPercent="0" OrderPriceType="ORDER_PRICE_OPP" OffsetHops="0" bOrderDependency="false" MinOrderHandicaps="50" bTimeDependency="true" OrderSpan="5" OrderSpanRange="0" TotalTime="60" eTotalTimeLimit="CurrentDay" bTakeActionsWhenHarmful="false" MinHarmfulHops="0" bStopOrAccelerateWhenHarmful="true" bTakeActionsWhenBenefit="false" MinBenefitHops="0" bStopOrAccelerateWhenBenefit="true" bChildReOrderWhenHarmful="false" ChildReOrderPriceType="ORDER_PRICE_LATEST" MinChildReOrderHarmfulHops="1" bCanAlgoTrade="false" bAutoKP="false">
<nBidAskTicks>0</nBidAskTicks>
</Template>
</AlgoTradeSetting>
</GoodsSetting>
</G>
<G RefID="1fc6f5d0-601a-4f1b-9665-0b2d011602da" lBeginTime="0" lEndTime="0">
<GoodsSetting Source="User" Display="On" GoodsName="沪铝加权0">
<DataRangeSetting FinishedStart="0" FinishedEnd="0" SampleValue="1000" SampleRangeUnit="Day" SampleUnitValue="1" EnableSampleEndDate="false">
<DataRange RangeType="BEGINEND" RangeUnit="0" RangeValue="20200106090000000" Term="Minitus" NValue="15" EnableNValue="false">
<GoodsKey Goods="al000" Category="CategoryFutures" Exchange="SHFE" nCodeID="-8983285507050605926" />
</DataRange>
</DataRangeSetting>
<TradeSetting LongMargin="9" ShortMargin="9" CurrentPercent="0" MarginFlag="PercentOfTotalAccount" CommissionFlag="PercentOfTotalAccount" CommissionOpen="1.5" CommissionClose="1.5" CommissionCloseToday="1.5" SlipPointMode="PointByNum" SlipPointValue="2" />
<MappingSetting MappingMode="D0ToMain">
<MappingGoods />
</MappingSetting>
<DelegateSetting EnableMarketPrice="true" OrderPriceType="ORDER_PRICE_OPP" MarketStep="10" />
<AimSetting AimType="Speculate" />
<KChartGoodsDataSetting eFormerRights="None" eKChartDataRange="All" EnableCC="false" EnableKCutTradeTime="false" KCutTradeTimeFlag="Normal" EnableKCutShowEndTime="false" DataSourceType="ByUser" IsAutoSwapPosition="false" />
<GoodsLineSetting KLineType="Hollow" CurrentKLineStyle="Nagative" Is3DStyle="false">
<NagativeLineStyle KLineStyle="Nagative" KLineColorHtml="#FFFF5858" />
<PositiveLineStyle KLineStyle="Positive" KLineColorHtml="#FF00FFFF" />
<NShadowLineStyle KLineStyle="NShadow" KLineColorHtml="#FFFF5858" />
<PShadowLineStyle KLineStyle="PShadow" KLineColorHtml="#FF00FFFF" />
</GoodsLineSetting>
<AlgoTradeSetting EnableAlgo="false" HaveInited="false">
<Template TemplateName="tempTemplate" RunMinNum="10" bSingleOrHandicap="true" SingleNum="1" SingleRange="1" HandicapPercent="0" OrderPriceType="ORDER_PRICE_OPP" OffsetHops="0" bOrderDependency="false" MinOrderHandicaps="50" bTimeDependency="true" OrderSpan="5" OrderSpanRange="0" TotalTime="60" eTotalTimeLimit="CurrentDay" bTakeActionsWhenHarmful="false" MinHarmfulHops="0" bStopOrAccelerateWhenHarmful="true" bTakeActionsWhenBenefit="false" MinBenefitHops="0" bStopOrAccelerateWhenBenefit="true" bChildReOrderWhenHarmful="false" ChildReOrderPriceType="ORDER_PRICE_LATEST" MinChildReOrderHarmfulHops="1" bCanAlgoTrade="false" bAutoKP="false">
<nBidAskTicks>0</nBidAskTicks>
</Template>
</AlgoTradeSetting>
</GoodsSetting>
</G>
</Goods>
<Formular>
<F>
<TacticSetting Enabled="true" Loaded="false" bShow="true" EnableWarn="false" WarnType="0" WarnSettingID="0" WarnTimes="-1" SerVarRefCount="0" dWeight="1">
<IsSelectedAllGoodsByDisplayStatus>false</IsSelectedAllGoodsByDisplayStatus>
<Layers />
<Master IsHavePlotInfo="false" Code="DE_MultipleTimeframes" Author="" Name="" ShowMode="Main" ScaleMode="Relative" MaxBarBack="0" TacticsCategory="Formular" TacticsType="EStrategyType_UserFormula" IsFromDrawLine="false" FuncRetType="ReturnType_VOID" IsSrcCodeEmpty="false" IsSrcCodeInvisible="false" IsSightLess="false" IsHasTradeFunc="true" IsHasPickStokeFunc="false" GroupName="My开发环境">
<NativeStrategyKey>
<author />
<strName>DE_MultipleTimeframes</strName>
<type>EStrategyType_UserFormula</type>
</NativeStrategyKey>
</Master>
<Parameters>
<Parameter Name="Length" DataType="DataType_Numeric" Value="19" Notes="均线周期" IsMust="false" IsHide="false">
<Enums />
</Parameter>
<Parameter Name="FastLength" DataType="DataType_Numeric" Value="12" Notes="MACD快速周期" IsMust="false" IsHide="false">
<Enums />
</Parameter>
<Parameter Name="SlowLength" DataType="DataType_Numeric" Value="26" Notes="MACD慢速周期" IsMust="false" IsHide="false">
<Enums />
</Parameter>
<Parameter Name="MACDLength" DataType="DataType_Numeric" Value="9" Notes="MACD平滑周期" IsMust="false" IsHide="false">
<Enums />
</Parameter>
<Parameter Name="HalfProfit" DataType="DataType_Numeric" Value="3" Notes="盈利3%后减半仓" IsMust="false" IsHide="false">
<Enums />
</Parameter>
<Parameter Name="ATRPeriod" DataType="DataType_Numeric" Value="14" Notes="ATR计算周期" IsMust="false" IsHide="false">
<Enums />
</Parameter>
<Parameter Name="StopLossMultiplier" DataType="DataType_Numeric" Value="2.0" Notes="止损倍数" IsMust="false" IsHide="false">
<Enums />
</Parameter>
<Parameter Name="Lots" DataType="DataType_Numeric" Value="1" Notes="开仓手数" IsMust="false" IsHide="false">
<Enums />
</Parameter>
</Parameters>
<Lines />
<Deal TacticsID="0" UserTacticsID="0" ShowTradeLine="true" TradeLineStyle="LineType_Dashed" TradeLineWidth="1" LoseColorHtml="#FF00FF00" WinColorHtml="#FFFF0000" />
<Symbles>
<Symble TacticsID="0" UserTacticsID="0" SymbleID="Buy" SymbleStyleID="1" SymbleStyleColorHtml="#FFFFFF00" PriceStyleID="1" PriceStyleColorHtml="#FFFFFF00" Flag="ShowTradeNum" />
<Symble TacticsID="0" UserTacticsID="0" SymbleID="Sell" SymbleStyleID="1" SymbleStyleColorHtml="#FFFFFF00" PriceStyleID="1" PriceStyleColorHtml="#FFFFFF00" Flag="ShowTradeNum" />
<Symble TacticsID="0" UserTacticsID="0" SymbleID="SellShort" SymbleStyleID="1" SymbleStyleColorHtml="#FFFF00FF" PriceStyleID="1" PriceStyleColorHtml="#FFFF00FF" Flag="ShowTradeNum" />
<Symble TacticsID="0" UserTacticsID="0" SymbleID="BuyToCover" SymbleStyleID="1" SymbleStyleColorHtml="#FFFF00FF" PriceStyleID="1" PriceStyleColorHtml="#FFFF00FF" Flag="ShowTradeNum" />
</Symbles>
<OptimizeParamters />
</TacticSetting>
</F>
</Formular>
<StrategyTradeSetting>
<BaseAccountSetting Equity="20000000" Rate="1" />
<TradeSetting VolType="TRADE_VOLUMN_TYPE_VOL" Vol="1" IniMargin="500000" IgnoreHistorySignal="false" SignalBeginMillSecTime="1776661478752" EnableSignalBeginBar="false" SignalBeginBar="1" EnableMaxTradeCount="false" MaxTradeCount="-1" AllowOpenOnEnd="false" MaxOpenOnEndNum="0" MaxPositionNum="200" CalExpandWhenOpti="true" NumForAverDrawdownCal="5" RptByReturnRate="false" RptIncLossOutGain="false" ZXSPDefault="95" ZXSPSampleSizeDefault="10000" />
</StrategyTradeSetting>
<ProgramTradeSetting>
<IgnoreSetting IgnoreBuy="false" IgnoreSell="false" IgnoreSellShort="false" IgnoreBuyToCover="false" />
<ExSetting OrderUserConfirm="false" StrategyShowDialog="false" SendMsgToApp="false" />
<UnitSetting IniMargin="500000" />
</ProgramTradeSetting>
</TradeUnit>
</App>在我本地可以复习这样的问题,策略报告TBQ和TBQ3不一样:

