“CGZ-Smart Money Concepts” 智能资金概念
“CGZ-Smart Money Concepts” 是一个基于智能资金概念(Smart Money Concepts, SMC)的技术指标,主要用于识别市场结构、订单块、公平价值缺口(FVG)、等高/等低点以及溢价/折扣区域等关键交易信息。它可以帮助交易者理解机构资金的潜在行为,从而制定更有效的交易策略。以下是如何使用此指标指导交易的详细中文说明:
一、指标核心功能及交易意义
市场结构(Swing Structure & Internal Structure)
突破结构(BOS):表示趋势延续,多头BOS提示买入机会,空头BOS提示卖出机会。
结构变化(CHoCH):表示趋势反转,多头CHoCH提示可能的反转买入,空头CHoCH提示可能的反转卖出。
交易应用:关注 BOS 和 CHoCH 的出现,结合趋势方向判断入场时机。例如,多头BOS后价格回撤到支撑位可考虑做多。
订单块(Order Blocks)
定义:订单块是机构资金可能聚集的区域,通常是未被完全消耗的供需区。
多头订单块(Bullish OB):价格回撤至此区域可能是买入机会。
空头订单块(Bearish OB):价格反弹至此区域可能是卖出机会。
交易应用:等待价格回撤到订单块区域,观察是否有反转信号(如K线形态或成交量放大)再入场。
公平价值缺口(Fair Value Gaps, FVG)
定义:价格快速移动留下的未填充区域,通常会被市场回填。
多头FVG:价格可能回撤至此区域后上涨,适合买入。
空头FVG:价格可能反弹至此区域后下跌,适合卖出。
交易应用:将FVG作为潜在目标或支撑/阻力位,结合其他信号确认交易方向。
等高/等低点(EQH/EQL)
定义:价格多次触及的高低点,表示潜在的阻力或支撑。
交易应用:在EQH附近寻找卖出机会,在EQL附近寻找买入机会,注意突破或假突破的可能性。
强弱高低点(Strong/Weak Highs & Lows)
强高/低点:趋势方向一致的高低点,适合顺势交易。
弱高/低点:趋势反向的高低点,可能预示反转。
交易应用:强高点可作为卖出止盈目标,强低点可作为买入支撑。
溢价/折扣区域(Premium/Discount Zones)
溢价区域:价格高于均衡,可能被视为高估,适合卖出。
折扣区域:价格低于均衡,可能被视为低估,适合买入。
交易应用:在折扣区域寻找买入机会,在溢价区域寻找卖出机会。
多时间框架水平线(Daily/Weekly/Monthly Levels)
定义:高时间框架的高低点,作为重要的支撑和阻力。
交易应用:结合当前时间框架的信号,在这些水平附近寻找高概率交易机会。
二、交易策略示例
以下是基于此指标的具体交易策略:
- 趋势跟随策略(BOS + Order Blocks)
条件:
出现多头BOS,趋势偏多。
价格回撤至多头订单块,且未被突破。
入场:
在订单块区域观察K线反转信号(如看涨吞没形态)。
设置止损在订单块下方。
出场:
目标设为最近的强高点或溢价区域。
反向示例:空头BOS + 空头订单块,卖出操作类似。 - 反转交易策略(CHoCH + FVG)
条件:
出现空头CHoCH,趋势可能反转为下跌。
价格反弹至空头FVG区域。
入场:
在FVG区域观察看跌信号(如Pin Bar或射击之星)。
设置止损在FVG上方。
出场:
目标设为最近的强低点或折扣区域。
反向示例:多头CHoCH + 多头FVG,买入操作类似。 - 区间交易策略(EQH/EQL + Premium/Discount Zones)
条件:
价格在EQH和EQL之间震荡,未出现明确BOS或CHoCH。
当前价格处于溢价或折扣区域。
入场:
在折扣区域靠近EQL买入,在溢价区域靠近EQH卖出。
设置止损在EQH/EQL之外。
出场:
目标设为均衡区域或对侧的EQH/EQL。 - 多时间框架确认策略
条件:
日线或周线级别的高低点与当前时间框架的订单块或FVG重合。
入场:
在重合区域等待当前时间框架的BOS或CHoCH信号。
确认K线形态后入场,止损设在重合区域外。
出场:
目标设为更高时间框架的下一个关键水平。
三、使用指标的步骤
设置时间框架:
根据交易风格选择合适的时间框架(短线用1分钟-15分钟,中线用1小时-4小时,长线用日线-周线)。
启用多时间框架水平线(如日线、周线)以获得更大背景。
调整输入参数:
Mode:选择“历史”查看完整结构,或“当前”仅关注最新信号。
Style:选择“彩色”或“单色”以适应视觉偏好。
Swings Length:调整波段检测的长度(默认50),短线可减少,长线可增加。
Order Blocks Size:设置显示的订单块数量(默认5),根据屏幕大小调整。
FVG Timeframe:设置公平价值缺口的时间框架,短线可留空,长线可设为更高周期。
观察关键区域:
在图表上识别BOS、CHoCH、订单块、FVG等。
注意价格是否接近EQH/EQL或溢价/折扣区域。
结合其他工具:
使用成交量指标确认订单块的有效性。
使用RSI或MACD确认趋势强度或超买/超卖状态。
制定交易计划:
根据上述策略选择入场点、止损点和止盈点。
设置警报(Alerts)以监控关键事件(如BOS、CHoCH、订单块突破)。
四、注意事项
风险管理:
每次交易风险控制在账户的1-2%,止损必须明确设置。
避免在高波动时段(如重要经济数据发布)盲目交易。
市场条件:
趋势市场适合BOS和订单块策略,震荡市场适合FVG和EQH/EQL策略。
在流动性低的市场(如周末外汇市场)谨慎使用。
验证信号:
单一信号可能不可靠,建议等待多重确认(如订单块+FVG+支撑位)。
回测策略在历史数据上的表现,确保适应当前市场。
耐心等待:
SMC策略依赖机构资金行为,信号可能不频繁,需等待高概率机会。
五、示例交易场景
场景:EUR/USD 1小时图
观察:出现多头BOS,价格回撤至多头订单块(1.0800),同时接近日线支撑(1.0790)和折扣区域。
入场:在1.0800看到看涨Pin Bar,买入,止损设在1.0780。
出场:目标设为最近强高点1.0850(溢价区域)。
结果:价格上涨至1.0850,获利50点。
总结
“CGZ-Smart Money Concepts”指标通过可视化市场结构和关键区域,帮助你捕捉机构资金的潜在意图。核心是识别高概率的供需区域(订单块、FVG)和趋势信号(BOS、CHoCH),结合多时间框架分析制定交易计划。建议从模拟账户开始,熟悉指标的信号并优化策略,逐步应用到实盘交易中。//@version=6 indicator('CGZ-Smart Money Concepts', 'CGZ-智能资金概念', overlay = true, max_labels_count = 500, max_lines_count = 500, max_boxes_count = 500) //---------------------------------------------------------------------------------------------------------------------} //常量 & 字符串 & 输入项 //---------------------------------------------------------------------------------------------------------------------{ BULLISH_LEG = 1 // 多头阶段 BEARISH_LEG = 0 // 空头阶段
BULLISH = +1 // 多头趋势
BEARISH = -1 // 空头趋势
GREEN = #089981 // 绿色
RED = #F23645 // 红色
BLUE = #2157f3 // 蓝色
GRAY = #878b94 // 灰色
MONO_BULLISH = #b2b5be // 单色多头
MONO_BEARISH = #5d606b // 单色空头
HISTORICAL = '历史' // 历史模式
PRESENT = '当前' // 当前模式
COLORED = '彩色' // 彩色主题
MONOCHROME = '单色' // 单色主题
ALL = '全部' // 全部显示
BOS = '突破结构' // Break of Structure
CHOCH = '结构变化' // Change of Character
TINY = size.tiny // 微小尺寸
SMALL = size.small // 小尺寸
NORMAL = size.normal // 正常尺寸
ATR = '平均真实波幅' // Atr
RANGE = '累计平均范围' // Cumulative Mean Range
CLOSE = '收盘价' // Close
HIGHLOW = '高/低点' // High/Low
SOLID = '⎯⎯⎯' // 实线
DASHED = '----' // 虚线
DOTTED = '····' // 点线
SMART_GROUP = '智能资金概念'
INTERNAL_GROUP = '实时内部结构'
SWING_GROUP = '实时波段结构'
BLOCKS_GROUP = '订单块'
EQUAL_GROUP = '等高/等低'
GAPS_GROUP = '公平价值缺口'
LEVELS_GROUP = '多时间框架高低点'
ZONES_GROUP = '溢价 & 折扣区域'
// 输入项的工具提示(中文)
modeTooltip = '允许显示历史结构或仅显示近期结构'
styleTooltip = '指标颜色主题'
showTrendTooltip = '显示反映当前趋势的额外K线颜色'
showInternalsTooltip = '显示内部市场结构'
internalFilterConfluenceTooltip = '过滤不重要的内部结构突破'
showStructureTooltip = '显示波段市场结构'
showSwingsTooltip = '在图表上以标签显示波段点'
showHighLowSwingsTooltip = '高亮显示最近的强弱高/低点'
showInternalOrderBlocksTooltip = '在图表上显示内部订单块\n\n显示的内部订单块数量'
showSwingOrderBlocksTooltip = '在图表上显示波段订单块\n\n显示的波段订单块数量'
orderBlockFilterTooltip = '过滤高波动订单块的方法\n\n当数据量少时建议使用累计平均范围方法'
orderBlockMitigationTooltip = '选择用于订单块缓解的值'
showEqualHighsLowsTooltip = '显示等高和等低点'
equalHighsLowsLengthTooltip = '确认等高和等低的K线数量'
equalHighsLowsThresholdTooltip = '检测等高和等低的敏感度阈值(0-1范围)\n\n较低值返回更少但更相关的结果'
showFairValueGapsTooltip = '在图表上显示公平价值缺口'
fairValueGapsThresholdTooltip = '过滤不重要的公平价值缺口'
fairValueGapsTimeframeTooltip = '公平价值缺口时间框架'
fairValueGapsExtendTooltip = '确定公平价值缺口框在图表上延伸的K线数量'
showPremiumDiscountZonesTooltip = '在图表上显示溢价、折扣和均衡区域'
// 输入项定义
modeInput = input.string( HISTORICAL, '模式', group = SMART_GROUP, tooltip = modeTooltip, options = [HISTORICAL, PRESENT])
styleInput = input.string( COLORED, '样式', group = SMART_GROUP, tooltip = styleTooltip,options = [COLORED, MONOCHROME])
showTrendInput = input.bool( false, 'K线着色', group = SMART_GROUP, tooltip = showTrendTooltip)
showInternalsInput = input.bool( true, '显示内部结构', group = INTERNAL_GROUP, tooltip = showInternalsTooltip)
showInternalBullInput = input.string( ALL, '多头结构', group = INTERNAL_GROUP, inline = 'ibull', options = [ALL,BOS,CHOCH])
internalBullColorInput = input.color( GREEN, '', group = INTERNAL_GROUP, inline = 'ibull')
showInternalBearInput = input.string( ALL, '空头结构' , group = INTERNAL_GROUP, inline = 'ibear', options = [ALL,BOS,CHOCH])
internalBearColorInput = input.color( RED, '', group = INTERNAL_GROUP, inline = 'ibear')
internalFilterConfluenceInput = input.bool( false, '汇合过滤', group = INTERNAL_GROUP, tooltip = internalFilterConfluenceTooltip)
internalStructureSize = input.string( TINY, '内部标签尺寸', group = INTERNAL_GROUP, options = [TINY,SMALL,NORMAL])
showStructureInput = input.bool( true, '显示波段结构', group = SWING_GROUP, tooltip = showStructureTooltip)
showSwingBullInput = input.string( ALL, '多头结构', group = SWING_GROUP, inline = 'bull', options = [ALL,BOS,CHOCH])
swingBullColorInput = input.color( GREEN, '', group = SWING_GROUP, inline = 'bull')
showSwingBearInput = input.string( ALL, '空头结构', group = SWING_GROUP, inline = 'bear', options = [ALL,BOS,CHOCH])
swingBearColorInput = input.color( RED, '', group = SWING_GROUP, inline = 'bear')
swingStructureSize = input.string( SMALL, '波段标签尺寸', group = SWING_GROUP, options = [TINY,SMALL,NORMAL])
showSwingsInput = input.bool( false, '显示波段点', group = SWING_GROUP, tooltip = showSwingsTooltip,inline = 'swings')
swingsLengthInput = input.int( 50, '', group = SWING_GROUP, minval = 10, inline = 'swings')
showHighLowSwingsInput = input.bool( true, '显示强弱高/低点',group = SWING_GROUP, tooltip = showHighLowSwingsTooltip)
showInternalOrderBlocksInput = input.bool( true, '内部订单块' , group = BLOCKS_GROUP, tooltip = showInternalOrderBlocksTooltip, inline = 'iob')
internalOrderBlocksSizeInput = input.int( 5, '', group = BLOCKS_GROUP, minval = 1, maxval = 20, inline = 'iob')
showSwingOrderBlocksInput = input.bool( false, '波段订单块', group = BLOCKS_GROUP, tooltip = showSwingOrderBlocksTooltip, inline = 'ob')
swingOrderBlocksSizeInput = input.int( 5, '', group = BLOCKS_GROUP, minval = 1, maxval = 20, inline = 'ob')
orderBlockFilterInput = input.string('平均真实波幅', '订单块过滤', group = BLOCKS_GROUP, tooltip = orderBlockFilterTooltip, options = [ATR, RANGE])
orderBlockMitigationInput = input.string( HIGHLOW, '订单块缓解', group = BLOCKS_GROUP, tooltip = orderBlockMitigationTooltip, options = [CLOSE,HIGHLOW])
internalBullishOrderBlockColor = input.color(color.new(#3179f5, 80), '内部多头订单块', group = BLOCKS_GROUP)
internalBearishOrderBlockColor = input.color(color.new(#f77c80, 80), '内部空头订单块', group = BLOCKS_GROUP)
swingBullishOrderBlockColor = input.color(color.new(#1848cc, 80), '多头订单块', group = BLOCKS_GROUP)
swingBearishOrderBlockColor = input.color(color.new(#b22833, 80), '空头订单块', group = BLOCKS_GROUP)
showEqualHighsLowsInput = input.bool( true, '等高/等低', group = EQUAL_GROUP, tooltip = showEqualHighsLowsTooltip)
equalHighsLowsLengthInput = input.int( 3, '确认K线数', group = EQUAL_GROUP, tooltip = equalHighsLowsLengthTooltip, minval = 1)
equalHighsLowsThresholdInput = input.float( 0.1, '阈值', group = EQUAL_GROUP, tooltip = equalHighsLowsThresholdTooltip, minval = 0, maxval = 0.5, step = 0.1)
equalHighsLowsSizeInput = input.string( TINY, '标签尺寸', group = EQUAL_GROUP, options = [TINY,SMALL,NORMAL])
showFairValueGapsInput = input.bool( false, '公平价值缺口', group = GAPS_GROUP, tooltip = showFairValueGapsTooltip)
fairValueGapsThresholdInput = input.bool( true, '自动阈值', group = GAPS_GROUP, tooltip = fairValueGapsThresholdTooltip)
fairValueGapsTimeframeInput = input.timeframe('', '时间框架', group = GAPS_GROUP, tooltip = fairValueGapsTimeframeTooltip)
fairValueGapsBullColorInput = input.color(color.new(#00ff68, 70), '多头FVG' , group = GAPS_GROUP)
fairValueGapsBearColorInput = input.color(color.new(#ff0008, 70), '空头FVG' , group = GAPS_GROUP)
fairValueGapsExtendInput = input.int( 1, 'FVG延伸', group = GAPS_GROUP, tooltip = fairValueGapsExtendTooltip, minval = 0)
showDailyLevelsInput = input.bool( false, '日线', group = LEVELS_GROUP, inline = 'daily')
dailyLevelsStyleInput = input.string( SOLID, '', group = LEVELS_GROUP, inline = 'daily', options = [SOLID,DASHED,DOTTED])
dailyLevelsColorInput = input.color( BLUE, '', group = LEVELS_GROUP, inline = 'daily')
showWeeklyLevelsInput = input.bool( false, '周线', group = LEVELS_GROUP, inline = 'weekly')
weeklyLevelsStyleInput = input.string( SOLID, '', group = LEVELS_GROUP, inline = 'weekly', options = [SOLID,DASHED,DOTTED])
weeklyLevelsColorInput = input.color( BLUE, '', group = LEVELS_GROUP, inline = 'weekly')
showMonthlyLevelsInput = input.bool( false, '月线', group = LEVELS_GROUP, inline = 'monthly')
monthlyLevelsStyleInput = input.string( SOLID, '', group = LEVELS_GROUP, inline = 'monthly', options = [SOLID,DASHED,DOTTED])
monthlyLevelsColorInput = input.color( BLUE, '', group = LEVELS_GROUP, inline = 'monthly')
showPremiumDiscountZonesInput = input.bool( false, '溢价/折扣区域', group = ZONES_GROUP , tooltip = showPremiumDiscountZonesTooltip)
premiumZoneColorInput = input.color( RED, '溢价区域', group = ZONES_GROUP)
equilibriumZoneColorInput = input.color( GRAY, '均衡区域', group = ZONES_GROUP)
discountZoneColorInput = input.color( GREEN, '折扣区域', group = ZONES_GROUP)
//---------------------------------------------------------------------------------------------------------------------}
//数据结构 & 变量
//---------------------------------------------------------------------------------------------------------------------{
// 警报类型定义
type alerts
bool internalBullishBOS = false // 内部多头BOS警报
bool internalBearishBOS = false // 内部空头BOS警报
bool internalBullishCHoCH = false // 内部多头CHoCH警报
bool internalBearishCHoCH = false // 内部空头CHoCH警报
bool swingBullishBOS = false // 波段多头BOS警报
bool swingBearishBOS = false // 波段空头BOS警报
bool swingBullishCHoCH = false // 波段多头CHoCH警报
bool swingBearishCHoCH = false // 波段空头CHoCH警报
bool internalBullishOrderBlock = false // 内部多头订单块警报
bool internalBearishOrderBlock = false // 内部空头订单块警报
bool swingBullishOrderBlock = false // 波段多头订单块警报
bool swingBearishOrderBlock = false // 波段空头订单块警报
bool equalHighs = false // 等高警报
bool equalLows = false // 等低警报
bool bullishFairValueGap = false // 多头公平价值缺口警报
bool bearishFairValueGap = false // 空头公平价值缺口警报
// 波段极值类型定义
type trailingExtremes
float top // 上方极值价格
float bottom // 下方极值价格
int barTime // 极值K线时间
int barIndex // 极值K线索引
int lastTopTime // 最后上方极值时间
int lastBottomTime // 最后下方极值时间
// 公平价值缺口类型定义
type fairValueGap
float top // 上方价格
float bottom // 下方价格
int bias // 方向(多头或空头)
box topBox // 上方框
box bottomBox // 下方框
// 趋势类型定义
type trend
int bias // 趋势方向(多头或空头)
// 等高/等低显示类型定义
type equalDisplay
line l_ine = na // 显示线
label l_abel = na // 显示标签
// 枢轴点类型定义
type pivot
float currentLevel // 当前价格水平
float lastLevel // 上次价格水平
bool crossed // 是否被穿越
int barTime = time // K线时间
int barIndex = bar_index // K线索引
// 订单块类型定义
type orderBlock
float barHigh // K线最高价
float barLow // K线最低价
int barTime // K线时间
int bias // 方向(多头或空头)
// 变量声明
var pivot swingHigh = pivot.new(na,na,false) // 当前波段高点
var pivot swingLow = pivot.new(na,na,false) // 当前波段低点
var pivot internalHigh = pivot.new(na,na,false) // 当前内部高点
var pivot internalLow = pivot.new(na,na,false) // 当前内部低点
var pivot equalHigh = pivot.new(na,na,false) // 当前等高点
var pivot equalLow = pivot.new(na,na,false) // 当前等低点
var trend swingTrend = trend.new(0) // 波段趋势
var trend internalTrend = trend.new(0) // 内部趋势
var equalDisplay equalHighDisplay = equalDisplay.new() // 等高显示
var equalDisplay equalLowDisplay = equalDisplay.new() // 等低显示
var array
var array
var array
var array
var array
var array
var trailingExtremes trailing = trailingExtremes.new() // 跟踪极值
var array
var array
var array
var array
var swingBullishColor = styleInput == MONOCHROME ? MONO_BULLISH : swingBullColorInput // 波段多头颜色
var swingBearishColor = styleInput == MONOCHROME ? MONO_BEARISH : swingBearColorInput // 波段空头颜色
var fairValueGapBullishColor = styleInput == MONOCHROME ? color.new(MONO_BULLISH,70) : fairValueGapsBullColorInput // 多头FVG颜色
var fairValueGapBearishColor = styleInput == MONOCHROME ? color.new(MONO_BEARISH,70) : fairValueGapsBearColorInput // 空头FVG颜色
var premiumZoneColor = styleInput == MONOCHROME ? MONO_BEARISH : premiumZoneColorInput // 溢价区域颜色
var discountZoneColor = styleInput == MONOCHROME ? MONO_BULLISH : discountZoneColorInput // 折扣区域颜色
varip int currentBarIndex = bar_index // 当前K线索引
varip int lastBarIndex = bar_index // 上次K线索引
alerts currentAlerts = alerts.new() // 当前警报
var initialTime = time // 图表起始时间
// 初始化订单块框
if barstate.isfirst
if showSwingOrderBlocksInput
for index = 1 to swingOrderBlocksSizeInput
swingOrderBlocksBoxes.push(box.new(na,na,na,na,xloc = xloc.bar_time,extend = extend.right))
if showInternalOrderBlocksInput
for index = 1 to internalOrderBlocksSizeInput
internalOrderBlocksBoxes.push(box.new(na,na,na,na,xloc = xloc.bar_time,extend = extend.right))
bearishOrderBlockMitigationSource = orderBlockMitigationInput == CLOSE ? close : high // 空头订单块缓解源
bullishOrderBlockMitigationSource = orderBlockMitigationInput == CLOSE ? close : low // 多头订单块缓解源
atrMeasure = ta.atr(200) // 默认波动率测量
volatilityMeasure = orderBlockFilterInput == ATR ? atrMeasure : ta.cum(ta.tr)/bar_index // 用户设置的波动率测量
highVolatilityBar = (high - low) >= (2 * volatilityMeasure) // 高波动K线判断
parsedHigh = highVolatilityBar ? low : high // 已解析高点
parsedLow = highVolatilityBar ? high : low // 已解析低点
parsedHighs.push(parsedHigh) // 存储当前值到数组
parsedLows.push(parsedLow)
highs.push(high)
lows.push(low)
times.push(time)
//---------------------------------------------------------------------------------------------------------------------}
//用户自定义函数
//---------------------------------------------------------------------------------------------------------------------{
// 获取当前阶段值(0为熊市,1为牛市)
leg(int size) =>
var leg = 0
newLegHigh = high[size] > ta.highest(size)
newLegLow = low[size] < ta.lowest(size)
if newLegHigh
leg := BEARISH_LEG
else if newLegLow
leg := BULLISH_LEG
leg
// 判断是否为新阶段起点
startOfNewLeg(int leg) => ta.change(leg) != 0
// 判断是否为新空头阶段起点
startOfBearishLeg(int leg) => ta.change(leg) == -1
// 判断是否为新多头阶段起点
startOfBullishLeg(int leg) => ta.change(leg) == +1
// 创建新标签
drawLabel(int labelTime, float labelPrice, string tag, color labelColor, string labelStyle) =>
var label l_abel = na
if modeInput == PRESENT
l_abel.delete()
l_abel := label.new(chart.point.new(labelTime,na,labelPrice),tag,xloc.bar_time,color=color(na),textcolor=labelColor,style = labelStyle,size = size.small)
// 创建并显示等高/等低线和标签
drawEqualHighLow(pivot p_ivot, float level, int size, bool equalHigh) =>
equalDisplay e_qualDisplay = equalHigh ? equalHighDisplay : equalLowDisplay
string tag = '等低'
color equalColor = swingBullishColor
string labelStyle = label.style_label_up
if equalHigh
tag := '等高'
equalColor := swingBearishColor
labelStyle := label.style_label_down
if modeInput == PRESENT
line.delete( e_qualDisplay.l_ine)
label.delete( e_qualDisplay.l_abel)
e_qualDisplay.l_ine := line.new(chart.point.new(p_ivot.barTime,na,p_ivot.currentLevel), chart.point.new(time[size],na,level), xloc = xloc.bar_time, color = equalColor, style = line.style_dotted)
labelPosition = math.round(0.5*(p_ivot.barIndex + bar_index - size))
e_qualDisplay.l_abel := label.new(chart.point.new(na,labelPosition,level), tag, xloc.bar_index, color = color(na), textcolor = equalColor, style = labelStyle, size = equalHighsLowsSizeInput)
// 获取当前结构并存储波段点
getCurrentStructure(int size,bool equalHighLow = false, bool internal = false) =>
currentLeg = leg(size)
newPivot = startOfNewLeg(currentLeg)
pivotLow = startOfBullishLeg(currentLeg)
pivotHigh = startOfBearishLeg(currentLeg)
if newPivot
if pivotLow
pivot p_ivot = equalHighLow ? equalLow : internal ? internalLow : swingLow
if equalHighLow and math.abs(p_ivot.currentLevel - low[size]) < equalHighsLowsThresholdInput * atrMeasure
drawEqualHighLow(p_ivot, low[size], size, false)
p_ivot.lastLevel := p_ivot.currentLevel
p_ivot.currentLevel := low[size]
p_ivot.crossed := false
p_ivot.barTime := time[size]
p_ivot.barIndex := bar_index[size]
if not equalHighLow and not internal
trailing.bottom := p_ivot.currentLevel
trailing.barTime := p_ivot.barTime
trailing.barIndex := p_ivot.barIndex
trailing.lastBottomTime := p_ivot.barTime
if showSwingsInput and not internal and not equalHighLow
drawLabel(time[size], p_ivot.currentLevel, p_ivot.currentLevel < p_ivot.lastLevel ? '低低' : '高低', swingBullishColor, label.style_label_up)
else
pivot p_ivot = equalHighLow ? equalHigh : internal ? internalHigh : swingHigh
if equalHighLow and math.abs(p_ivot.currentLevel - high[size]) < equalHighsLowsThresholdInput * atrMeasure
drawEqualHighLow(p_ivot,high[size],size,true)
p_ivot.lastLevel := p_ivot.currentLevel
p_ivot.currentLevel := high[size]
p_ivot.crossed := false
p_ivot.barTime := time[size]
p_ivot.barIndex := bar_index[size]
if not equalHighLow and not internal
trailing.top := p_ivot.currentLevel
trailing.barTime := p_ivot.barTime
trailing.barIndex := p_ivot.barIndex
trailing.lastTopTime := p_ivot.barTime
if showSwingsInput and not internal and not equalHighLow
drawLabel(time[size], p_ivot.currentLevel, p_ivot.currentLevel > p_ivot.lastLevel ? '高高' : '低高', swingBearishColor, label.style_label_down)
// 绘制结构线和标签
drawStructure(pivot p_ivot, string tag, color structureColor, string lineStyle, string labelStyle, string labelSize) =>
var line l_ine = line.new(na,na,na,na,xloc = xloc.bar_time)
var label l_abel = label.new(na,na)
if modeInput == PRESENT
l_ine.delete()
l_abel.delete()
l_ine := line.new(chart.point.new(p_ivot.barTime,na,p_ivot.currentLevel), chart.point.new(time,na,p_ivot.currentLevel), xloc.bar_time, color=structureColor, style=lineStyle)
l_abel := label.new(chart.point.new(na,math.round(0.5*(p_ivot.barIndex+bar_index)),p_ivot.currentLevel), tag, xloc.bar_index, color=color(na), textcolor=structureColor, style=labelStyle, size = labelSize)
// 删除订单块
deleteOrderBlocks(bool internal = false) =>
array
for [index,eachOrderBlock] in orderBlocks
bool crossedOderBlock = false
if bearishOrderBlockMitigationSource > eachOrderBlock.barHigh and eachOrderBlock.bias == BEARISH
crossedOderBlock := true
if internal
currentAlerts.internalBearishOrderBlock := true
else
currentAlerts.swingBearishOrderBlock := true
else if bullishOrderBlockMitigationSource < eachOrderBlock.barLow and eachOrderBlock.bias == BULLISH
crossedOderBlock := true
if internal
currentAlerts.internalBullishOrderBlock := true
else
currentAlerts.swingBullishOrderBlock := true
if crossedOderBlock
orderBlocks.remove(index)
// 存储订单块
storeOrdeBlock(pivot p_ivot,bool internal = false,int bias) =>
if (not internal and showSwingOrderBlocksInput) or (internal and showInternalOrderBlocksInput)
array<float> a_rray = na
int parsedIndex = na
if bias == BEARISH
a_rray := parsedHighs.slice(p_ivot.barIndex,bar_index)
parsedIndex := p_ivot.barIndex + array.indexof(a_rray,array.max(a_rray))
else
a_rray := parsedLows.slice(p_ivot.barIndex,bar_index)
parsedIndex := p_ivot.barIndex + array.indexof(a_rray,array.min(a_rray))
orderBlock o_rderBlock = orderBlock.new(parsedHighs.get(parsedIndex), parsedLows.get(parsedIndex), times.get(parsedIndex),bias)
array<orderBlock> orderBlocks = internal ? internalOrderBlocks : swingOrderBlocks
if orderBlocks.size() >= 100
orderBlocks.pop()
orderBlocks.unshift(o_rderBlock)
// 绘制订单块框
drawOrderBlocks(bool internal = false) =>
array
orderBlocksSize = orderBlocks.size()
if orderBlocksSize > 0
maxOrderBlocks = internal ? internalOrderBlocksSizeInput : swingOrderBlocksSizeInput
array<orderBlock> parsedOrdeBlocks = orderBlocks.slice(0, math.min(maxOrderBlocks,orderBlocksSize))
array<box> b_oxes = internal ? internalOrderBlocksBoxes : swingOrderBlocksBoxes
for [index,eachOrderBlock] in parsedOrdeBlocks
orderBlockColor = styleInput == MONOCHROME ? (eachOrderBlock.bias == BEARISH ? color.new(MONO_BEARISH,80) : color.new(MONO_BULLISH,80)) : internal ? (eachOrderBlock.bias == BEARISH ? internalBearishOrderBlockColor : internalBullishOrderBlockColor) : (eachOrderBlock.bias == BEARISH ? swingBearishOrderBlockColor : swingBullishOrderBlockColor)
box b_ox = b_oxes.get(index)
b_ox.set_top_left_point( chart.point.new(eachOrderBlock.barTime,na,eachOrderBlock.barHigh))
b_ox.set_bottom_right_point(chart.point.new(last_bar_time,na,eachOrderBlock.barLow))
b_ox.set_border_color( internal ? na : orderBlockColor)
b_ox.set_bgcolor( orderBlockColor)
// 检测并显示结构及订单块
displayStructure(bool internal = false) =>
var bullishBar = true
var bearishBar = true
if internalFilterConfluenceInput
bullishBar := high - math.max(close, open) > math.min(close, open - low)
bearishBar := high - math.max(close, open) < math.min(close, open - low)
pivot p_ivot = internal ? internalHigh : swingHigh
trend t_rend = internal ? internalTrend : swingTrend
lineStyle = internal ? line.style_dashed : line.style_solid
labelSize = internal ? internalStructureSize : swingStructureSize
extraCondition = internal ? internalHigh.currentLevel != swingHigh.currentLevel and bullishBar : true
bullishColor = styleInput == MONOCHROME ? MONO_BULLISH : internal ? internalBullColorInput : swingBullColorInput
if ta.crossover(close,p_ivot.currentLevel) and not p_ivot.crossed and extraCondition
string tag = t_rend.bias == BEARISH ? CHOCH : BOS
if internal
currentAlerts.internalBullishCHoCH := tag == CHOCH
currentAlerts.internalBullishBOS := tag == BOS
else
currentAlerts.swingBullishCHoCH := tag == CHOCH
currentAlerts.swingBullishBOS := tag == BOS
p_ivot.crossed := true
t_rend.bias := BULLISH
displayCondition = internal ? showInternalsInput and (showInternalBullInput == ALL or (showInternalBullInput == BOS and tag != CHOCH) or (showInternalBullInput == CHOCH and tag == CHOCH)) : showStructureInput and (showSwingBullInput == ALL or (showSwingBullInput == BOS and tag != CHOCH) or (showSwingBullInput == CHOCH and tag == CHOCH))
if displayCondition
drawStructure(p_ivot,tag,bullishColor,lineStyle,label.style_label_down,labelSize)
if (internal and showInternalOrderBlocksInput) or (not internal and showSwingOrderBlocksInput)
storeOrdeBlock(p_ivot,internal,BULLISH)
p_ivot := internal ? internalLow : swingLow
extraCondition := internal ? internalLow.currentLevel != swingLow.currentLevel and bearishBar : true
bearishColor = styleInput == MONOCHROME ? MONO_BEARISH : internal ? internalBearColorInput : swingBearColorInput
if ta.crossunder(close,p_ivot.currentLevel) and not p_ivot.crossed and extraCondition
string tag = t_rend.bias == BULLISH ? CHOCH : BOS
if internal
currentAlerts.internalBearishCHoCH := tag == CHOCH
currentAlerts.internalBearishBOS := tag == BOS
else
currentAlerts.swingBearishCHoCH := tag == CHOCH
currentAlerts.swingBearishBOS := tag == BOS
p_ivot.crossed := true
t_rend.bias := BEARISH
displayCondition = internal ? showInternalsInput and (showInternalBearInput == ALL or (showInternalBearInput == BOS and tag != CHOCH) or (showInternalBearInput == CHOCH and tag == CHOCH)) : showStructureInput and (showSwingBearInput == ALL or (showSwingBearInput == BOS and tag != CHOCH) or (showSwingBearInput == CHOCH and tag == CHOCH))
if displayCondition
drawStructure(p_ivot,tag,bearishColor,lineStyle,label.style_label_up,labelSize)
if (internal and showInternalOrderBlocksInput) or (not internal and showSwingOrderBlocksInput)
storeOrdeBlock(p_ivot,internal,BEARISH)
// 绘制公平价值缺口框
fairValueGapBox(leftTime,rightTime,topPrice,bottomPrice,boxColor) => box.new(chart.point.new(leftTime,na,topPrice),chart.point.new(rightTime + fairValueGapsExtendInput * (time-time[1]),na,bottomPrice), xloc=xloc.bar_time, border_color = boxColor, bgcolor = boxColor)
// 删除公平价值缺口
deleteFairValueGaps() =>
for [index,eachFairValueGap] in fairValueGaps
if (low < eachFairValueGap.bottom and eachFairValueGap.bias == BULLISH) or (high > eachFairValueGap.top and eachFairValueGap.bias == BEARISH)
eachFairValueGap.topBox.delete()
eachFairValueGap.bottomBox.delete()
fairValueGaps.remove(index)
// 绘制公平价值缺口
drawFairValueGaps() =>
[lastClose, lastOpen, lastTime, currentHigh, currentLow, currentTime, last2High, last2Low] = request.security(syminfo.tickerid, fairValueGapsTimeframeInput, [close[1], open[1], time[1], high[0], low[0], time[0], high[2], low[2]],lookahead = barmerge.lookahead_on)
barDeltaPercent = (lastClose - lastOpen) / (lastOpen * 100)
newTimeframe = timeframe.change(fairValueGapsTimeframeInput)
threshold = fairValueGapsThresholdInput ? ta.cum(math.abs(newTimeframe ? barDeltaPercent : 0)) / bar_index * 2 : 0
bullishFairValueGap = currentLow > last2High and lastClose > last2High and barDeltaPercent > threshold and newTimeframe
bearishFairValueGap = currentHigh < last2Low and lastClose < last2Low and -barDeltaPercent > threshold and newTimeframe
if bullishFairValueGap
currentAlerts.bullishFairValueGap := true
fairValueGaps.unshift(fairValueGap.new(currentLow,last2High,BULLISH,fairValueGapBox(lastTime,currentTime,currentLow,math.avg(currentLow,last2High),fairValueGapBullishColor),fairValueGapBox(lastTime,currentTime,math.avg(currentLow,last2High),last2High,fairValueGapBullishColor)))
if bearishFairValueGap
currentAlerts.bearishFairValueGap := true
fairValueGaps.unshift(fairValueGap.new(currentHigh,last2Low,BEARISH,fairValueGapBox(lastTime,currentTime,currentHigh,math.avg(currentHigh,last2Low),fairValueGapBearishColor),fairValueGapBox(lastTime,currentTime,math.avg(currentHigh,last2Low),last2Low,fairValueGapBearishColor)))
// 获取线条样式
getStyle(string style) =>
switch style
SOLID => line.style_solid
DASHED => line.style_dashed
DOTTED => line.style_dotted
// 绘制多时间框架水平线
drawLevels(string timeframe, bool sameTimeframe, string style, color levelColor) =>
[topLevel, bottomLevel, leftTime, rightTime] = request.security(syminfo.tickerid, timeframe, [high[1], low[1], time[1], time],lookahead = barmerge.lookahead_on)
float parsedTop = sameTimeframe ? high : topLevel
float parsedBottom = sameTimeframe ? low : bottomLevel
int parsedLeftTime = sameTimeframe ? time : leftTime
int parsedRightTime = sameTimeframe ? time : rightTime
int parsedTopTime = time
int parsedBottomTime = time
if not sameTimeframe
int leftIndex = array.binary_search_rightmost(times,parsedLeftTime)
int rightIndex = array.binary_search_rightmost(times,parsedRightTime)
array<int> timeArray = times.slice(leftIndex,rightIndex)
array<float> topArray = highs.slice(leftIndex,rightIndex)
array<float> bottomArray = lows.slice(leftIndex,rightIndex)
parsedTopTime := timeArray.size() > 0 ? timeArray.get(array.indexof(topArray,array.max(topArray))) : initialTime
parsedBottomTime := timeArray.size() > 0 ? timeArray.get(array.indexof(bottomArray,array.min(bottomArray))) : initialTime
var line topLine = line.new(na, na, na, na, xloc = xloc.bar_time, color = levelColor, style = getStyle(style))
var line bottomLine = line.new(na, na, na, na, xloc = xloc.bar_time, color = levelColor, style = getStyle(style))
var label topLabel = label.new(na, na, xloc = xloc.bar_time, text = str.format('前{0}高',timeframe), color=color(na), textcolor = levelColor, size = size.small, style = label.style_label_left)
var label bottomLabel = label.new(na, na, xloc = xloc.bar_time, text = str.format('前{0}低',timeframe), color=color(na), textcolor = levelColor, size = size.small, style = label.style_label_left)
topLine.set_first_point( chart.point.new(parsedTopTime,na,parsedTop))
topLine.set_second_point( chart.point.new(last_bar_time + 20 * (time-time[1]),na,parsedTop))
topLabel.set_point( chart.point.new(last_bar_time + 20 * (time-time[1]),na,parsedTop))
bottomLine.set_first_point( chart.point.new(parsedBottomTime,na,parsedBottom))
bottomLine.set_second_point(chart.point.new(last_bar_time + 20 * (time-time[1]),na,parsedBottom))
bottomLabel.set_point( chart.point.new(last_bar_time + 20 * (time-time[1]),na,parsedBottom))
// 判断是否为更高时间框架
higherTimeframe(string timeframe) => timeframe.in_seconds(timeframe) > timeframe.in_seconds()
// 更新跟踪极值
updateTrailingExtremes() =>
trailing.top := math.max(high,trailing.top)
trailing.lastTopTime := trailing.top == high ? time : trailing.lastTopTime
trailing.bottom := math.min(low,trailing.bottom)
trailing.lastBottomTime := trailing.bottom == low ? time : trailing.lastBottomTime
// 绘制强弱高低点
drawHighLowSwings() =>
var line topLine = line.new(na, na, na, na, color = swingBearishColor, xloc = xloc.bar_time)
var line bottomLine = line.new(na, na, na, na, color = swingBullishColor, xloc = xloc.bar_time)
var label topLabel = label.new(na, na, color=color(na), textcolor = swingBearishColor, xloc = xloc.bar_time, style = label.style_label_down, size = size.tiny)
var label bottomLabel = label.new(na, na, color=color(na), textcolor = swingBullishColor, xloc = xloc.bar_time, style = label.style_label_up, size = size.tiny)
rightTimeBar = last_bar_time + 20 * (time - time[1])
topLine.set_first_point( chart.point.new(trailing.lastTopTime, na, trailing.top))
topLine.set_second_point( chart.point.new(rightTimeBar, na, trailing.top))
topLabel.set_point( chart.point.new(rightTimeBar, na, trailing.top))
topLabel.set_text( swingTrend.bias == BEARISH ? '强高点' : '弱高点')
bottomLine.set_first_point( chart.point.new(trailing.lastBottomTime, na, trailing.bottom))
bottomLine.set_second_point(chart.point.new(rightTimeBar, na, trailing.bottom))
bottomLabel.set_point( chart.point.new(rightTimeBar, na, trailing.bottom))
bottomLabel.set_text( swingTrend.bias == BULLISH ? '强低点' : '弱低点')
// 绘制区域(溢价/折扣)
drawZone(float labelLevel, int labelIndex, float top, float bottom, string tag, color zoneColor, string style) =>
var label l_abel = label.new(na,na,text = tag, color=color(na),textcolor = zoneColor, style = style, size = size.small)
var box b_ox = box.new(na,na,na,na,bgcolor = color.new(zoneColor,80),border_color = color(na), xloc = xloc.bar_time)
b_ox.set_top_left_point( chart.point.new(trailing.barTime,na,top))
b_ox.set_bottom_right_point(chart.point.new(last_bar_time,na,bottom))
l_abel.set_point( chart.point.new(na,labelIndex,labelLevel))
// 绘制溢价/折扣区域
drawPremiumDiscountZones() =>
drawZone(trailing.top, math.round(0.5(trailing.barIndex + last_bar_index)), trailing.top, 0.95trailing.top + 0.05*trailing.bottom, '溢价', premiumZoneColor, label.style_label_down)
equilibriumLevel = math.avg(trailing.top, trailing.bottom)
drawZone(equilibriumLevel, last_bar_index, 0.525*trailing.top + 0.475*trailing.bottom, 0.525*trailing.bottom + 0.475*trailing.top, '均衡', equilibriumZoneColorInput, label.style_label_left)
drawZone(trailing.bottom, math.round(0.5*(trailing.barIndex + last_bar_index)), 0.95*trailing.bottom + 0.05*trailing.top, trailing.bottom, '折扣', discountZoneColor, label.style_label_up)
//---------------------------------------------------------------------------------------------------------------------}
//可变变量 & 执行逻辑
//---------------------------------------------------------------------------------------------------------------------{
parsedOpen = showTrendInput ? open : na
candleColor = internalTrend.bias == BULLISH ? swingBullishColor : swingBearishColor
plotcandle(parsedOpen,high,low,close,color = candleColor, wickcolor = candleColor, bordercolor = candleColor)
if showHighLowSwingsInput or showPremiumDiscountZonesInput
updateTrailingExtremes()
if showHighLowSwingsInput
drawHighLowSwings()
if showPremiumDiscountZonesInput
drawPremiumDiscountZones()
if showFairValueGapsInput
deleteFairValueGaps()
getCurrentStructure(swingsLengthInput,false)
getCurrentStructure(5,false,true)
if showEqualHighsLowsInput
getCurrentStructure(equalHighsLowsLengthInput,true)
if showInternalsInput or showInternalOrderBlocksInput or showTrendInput
displayStructure(true)
if showStructureInput or showSwingOrderBlocksInput or showHighLowSwingsInput
displayStructure()
if showInternalOrderBlocksInput
deleteOrderBlocks(true)
if showSwingOrderBlocksInput
deleteOrderBlocks()
if showFairValueGapsInput
drawFairValueGaps()
if barstate.islastconfirmedhistory or barstate.islast
if showInternalOrderBlocksInput
drawOrderBlocks(true)
if showSwingOrderBlocksInput
drawOrderBlocks()
lastBarIndex := currentBarIndex
currentBarIndex := bar_index
newBar = currentBarIndex != lastBarIndex
if barstate.islastconfirmedhistory or (barstate.isrealtime and newBar)
if showDailyLevelsInput and not higherTimeframe('D')
drawLevels('D',timeframe.isdaily,dailyLevelsStyleInput,dailyLevelsColorInput)
if showWeeklyLevelsInput and not higherTimeframe('W')
drawLevels('W',timeframe.isweekly,weeklyLevelsStyleInput,weeklyLevelsColorInput)
if showMonthlyLevelsInput and not higherTimeframe('M')
drawLevels('M',timeframe.ismonthly,monthlyLevelsStyleInput,monthlyLevelsColorInput)
//---------------------------------------------------------------------------------------------------------------------}
//警报设置
//---------------------------------------------------------------------------------------------------------------------{
alertcondition(currentAlerts.internalBullishBOS, '内部多头BOS', '内部多头BOS形成')
alertcondition(currentAlerts.internalBullishCHoCH, '内部多头CHoCH', '内部多头CHoCH形成')
alertcondition(currentAlerts.internalBearishBOS, '内部空头BOS', '内部空头BOS形成')
alertcondition(currentAlerts.internalBearishCHoCH, '内部空头CHoCH', '内部空头CHoCH形成')
alertcondition(currentAlerts.swingBullishBOS, '多头BOS', '波段多头BOS形成')
alertcondition(currentAlerts.swingBullishCHoCH, '多头CHoCH', '波段多头CHoCH形成')
alertcondition(currentAlerts.swingBearishBOS, '空头BOS', '波段空头BOS形成')
alertcondition(currentAlerts.swingBearishCHoCH, '空头CHoCH', '波段空头CHoCH形成')
alertcondition(currentAlerts.internalBullishOrderBlock, '多头内部订单块突破', '价格突破多头内部订单块')
alertcondition(currentAlerts.internalBearishOrderBlock, '空头内部订单块突破', '价格突破空头内部订单块')
alertcondition(currentAlerts.swingBullishOrderBlock, '多头波段订单块突破', '价格突破多头波段订单块')
alertcondition(currentAlerts.swingBearishOrderBlock, '空头波段订单块突破', '价格突破空头波段订单块')
alertcondition(currentAlerts.equalHighs, '等高点', '检测到等高点')
alertcondition(currentAlerts.equalLows, '等低点', '检测到等低点')
alertcondition(currentAlerts.bullishFairValueGap, '多头FVG', '多头公平价值缺口形成')
alertcondition(currentAlerts.bearishFairValueGap, '空头FVG', '空头公平价值缺口形成')
//---------------------------------------------------------------------------------------------------------------------}