老师可以帮我修复一下吗?

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

// 名称: 量大入场,量小出场-正向开仓策略(TBQuant3版)

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


Params

   Integer volLen(20);        // 成交量均线周期

   Numeric highVolMult(2.0);  // 高量阈值倍数(入场)

   Numeric lowVolMult(0.5);   // 低量阈值倍数(平仓)

   Integer atrLen(14);        // ATR周期

   Numeric slMult(1.0);       // 止损倍数

   Numeric tpMult(2.5);       // 止盈倍数

   Numeric qty(1);            // 手数

Vars

   Numeric volAvg, atrValue;

   Numeric longStop, longTP, shortStop, shortTP;

   Bool highVolCondition, lowVolCondition;

   Bool signalLong, signalShort;


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

// 1. 成交量计算

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

volAvg = Average(Volume, volLen);

highVolCondition = Volume >= volAvg * highVolMult;

lowVolCondition  = Volume <= volAvg * lowVolMult;


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

// 2. ATR止盈止损计算

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

atrValue = AvgTrueRange(atrLen);

longStop  = Close - atrValue * slMult;

longTP    = Close + atrValue * tpMult;

shortStop = Close + atrValue * slMult;

shortTP   = Close - atrValue * tpMult;


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

// 3. 信号定义

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

signalLong  = Close > Average(Close, volLen) and highVolCondition;

signalShort = Close < Average(Close, volLen) and highVolCondition;


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

// 4. 平仓逻辑

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

if lowVolCondition then

begin

   if MarketPosition = 1 then Sell("ExitLong") Next Bar at Market;

   if MarketPosition = -1 then BuyToCover("ExitShort") Next Bar at Market;

end;


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

// 5. 开仓逻辑(禁止双向)

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

if MarketPosition <= 0 and signalLong then

begin

   if MarketPosition = -1 then BuyToCover("CloseShort") Next Bar at Market;

   Buy("OpenLong") qty shares Next Bar at Market;

end;


if MarketPosition >= 0 and signalShort then

begin

   if MarketPosition = 1 then Sell("CloseLong") Next Bar at Market;

   SellShort("OpenShort") qty shares Next Bar at Market;

end;


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

// 6. 止盈止损(动态判断)

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

if MarketPosition = 1 then

begin

   if Low <= longStop then Sell("LongStop") Next Bar at Market;

   if High >= longTP   then Sell("LongTP")   Next Bar at Market;

end;


if MarketPosition = -1 then

begin

   if High >= shortStop then BuyToCover("ShortStop") Next Bar at Market;

   if Low <= shortTP    then BuyToCover("ShortTP")   Next Bar at Market;

end;

📊 策略逻辑说明(量大入场,量小出场)

一、核心思路

  • 成交量大 → 开仓
  • 成交量小 → 平仓
  • 方向判断:用价格相对均线位置决定多空方向


二、具体逻辑


模块逻辑说明
成交量条件当前成交量 ≥ 均量 × 高倍数 → 触发入场; ≤ 均量 × 低倍数 → 触发出场
趋势方向close > 均线 → 多头; close < 均线 → 空头
止盈止损使用 ATR 动态止盈止损,分别为 2.5×ATR、1×ATR
仓位控制禁止双向开仓,开仓前自动平掉反向仓
开多条件成交量高 + 收盘价 > 均线
开空条件成交量高 + 收盘价 < 均线
平仓条件成交量低(多空一致)


三、参数可调


参数默认值作用
volLen20成交量均线周期
highVolMult2.0高成交量阈值倍数
lowVolMult0.5低成交量阈值倍数
atrLen14ATR周期
slMult1.0止损倍数
tpMult2.5止盈倍数


老师,能帮我一下?
麻烦老师帮我编写一下
老师 我有个策略老是出现 信号闪烁 和重复开仓的问题 能帮我修复一下吗
老师帮忙修复一下策略隐患
麻烦老师帮我改正一下
麻烦老师帮我改一下
求助|老师能帮我看一下我的代码问题吗
请问一下老师,我想实现早午晚尾盘自动平仓,这样写代码可以吗?
策略闪烁,能帮我修改一下吗?
老师, 信号闪烁问题, 困扰我一个多月, 能帮我解决一下吗

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

// 简称: TB_Vol

// 名称: 量大入场,量小出场-正向开仓策略

// 类别: 策略应用

// 类型: 用户应用

// 输出: Void

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

Params

  Integer volLen(20);        // 成交量均线周期

  Numeric highVolMult(2.0);  // 高量阈值倍数(入场)

  Numeric lowVolMult(0.5);   // 低量阈值倍数(平仓)

  Integer atrLen(14);        // ATR周期

  Numeric slMult(1.0);       // 止损倍数

  Numeric tpMult(2.5);       // 止盈倍数

  Numeric qty(1);            // 手数

Vars

  Numeric  volAvg;

  Numeric atrValue;

  Numeric longStop;

  Numeric longTP;

  Numeric shortStop;

  Numeric shortTP;

  Bool highVolCondition;

  Bool lowVolCondition;

  Bool signalLong;

  Bool signalShort;

Defs

   //此处添加公式函数

Events

   //此处实现事件函数

   OnInit()

   //设置周期

   {

     }

//Bar更新事件函数,参数indexs表示变化的数据源图层ID数组

OnBar(ArrayRef<Integer>indexs)  

     {

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

     // 1. 成交量计算

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

         volAvg = Average(Vol, volLen);

         highVolCondition = Vol >= volAvg * highVolMult;

         lowVolCondition  = Vol <= volAvg * lowVolMult;

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

     // 2. ATR止盈止损计算

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

         atrValue = AvgTrueRange(atrLen);

         longStop  = Close - atrValue * slMult;

         longTP    = Close + atrValue * tpMult;

         shortStop = Close + atrValue * slMult;

         shortTP   = Close - atrValue * tpMult;

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

     // 3. 信号定义

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

         signalLong  = Close > Average(Close, volLen) and highVolCondition;

         signalShort = Close < Average(Close, volLen) and highVolCondition;

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

     // 4. 平仓逻辑

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

        If(lowVolCondition)

        {

            if(MarketPosition == 1 )

            {

                Sell(0, Open);

            }

            Else

                if (MarketPosition == -1 )

                {

                    BuyToCover(0, Open) ;

                }

        }

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

     // 5. 开仓逻辑(禁止双向)

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

         if (MarketPosition <= 0 and signalLong )

         {

             Buy(qty, Open);

         }

         Else

         if (MarketPosition >= 0 and signalShort )

         {

             SellShort(qty, Open);

         }

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

     // 6. 止盈止损(动态判断)

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

         if (MarketPosition == 1 And ((Low <= longStop)OR(High>=longTP)))

         {

             Sell(0, Open);

             }

         if (MarketPosition == -1 And ((High >= shortStop)OR (Low <= shortTP)))

         {

             BuyToCover(0,Open);

         }

     }

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

// 编译版本    2025/10/17 1396/1762/277

// 版权所有    jswxyfx

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

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

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

编译通过了,不知道是不是你所要的结果。

AI代码不考虑修改

王老师好,如可删除自己的贴子和评论