TB中手数类型如何定义?

//------------------------------------------------------------------------// 策略名称: TripleEMA Trend Strategy// 作者: Based on MT5 Original// 版本: 1.1//------------------------------------------------------------------------Params Numeric LookBack(100); // 回溯周期 Numeric ProfitLock(15); // 锁定盈利点数 Numeric TrailingStep(15); // 移动止损间距 Numeric TakeProfit(80); // 固定止盈点数 Numeric StopLoss(20); // 初始止损点数 Numeric LotType(0); // 手数类型:0=固定,1=风险%,2=波动率 Numeric FixedLot(1); // 固定手数 Numeric RiskPercent(5); // 风险百分比 Numeric VolatilityRatio(0.5); // 波动系数Vars Numeric ema21; // 21周期EMA Numeric ema34; // 34周期EMA Numeric ema55; // 55周期EMA Series<Numeric> trailPrice; // 追踪止损价格 Numeric contractSize; // 合约大小 Numeric pointValue; // 点值 Numeric currentLot; // 实际手数 Bool buySignal; // 买入信号 Bool sellSignal; // 卖出信号 Numeric atrValue; // ATR值 Numeric minLot; // 最小手数 Numeric maxLot; // 最大手数 Numeric lotStep; // 手数步长 Numeric riskAmount; // 风险金额 Numeric tickValue; // 每点价值 Numeric stopLossPoints; // 止损点数 Numeric i; // 循环变量 Bool trendValid; // 趋势验证标志//---------------------------------------------------------------------// 主程序//---------------------------------------------------------------------Begin // 基础参数计算 pointValue = PriceScale * BigPointValue; // 计算点值 ema21 = XAverage(Close,21); ema34 = XAverage(Close,34); ema55 = XAverage(Close,55); // 手数计算 contractSize = ContractUnit; // 合约大小 minLot = MinLot; // 最小手数 maxLot = MaxLot; // 最大手数 lotStep = LotStep; // 手数步长 If LotType == 0 Then // 固定手数 Begin currentLot = FixedLot; End Else If LotType == 1 Then // 风险百分比 Begin riskAmount = Portfolio_CurrentCapital * RiskPercent / 100; tickValue = TickValue; stopLossPoints = StopLoss * pointValue; If stopLossPoints > 0 Then currentLot = riskAmount / (stopLossPoints * tickValue); End Else If LotType == 2 Then // 波动率 Begin atrValue = AvgTrueRange(14); currentLot = (atrValue * VolatilityRatio) / pointValue; End; // 规范化手数 currentLot = IntPart(currentLot / lotStep) * lotStep; currentLot = Max(currentLot, minLot); currentLot = Min(currentLot, maxLot); // 持仓管理 If MarketPosition <> 0 Then Begin // 移动止损逻辑 If MarketPosition == 1 Then // 多单 Begin If High >= EntryPrice + ProfitLock * pointValue Then trailPrice = EntryPrice + TrailingStep * pointValue; End Else If MarketPosition == -1 Then // 空单 Begin If Low <= EntryPrice - ProfitLock * pointValue Then trailPrice = EntryPrice - TrailingStep * pointValue; End // 更新止损 If trailPrice > 0 Then SetStopLoss(trailPrice); End // 信号生成 If MarketPosition == 0 Then Begin // 多单条件 trendValid = True; For i = 0 To LookBack - 1 Begin If XAverage(Close,34)[i] <= XAverage(Close,34)[i+1] Or XAverage(Close,55)[i] <= XAverage(Close,55)[i+1] Then trendValid = False; End buySignal = Close > ema21 And trendValid And Close[1] < ema21[1]; // 空单条件 trendValid = True; For i = 0 To LookBack - 1 Begin If XAverage(Close,34)[i] >= XAverage(Close,34)[i+1] Or XAverage(Close,55)[i] >= XAverage(Close,55)[i+1] Then trendValid = False; End sellSignal = Close < ema21 And trendValid And Close[1] > ema21[1]; // 执行交易 If buySignal Then Buy(currentLot, Open, Open - StopLoss * pointValue, Open + TakeProfit * pointValue); Else If sellSignal Then SellShort(currentLot, Open, Open + StopLoss * pointValue, Open - TakeProfit * pointValue); EndEnd这个程序在tb中编译时总是提示:无法识别的字符串LotType,错误号1002,行号54。本人不会写代码,这个是将mt5中的EA代码放deepseek编译过来的,有高手能帮忙解决一下问题吗?先谢谢了。

这说明deepseek是瞎写的。瞎写出来的东西能怎么处理呢?只能扔进垃圾桶

你这个不是哪一行的问题,是从头到尾都没对TB公式里面没有 begin end 的结构也没有 if then的写法总之 从头错到尾,估计你只能找人代写。置顶帖有

回复:😁😁😁