You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Amibroker布林带突破策略修改问询:近7日突破且今日收涨买入

Modified Bollinger Band Breakout Strategy with Retest Condition

Got it, let's tweak your existing Amibroker strategy to meet your new buy requirement: triggering a buy only if there was a Bollinger Band upper breakout in the last 7 days, and today's close is higher than the breakout day's close.

Full Modified Code

SetOption("MaxOpenPositions", 20);
SetPositionSize(5, spsPercentOfEquity);

// Keep your original index filter logic
Index = Foreign("$XAO", "C", True);
IndexMA = MA(Index, 75);

// Keep your Bollinger Band calculations
BollyTop = BBandTop(C, 100, 3);
BollyBot = BBandBot(C, 100, 1);

// 1. Define the original upper-band breakout signal (to identify past breakouts)
OriginalBuySignal = C >= BollyTop;

// 2. Check if there was at least one breakout in the last 7 trading days (excludes today)
HasRecentBreakout = Exists(OriginalBuySignal, 1, 7);

// 3. Grab the closing price from the most recent breakout day
LastBreakoutClose = ValueWhen(OriginalBuySignal, C, 1);

// 4. New buy condition: combine index filter + recent breakout + higher close today
Buy = Index >= IndexMA AND HasRecentBreakout AND C > LastBreakoutClose;

// Keep your original sell logic
Sell = C <= BollyBot;

Key Changes Explained

  • OriginalBuySignal: We extracted your original breakout condition into a separate variable to easily reference past breakout events without repeating code.
  • HasRecentBreakout: Uses Amibroker's Exists() function to check if the original breakout signal fired at least once in the last 7 days (the 1,7 range means we look 1 to 7 bars back — yesterday through 7 trading days ago — so we don't count today's potential breakout).
  • LastBreakoutClose: Uses ValueWhen() to pull the closing price from the most recent day the original breakout signal triggered. The 1 parameter ensures we get the latest breakout price, not older ones in the 7-day window.
  • New Buy Condition: Combines three core requirements: your original index trend filter, confirmation of a recent breakout, and today's close being higher than the breakout day's close (to validate a follow-through upward move).

Optional Tweaks

  • If you want to check against the highest close of all breakouts in the last 7 days instead of just the most recent one, replace LastBreakoutClose with:
    LastBreakoutClose = Highest(ValueWhen(OriginalBuySignal, C, 0), 7);
    
  • If you want to include today in the "last 7 days" breakout check, adjust the Exists() range to 0,7.

内容的提问来源于stack exchange,提问作者Dave Barker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 06:32:21