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策略修改和重写的权利 //------------------------------------------------------------------------

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

回复:这不就是完整的么?要怎么完整?

回复:上面只有买开平,卖开平没有

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

我哪里写错了?为什么有人说没有加仓部分?没有减仓部分?直播的时候不是根据代码把加减仓信号都检查验证过了?????

回复:加载试了 没有问题难道说的是这个?

回复:😅