Thanhanh9/Test / trend_reverse.pine
download
raw
3.62 kB
//@version=5
indicator("Gold Swing Box (>120 pips)", overlay=true, max_boxes_count=500)
// --- USER INPUTS ---
boxMinPips = input.float(120, title="Số pips tối thiểu của Swing (Box)", tooltip="Swing phải lớn hơn số pips này để được vẽ Box.")
revPips = input.float(50, title="Số pips đảo chiều (Reversal)", tooltip="Khoảng cách giá lùi lại để xác nhận một swing đã kết thúc.")
pipSize = input.float(0.1, title="Giá trị 1 Pip", tooltip="Với Vàng (XAUUSD), 1 pip thường là 0.1 (tương đương 10 points).")
minCandles = input.int(5, title="Số nến tối thiểu 1 Swing", tooltip="Swing phải kéo dài ít nhất số nến này mới vẽ Box.")
upBoxColor = input.color(color.new(color.teal, 80), title="Màu Box Swing Tăng")
dnBoxColor = input.color(color.new(color.maroon, 80), title="Màu Box Swing Giảm")
boxBorder = input.color(color.new(color.gray, 50), title="Màu Viền Box")
// --- CẢNH BÁO TIMEFRAME ---
if timeframe.period != "5"
// Hiển thị cảnh báo nếu không phải ở khung 5 phút
var label warningLabel = na
if na(warningLabel)
warningLabel := label.new(bar_index, high, "Vui lòng chuyển sang Timeframe 5m\nnhư yêu cầu của chiến lược.", color=color.red, textcolor=color.white, style=label.style_label_down, size=size.large)
else
label.set_xy(warningLabel, bar_index, high)
// --- TÍNH TOÁN LOGIC SWING (ZIGZAG) ---
var int dir = 0
var float extremum = close
var int extremum_bar = bar_index
var float swingStartPrice = close
var int swingStartBar = bar_index
if barstate.isfirst
dir := 1
extremum := high
extremum_bar := bar_index
swingStartPrice := low
swingStartBar := bar_index
if dir == 1
// Trong Swing TĂNG: Cập nhật High cao nhất
if high > extremum
extremum := high
extremum_bar := bar_index
// Kiểm tra điều kiện đảo chiều GIẢM
if low <= extremum - (revPips * pipSize)
// Đo lường kích thước của Swing TĂNG vừa qua
swingPips = (extremum - swingStartPrice) / pipSize
// Nếu đạt yêu cầu > 120 pips và đủ số nến tối thiểu thì vẽ Box
if swingPips >= boxMinPips and (extremum_bar - swingStartBar) >= minCandles
box.new(left=swingStartBar, top=extremum, right=extremum_bar, bottom=swingStartPrice, bgcolor=upBoxColor, border_color=boxBorder)
// Bắt đầu một Swing GIẢM mới
dir := -1
swingStartPrice := extremum
swingStartBar := extremum_bar
extremum := low
extremum_bar := bar_index
else if dir == -1
// Trong Swing GIẢM: Cập nhật Low thấp nhất
if low < extremum
extremum := low
extremum_bar := bar_index
// Kiểm tra điều kiện đảo chiều TĂNG
if high >= extremum + (revPips * pipSize)
// Đo lường kích thước của Swing GIẢM vừa qua
swingPips = (swingStartPrice - extremum) / pipSize
// Nếu đạt yêu cầu > 120 pips và đủ số nến tối thiểu thì vẽ Box
if swingPips >= boxMinPips and (extremum_bar - swingStartBar) >= minCandles
box.new(left=swingStartBar, top=swingStartPrice, right=extremum_bar, bottom=extremum, bgcolor=dnBoxColor, border_color=boxBorder)
// Bắt đầu một Swing TĂNG mới
dir := 1
swingStartPrice := extremum
swingStartBar := extremum_bar
extremum := high
extremum_bar := bar_index

Xet Storage Details

Size:
3.62 kB
·
Xet hash:
2b9f050fa108951a4b018ae4f6932edb7034b1ab16e53bca3868af04e4cb7b15

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.