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