该策略是一个基于分形理论和订单块分析的自适应交易系统。它通过识别市场结构中的关键支撑阻力位,结合分形突破信号和订单块确认来捕捉高概率交易机会。策略集成了多重技术指标,包括分形指标、动态订单块和价格突破确认系统,实现了对市场转折点的精确定位和交易时机的准确把握。
策略的核心逻辑建立在三个主要支柱之上:首先是通过分形计算模块持续监测市场高低点,识别潜在的趋势转折区域;其次是通过订单块分析,在关键价格水平建立供需区域;最后是通过突破确认系统,验证价格突破的有效性。当价格突破上方分形且确认有效时,系统会在最近的红色蜡烛区域创建需求区订单块并开立多单;当价格突破下方分形且确认有效时,系统会在最近的绿色蜡烛区域创建供应区订单块并开立空单。策略还包含了订单块颜色动态更新功能,用于直观显示价格与订单块的相对位置关系。
这是一个融合了技术分析多个维度的复合型交易策略,通过分形理论和订单块分析为核心,构建了一个完整的交易系统。策略的优势在于其自适应性和多重确认机制,但同时也需要注意市场环境对策略表现的影响。通过建议的优化方向,策略的可靠性和稳定性有望得到进一步提升。
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-25 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Supply and Demand - Order Block Strategy", format=format.price, precision=0, overlay=true)
// Input options for customization
changeColor = input(false, title="Change Box Colors?")
breakType = input.string("Wick+Body", title="Fractal Break Type:", options=["Wick+Body", "Body"])
n = input.int(title="Periods", defval=2, minval=1, tooltip="Number of periods for fractal lookback")
if n <= 0
runtime.error("Periods input must be greater than zero.")
transGreenClr = input.color(color.new(color.green, 80), title="Bg:", inline="a_1")
greenClr = input.color(color.new(color.green, 0), title="Border:", inline="a_1")
transRedClr = input.color(color.new(color.red, 80), title="Bg:", inline="b_1")
redClr = input.color(color.new(color.red, 0), title="Border:", inline="b_1")
// --- Fractal Calculation ---
upFractal = high[n] == ta.highest(high, 2 * n + 1)
downFractal = low[n] == ta.lowest(low, 2 * n + 1)
// --- End Fractal Calculation ---
var float topValue = na
var float bottomValue = na
var int lastRedIndex = na
var float lastRedLow = na
var float lastRedHigh = na
var int lastGreenIndex = na
var float lastGreenLow = na
var float lastGreenHigh = na
var line topLine = na
var line bottomLine = na
var box demandBox = na
var box supplyBox = na
var topBreakBlock = false
var bottomBreakBlock = false
var isLongBreak = false
var isShortBreak = false
topBreakCheckSource = breakType == "Wick+Body" ? high : close
bottomBreakCheckSource = breakType == "Wick+Body" ? low : close
// Last Red Check
if close < open
lastRedIndex := bar_index
lastRedLow := low
lastRedHigh := high
// Last Green Check
if close > open
lastGreenIndex := bar_index
lastGreenLow := low
lastGreenHigh := high
// Top break
if ta.crossover(topBreakCheckSource, topValue) and not topBreakBlock
topBreakBlock := true
isLongBreak := true
// line.set_x2(topLine, bar_index)
// demandBox := box.new(lastRedIndex - 1, lastRedHigh, lastRedIndex + 1, lastRedLow, bgcolor=transGreenClr, border_color=greenClr)
if strategy.position_size <= 0
strategy.entry("Long", strategy.long)
// Bottom break
if ta.crossunder(bottomBreakCheckSource, bottomValue) and not bottomBreakBlock
bottomBreakBlock := true
isShortBreak := true
// line.set_x2(bottomLine, bar_index)
// supplyBox := box.new(lastGreenIndex - 1, lastGreenHigh, lastGreenIndex + 1, lastGreenLow, bgcolor=transRedClr, border_color=redClr)
if strategy.position_size >= 0
strategy.entry("Short", strategy.short)
// New up fractal
if upFractal
topBreakBlock := false
isLongBreak := false
topValue := high[n]
// topLine := line.new(bar_index[n], topValue, bar_index, topValue, color=color.teal, style=line.style_dotted, width=2)
// if not isLongBreak[1]
// line.delete(topLine[1])
// New down fractal
if downFractal
bottomBreakBlock := false
isShortBreak := false
bottomValue := low[n]
// bottomLine := line.new(bar_index[n], bottomValue, bar_index, bottomValue, color=color.maroon, style=line.style_dotted, width=2)
// if not isShortBreak[1]
// line.delete(bottomLine[1])
// Box state update
// activeBoxes = box.all
// if array.size(activeBoxes) > 0 and changeColor
// for i = 0 to array.size(activeBoxes) - 1
// boxId = array.get(activeBoxes, i)
// bVal = box.get_bottom(boxId)
// tVal = box.get_top(boxId)
// if close < bVal
// box.set_bgcolor(boxId, transRedClr)
// box.set_border_color(boxId, redClr)
// if close > tVal
// box.set_bgcolor(boxId, transGreenClr)
// box.set_border_color(boxId, greenClr)
//PLOTS
plotshape(downFractal ,style=shape.triangleup, location=location.belowbar, offset=-n, color=color.new(color.gray,80), size = size.tiny)
plotshape(upFractal, style=shape.triangledown, location=location.abovebar, offset=-n, color=color.new(color.gray,80), size = size.tiny)
// --- Checklist Table ---
// var table checklistTable = table.new(position.bottom_right, 2, 8, bgcolor=color.new(color.gray, 80), border_width=1)
// if barstate.islast
// table.cell(checklistTable, 0, 0, "Condition", text_color=color.white, text_size=size.small, bgcolor=color.teal)
// table.cell(checklistTable, 1, 0, "Status", text_color=color.white, text_size=size.small, bgcolor=color.teal)
// table.cell(checklistTable, 0, 1, "Up Fractal", text_size=size.small)
// table.cell(checklistTable, 1, 1, upFractal ? "✅" : "❌", text_color=upFractal ? color.green : color.red, text_size=size.small)
// table.cell(checklistTable, 0, 2, "Down Fractal", text_size=size.small)
// table.cell(checklistTable, 1, 2, downFractal ? "✅" : "❌", text_color=downFractal ? color.green : color.red, text_size=size.small)
// table.cell(checklistTable, 0, 3, "Top Break", text_size=size.small)
// table.cell(checklistTable, 1, 3, isLongBreak ? "✅" : "❌", text_color=isLongBreak ? color.green : color.red, text_size=size.small)
// table.cell(checklistTable, 0, 4, "Bottom Break", text_size=size.small)
// table.cell(checklistTable, 1, 4, isShortBreak ? "✅" : "❌", text_color=isShortBreak ? color.green : color.red, text_size=size.small)
// table.cell(checklistTable, 0, 5, "Last Red Candle", text_size=size.small)
// table.cell(checklistTable, 1, 5, close < open ? "✅" : "❌", text_color=close < open ? color.green : color.red, text_size=size.small)
// table.cell(checklistTable, 0, 6, "Last Green Candle", text_size=size.small)
// table.cell(checklistTable, 1, 6, close > open ? "✅" : "❌", text_color=close > open ? color.green : color.red, text_size=size.small)
// table.cell(checklistTable, 0, 7, "Box Color Change Active", text_size=size.small)
// table.cell(checklistTable, 1, 7, changeColor ? "✅" : "❌", text_color=changeColor ? color.green : color.red, text_size=size.small)