一个基于成交量与顶底分型的交易策略

松鼠Quant
2024-12-06

PS:12月6日本周五(19:30)年度直播2025俱乐部最新内容,非常豪华。不要错过抽大红包的环节,一定要来瞅瞅。加小松鼠微信,防丢失。

图片
扫码进入直播
参数可视化工具:点击进入

Ai帮你编写策略:点击进入

订单流图表:点击进入

图片

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

// 简称: VolumeAccumulationWithFenxingAndStop

// 名称: 成交量堆积与顶底分型及移动止损止盈策略

// 来源:松鼠QuantAi助手编写-https://ai.kanpan789.com/

// 类别: 公式应用

// 类型: 内建应用

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

Params    Numeric Length(10);   // 计算成交量堆积的周期    Numeric Threshold(2);   // 成交量堆积的阈值    Numeric LookBackPeriod(5); // 回看周期,用于判断顶底分型    Numeric StopLossPercent(0.02); // 初始止损百分比    Numeric TakeProfitPercent(0.05); // 初始止盈百分比    Numeric TrailingStopPercent(0.01); // 移动止损百分比    Numeric AmplitudeFilter(0.01); // 幅度过滤震荡百分比
Vars    Series<Numeric> VolumeAccumulation(0);   // 成交量堆积值    Series<Bool> BuySignal(False);   // 买入信号    Series<Bool> SellSignal(False);   // 卖出信号    Series<Numeric> IsTop;    // 是否为顶分型    Series<Numeric> IsBottom; // 是否为底分型    Series<Numeric> TopPrice; // 顶分型价格    Series<Numeric> BottomPrice; // 底分型价格    Series<Numeric> StopLossPrice; // 止损价格    Series<Numeric> TakeProfitPrice; // 止盈价格    Series<Numeric> TrailingStopPrice; // 移动止损价格    Series<Numeric> Amplitude; // 幅度
Events    OnBar(ArrayRef<Integer> indexs)    {// 计算成交量堆积        Numeric sumVol = 0;        Numeric i = 0;For i = 1 To Length        {            sumVol = sumVol + vol[i];        }        VolumeAccumulation = sumVol;
// 生成买入信号        BuySignal = VolumeAccumulation > Threshold * Average(vol, Length);
// 生成卖出信号        SellSignal = VolumeAccumulation < Threshold * Average(vol, Length);
// 判断顶分型If(High[1] > High[2] And High[1] > High[3] And High[1] > High[4] And High[1] > High[5])        {            IsTop = 1;            TopPrice = High[1];        }Else        {            IsTop = 0;        }// 来源:松鼠QuantAi助手编写-https://ai.kanpan789.com/
// 判断底分型If(Low[1] < Low[2] And Low[1] < Low[3] And Low[1] < Low[4] And Low[1] < Low[5])        {            IsBottom = 1;            BottomPrice = Low[1];        }Else        {            IsBottom = 0;        }
// 计算幅度        Amplitude = Abs(High - Low) / Close;
// 交易逻辑If (BuySignal[1] And IsBottom[1] > 0And MarketPosition == 0And Amplitude[1] > AmplitudeFilter)   // 如果前一根Bar出现买入信号且当前无持仓且为底分型且幅度大于过滤值        {            Buy(1, Open);   // 以开盘价买入1手            StopLossPrice = EntryPrice * (1 - StopLossPercent);            TakeProfitPrice = EntryPrice * (1 + TakeProfitPercent);            TrailingStopPrice = EntryPrice * (1 - TrailingStopPercent);        }// 来源:松鼠QuantAi助手编写-https://ai.kanpan789.com/
If (SellSignal[1] And IsTop[1] > 0And MarketPosition == 1And Amplitude[1] > AmplitudeFilter)   // 如果前一根Bar出现卖出信号且当前持有多头且为顶分型且幅度大于过滤值        {            Sell(1, Open);   // 以开盘价卖出1手        }
// 移动止损逻辑If (MarketPosition == 1And BarsSinceEntry > 0)        {            TrailingStopPrice = Max(TrailingStopPrice, Low * (1 - TrailingStopPercent));        }If (MarketPosition == -1And BarsSinceEntry > 0)        {            TrailingStopPrice = Min(TrailingStopPrice, High * (1 + TrailingStopPercent));        }
// 止盈止损逻辑If (MarketPosition == 1And BarsSinceEntry > 0)        {If (Low <= TrailingStopPrice)            {                Sell(1, Min(Open, TrailingStopPrice));   // 移动止损出场            }ElseIf (High >= TakeProfitPrice)            {                Sell(1, Max(Open, TakeProfitPrice));   // 止盈出场            }        }
// 输出信号        Commentary("VolumeAccumulation: " + text(VolumeAccumulation));        Commentary("IsTop: " + text(IsTop));        Commentary("TopPrice: " + text(TopPrice));        Commentary("IsBottom: " + text(IsBottom));        Commentary("BottomPrice: " + text(BottomPrice));        Commentary("StopLossPrice: " + text(StopLossPrice));        Commentary("TakeProfitPrice: " + text(TakeProfitPrice));        Commentary("TrailingStopPrice: " + text(TrailingStopPrice));        Commentary("Amplitude: " + text(Amplitude));    }

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

// 编译版本 GS2010.12.08// 版权所有 TradeBlazer Software 2003-2025

// 更改声明 TradeBlazer Software保留对TradeBlazer平台每一版本的TradeBlazer公式修改和重写的权利

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

// 由 Ai 生成的内容仅作为学习参考,不能保证正确性,不构成任何投资意见,风险自负。

图片

品种周期:30分钟,螺纹

策略说明

  1. 移动止损百分比 (TrailingStopPercent): 设置移动止损的百分比,用于动态调整止损价格。

  2. 移动止损价格 (TrailingStopPrice): 记录当前的移动止损价格。

策略逻辑

  • 买入条件: 当价格下跌到买入价格时,执行买入操作,且当前Bar的幅度大于设定的幅度过滤值。

  • 卖出条件: 当价格上涨到卖出价格时,执行卖出操作,且当前Bar的幅度大于设定的幅度过滤值。

  • 移动止损逻辑: 在持有多头仓位时,根据最低价动态调整移动止损价格;在持有空头仓位时,根据最高价动态调整移动止损价格。

  • 止盈止损逻辑: 当价格触及移动止损价格时,执行移动止损操作;当价格触及止盈价格时,执行止盈操作。

注意事项

  • 该策略适用于震荡市场,能够捕捉市场的短期波动。

  • 需要根据具体的市场情况调整参数,以达到最佳效果。

直播时间:12月06号(本周五晚19:30分)

内容:《松鼠年会&2025俱乐部内容展示》

非常豪华,多轮抽奖不要错过,加小松鼠参与抽奖!!!微信号:viquant01

图片


分享