20250828加减仓模型附代码
//------------------------------------------------------------------------
// 简称: new2
// 名称:
// 类别: 策略应用
// 类型: 用户应用
// 输出: Void
//------------------------------------------------------------------------
Params
    integer add_set(10);
    integer minus_set(10);
    integer add_limit(10);
    
Vars
    Series<Numeric> h4w;
    Series<Numeric> l4w;
    Series<Numeric> my_last_entry_price;
    
Defs
    //此处添加策略函数
    
Events
    //此处实现事件函数
    
    //初始化事件函数,策略运行期间,首先运行且只有一次
    OnInit()
    {
    
    }
    
    
    //Bar更新事件函数,参数indexs表示变化的数据源图层ID数组
    OnBar(ArrayRef<Integer> indexs)
    {
        h4w = Highest(high[1], 20);
        l4w = lowest(low[1], 20);
        PlotNumeric("h4w", h4w);
        PlotNumeric("l4w", l4w);
    
        If(MarketPosition<>1 and high >= h4w)
        {
            buy(1, max(open, h4w));
            my_last_entry_price = max(open, h4w);
            Commentary("第一次开仓");
        }
    
        Numeric i;
    
        for i = 0 to 124
        {
            If(MarketPosition == 1 and CurrentEntries < add_limit && high >= my_last_entry_price + add_set *MinMove * PriceScale)
            {
                buy(1, max(open, my_last_entry_price + add_set * MinMove * PriceScale));
                my_last_entry_price = max(open, my_last_entry_price + add_set * MinMove * PriceScale);
                Commentary("加仓");
            }
            If(date+time == 20250822.2100) print(text(i));
            If(high<my_last_entry_price + add_set *MinMove * PriceScale) break;
        }
    
        /*While(CurrentEntries < add_limit && high>=my_last_entry_price+add_set*MinMove*PriceScale)     // 加仓
        {
            buy(1, max(open, my_last_entry_price+add_set*MinMove*PriceScale));
            my_last_entry_price = max(open, my_last_entry_price+add_set*MinMove*PriceScale);
        }*/
        While(MarketPosition==1 && BarsSinceEntry>=1 and  low<=my_last_entry_price-minus_set*MinMove*PriceScale)     // 加仓
        {
            sell(1, min(open, my_last_entry_price-minus_set*MinMove*PriceScale));
            my_last_entry_price = min(open, my_last_entry_price-minus_set*MinMove*PriceScale);
        }
    
        If(MarketPosition == 1 and low <= l4w)
        {
            sell(0, min(open, l4w));
        }
    }
    
//------------------------------------------------------------------------
// 编译版本    2025/8/28 154226
// 版权所有    kyover
// 更改声明    TradeBlazer Software保留对TradeBlazer平台
//            每一版本的TradeBlazer策略修改和重写的权利
//------------------------------------------------------------------------


加减仓
如果只写一个资金管理的加减仓策略,开仓人工下单,tbquant满足加减仓条件会执行吗?
根据上一笔交易盈亏决定是否加减仓
多周期的仓位怎么加减仓?
云条件单:如何根据仓位设置加减仓
模型策略开仓后的持仓手数
分组指令模型手数在代码里怎么写
模型设置开仓一手,怎么样才能允许每个品种开仓一手?
帮忙编写代码
学习使用tbquant3 遇到的小问题 截图说明 (附策略代码)

请教刘风老师,昨天讲的“20250828加减仓模型附代码”,能不能编写一个完整量化交易源码策略

这不就是完整的么?要怎么完整?

上面只有买开平,卖开平没有

可以自己动动脑子改一下无非就是大于小于兑换,加减号兑换,buysell命令兑换

我哪里写错了?为什么有人说没有加仓部分?没有减仓部分?

直播的时候不是根据代码把加减仓信号都检查验证过了?

????

加载试了 没有问题

难道说的是这个?

😅