Chiến lược này là một hệ thống giao dịch thích ứng dựa trên lý thuyết fractal và phân tích khối lệnh. Phương pháp này nắm bắt các cơ hội giao dịch có xác suất cao bằng cách xác định các mức hỗ trợ và kháng cự quan trọng trong cấu trúc thị trường, kết hợp với các tín hiệu đột phá fractal và xác nhận khối lệnh. Chiến lược này tích hợp nhiều chỉ báo kỹ thuật, bao gồm các chỉ báo fractal, khối lệnh động và hệ thống xác nhận đột phá giá, để xác định chính xác các điểm đảo chiều của thị trường và nắm bắt chính xác các cơ hội giao dịch.
Logic cốt lõi của chiến lược này được xây dựng trên ba trụ cột chính: thứ nhất, theo dõi liên tục mức cao và thấp của thị trường thông qua mô-đun tính toán fractal để xác định các khu vực có khả năng đảo ngược xu hướng; thứ hai, thông qua phân tích khối lệnh, thiết lập các khu vực cung và cầu ở các mức giá quan trọng ; và cuối cùng, thông qua hệ thống xác nhận đột phá để xác minh tính hợp lệ của đột phá giá. Khi giá vượt qua fractal trên và được xác nhận là hợp lệ, hệ thống sẽ tạo một khối lệnh theo vùng cầu ở vùng nến đỏ gần nhất và mở một lệnh mua; khi giá vượt qua fractal dưới và được xác nhận là hợp lệ , hệ thống sẽ tạo một vùng cung cấp tại khối lệnh nến xanh gần nhất và mở một lệnh bán khống. Chiến lược này cũng bao gồm chức năng cập nhật động cho màu khối lệnh, được sử dụng để hiển thị trực quan mối quan hệ vị trí tương đối giữa giá và khối lệnh.
Đây là một chiến lược giao dịch phức tạp tích hợp nhiều chiều của phân tích kỹ thuật. Nó xây dựng một hệ thống giao dịch hoàn chỉnh với lý thuyết fractal và phân tích khối lệnh làm cốt lõi. Ưu điểm của chiến lược này nằm ở khả năng thích ứng và nhiều cơ chế xác nhận, nhưng đồng thời, chúng ta cũng cần chú ý đến tác động của môi trường thị trường đến hiệu quả của chiến lược. Thông qua các hướng tối ưu hóa được đề xuất, độ tin cậy và tính ổn định của chiến lược dự kiến sẽ được cải thiện hơn nữa.
/*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)