XAD SYSTEM
Сообщите нам, если считаете, что материал размещён без разрешения.
Сообщить о материале
Обращение по товару «indicator xad system for tradingview.pine» отправится на рассмотрение. Укажите контакт для ответа и опишите причину.
О программе
XAD SYSTEM — индикатор для TradingView, портированный с MQL5 (исходная концепция XARD UNIVERSE). Реализует двухпроходный rolling-extreme ZigZag для определения свинг-хайлов и свинг-лоу на графике цены.
Индикатор отображает линии AVWAP (средневзвешенная цена по объёму), проведённые от найденных пивотов, а также визуализирует торговые установки с уровнями ENTRY, SL, TP1 и TP2. Зоны TP1 и SL отрисовываются в виде заливок, TP2 — в виде дугообразной зоны до противоположного сигнала.
Расчёт носит ретроспективный характер: найденные пивоты и уровни могут перерисовываться при появлении новых данных. Панель статистики показывает результаты по закрытым свечам (количество TP/SL/открытых, чистый результат в пипсах, процент прибыльных выходов). Поддерживаются условия оповещений для пивотов.
Настройки программы
| Настройка | Описание |
|---|---|
| brandCard | Текстовое поле для пользовательской карточки бренда. По умолчанию скрыто (active = false, display = display.none). Значение используется в подсказке логотипа XAD на графике. |
Поиск по коду файла
indicator("XAD SYSTEM", "XAD SYSTEM", overlay = true, max_bars_back = 5000, max_polylines_count = 100, max_lines_count = 200, max_boxes_count = 100, max_labels_count = 300)
string brandCard = input.string("XAD SCALPER", "☠", group = "XAD SYSTEM", active = false, display = display.none)
const bool showEngine = true
const bool showAVWAP = true
const int keepSegments = 13
const color peakColor = color.rgb(255, 165, 0)
int peakWidth = 1
const string peakStyle = "Solid"
const color troughColor = color.rgb(48, 144, 240)
int troughWidth = 1
const string troughStyle = "Solid"
const bool showOutline = false
const int depth = 192
const int deviation = 5
const float pointOverride = 0.0
const int backstep = 3
const bool useGuard = false
const int guardBars = 3
const bool enableAlerts = false
const int alertDelay = 0
const bool reversalsOnly = false
const int cooldownSeconds = 60
const bool showPivots = true
const bool showZigZag = false
const bool showHeader = false
const bool debugMode = false
const int historyBars = 4500
const bool closedBarsOnly = true
const bool unitVolumeFallback = true
const bool showEntries = true
const int setupsToShow = 10
const int tp1BasePips = 1000
const float tp1Percent = 50.0
const float pipSize = 0.01
const int slBufferTicks = 1
const int zoneBars = 35
const bool clipAtNext = true
const int fillTransparency = 90
const int levelWidth = 1
const color entryColor = color.rgb(255, 218, 53)
const color slColor = color.rgb(255, 49, 74)
const color tp1Color = color.rgb(0, 188, 212)
const color tpColor = color.rgb(0, 210, 105)
const string tagSizeInput = "Tiny"
const float signalLabelGapPct = 35.0
const bool showStats = true
const string statsTarget = "TP2"
const float costPips = 0.0
const string statsPosition = "Top Right"
const string statsSize = "Small"
const int LOGO_COLUMNS = 21
const int LOGO_PIXEL_ROWS = 19
const float LOGO_CELL_WIDTH = 0.24
const float LOGO_CELL_HEIGHT = 0.44
const color LOGO_NEON = #00D99C
const color LOGO_HOOD = #111820
const color LOGO_SHADOW = #637786
const color LOGO_BONE = #DFE8E9
const color LOGO_SOCKET = #070A10
const color LOGO_EYE = #FF2347
var array<string> skullRows = array.new<string>()
var table xadLogo = table.new(position.top_center, LOGO_COLUMNS, LOGO_PIXEL_ROWS + 1, bgcolor = color.new(color.black, 100), border_width = 0)
if barstate.isfirst
array.push(skullRows, ".....................")
array.push(skullRows, "........ccccc........")
array.push(skullRows, "......cHHHHHHHc......")
array.push(skullRows, ".....cHHSSSSSHHc.....")
array.push(skullRows, "....cHSSBBBBBSSHc....")
array.push(skullRows, "....cHSBBBBBBBSHc....")
array.push(skullRows, "...cHSBBBBBBBBBSHc...")
array.push(skullRows, "...cHSBBBBBBBBBSHc...")
array.push(skullRows, "..cHSBSSBBBBBSSBSHc..")
array.push(skullRows, "..cHSBDDSBBBSDDBSHc..")
array.push(skullRows, "..cHSBRRDSBSDRRBSHc..")
array.push(skullRows, "..cHSBDRDSBSDRDBSHc..")
array.push(skullRows, "..cHSBSSBBNBBSSBSHc..")
array.push(skullRows, "...cHSSBBNNNBBSSHc...")
array.push(skullRows, "...cHSBBBBBBBBBSHc...")
array.push(skullRows, "....cHBSBSBSBSBHc....")
array.push(skullRows, "....cHBSBSBSBSBHc....")
array.push(skullRows, ".....cSBSBSBSBSc.....")
array.push(skullRows, "......cSSSSSSSc......")
table.merge_cells(xadLogo, 0, LOGO_PIXEL_ROWS, LOGO_COLUMNS - 1, LOGO_PIXEL_ROWS)
if barstate.islast or barstate.islastconfirmedhistory
for row = 0 to LOGO_PIXEL_ROWS - 1
string pixels = array.get(skullRows, row)
for column = 0 to LOGO_COLUMNS - 1
string pixel = str.substring(pixels, column, column + 1)
color ink = switch pixel
"c" => LOGO_NEON
"H" => LOGO_HOOD
"S" => LOGO_SHADOW
"B" => LOGO_BONE
"D" => LOGO_SOCKET
"N" => LOGO_SOCKET
"R" => LOGO_EYE
=> color.new(color.black, 100)
table.cell(xadLogo, column, row, "", width = LOGO_CELL_WIDTH, height = LOGO_CELL_HEIGHT, bgcolor = ink, text_size = 1)
table.cell(xadLogo, 0, LOGO_PIXEL_ROWS, "XAD", height = 2.4, text_color = LOGO_NEON, text_size = 16, text_font_family = font.family_monospace, text_formatting = text.format_bold, text_halign = text.align_center, bgcolor = color.new(color.black, 100), tooltip = brandCard)
f_position(string selected) =>
switch selected
"Top Left" => position.top_left
"Bottom Right" => position.bottom_right
"Bottom Left" => position.bottom_left
=> position.top_right
f_panelSize() =>
switch statsSize
"Tiny" => size.tiny
"Normal" => size.normal
=> size.small
f_pips(float value) =>
na(value) ? "--" : str.tostring(value, "0.0") + " pip"
f_signedPips(float value) =>
na(value) ? "--" : (value >= 0 ? "+" : "") + f_pips(value)
f_style(string selected) =>
switch selected
"Dashed" => line.style_dashed
"Dotted" => line.style_dotted
=> line.style_solid
f_weight(float rawVolume) =>
not na(rawVolume) and rawVolume > 0 ? rawVolume : unitVolumeFallback ? 1.0 : 0.0
f_tagSize() =>
switch tagSizeInput
"Small" => size.small
"Normal" => size.normal
=> size.tiny
f_levels(int offset, int side) =>
float entry = close[offset]
float buffer = slBufferTicks * syminfo.mintick
float stop = side == 1 ? high[offset] + buffer : low[offset] - buffer
float distance1 = tp1BasePips * pipSize * tp1Percent / 100.0
float target1 = side == 1 ? entry - distance1 : entry + distance1
[entry, math.round_to_mintick(stop), math.round_to_mintick(target1)]
f_nextOpposite(array<int> offsets, array<int> sides, int pivot, int lastClosed) =>
int oppositeOffset = na
int side = array.get(sides, pivot)
if pivot > 0
for q = pivot - 1 to 0
int candidate = array.get(offsets, q)
if candidate >= lastClosed and array.get(sides, q) == -side
oppositeOffset := candidate
break
oppositeOffset
f_barResult(float o, float h, float l, float c, float entry, float stop, float target1, bool isBuy, bool exitAtOpposite, bool oppositeBar) =>
bool hitSL = isBuy ? l <= stop : h >= stop
bool hitTP = exitAtOpposite ? oppositeBar : (isBuy ? h >= target1 : l <= target1)
bool gapSL = hitSL and (isBuy ? o < stop : o > stop)
bool both = hitSL and hitTP
int result = hitSL ? -1 : hitTP ? 1 : 0
float exitPrice = hitSL ? (gapSL ? o : stop) : (exitAtOpposite ? c : target1)
float earned = result == 0 ? 0.0 : (isBuy ? exitPrice - entry : entry - exitPrice) / pipSize
[result, earned, both, gapSL]
f_outcome(int start, int lastClosed, float entry, float stop, float target1, bool isBuy, bool exitAtOpposite, int oppositeOffset) =>
int result = 0
float earned = 0.0
bool both = false
bool gapSL = false
bool valid = not na(entry) and not na(stop) and (isBuy ? stop < entry : stop > entry)
if not exitAtOpposite
valid := valid and not na(target1) and (isBuy ? target1 > entry : target1 < entry)
else if not na(oppositeOffset)
valid := valid and oppositeOffset >= lastClosed and oppositeOffset < start
int finish = exitAtOpposite and not na(oppositeOffset) ? oppositeOffset : lastClosed
if not valid
result := 2
else if start > finish
for i = start - 1 to finish
bool oppositeBar = not na(oppositeOffset) and i == oppositeOffset
[barResult, barEarned, barBoth, barGap] = f_barResult(open[i], high[i], low[i], close[i], entry, stop, target1, isBuy, exitAtOpposite, oppositeBar)
if barResult != 0
result := barResult
earned := barEarned
both := barBoth
gapSL := barGap
break
[result, earned, both, gapSL]
float rollingHigh = ta.highest(high, depth)
float rollingLow = ta.lowest(low, depth)
float pointSize = pointOverride > 0 ? pointOverride : syminfo.mintick
float tolerance = deviation * pointSize
int guard = useGuard ? guardBars : 0
var array<polyline> drawings = array.new<polyline>()
var array<label> pivotLabels = array.new<label>()
var array<line> tradeLines = array.new<line>()
var array<box> tradeBoxes = array.new<box>()
var array<label> tradeLabels = array.new<label>()
var table header = table.new(showStats and statsPosition == "Top Right" ? position.bottom_right : position.top_right, 1, 3, bgcolor = color.new(color.rgb(50, 60, 70), 15))
var table statsPanel = table.new(f_position(statsPosition), 2, 15, bgcolor = color.rgb(22, 27, 35), frame_color = color.rgb(69, 80, 96), frame_width = 1, border_width = 0)
var float currentAVWAP = na
var int currentBias = 0
var int latestSide = 0
var int latestPivotTime = na
var float latestPivotPrice = na
var int latestPivotAge = na
var int displayedSegments = 0
var int fallbackBars = 0
var float latestEntry = na
var float latestSL = na
var float latestTP1 = na
var float latestTP = na
var int displayedSetups = 0
var int statsSignals = 0
var int tpCount = 0
var int slCount = 0
var int profitableCount = 0
var int openCount = 0
var int invalidCount = 0
var int ambiguousCount = 0
var int gapCount = 0
var float totalTP = 0.0
var float totalSL = 0.0
var float newestRiskPips = na
var float newestTargetPips = na
var string newestTP2Status = "Waiting for signal"
f_statRow(int row, string caption, string value, color valueColor) =>
color bg = row % 2 == 0 ? color.rgb(22, 27, 35) : color.rgb(29, 35, 44)
table.cell(statsPanel, 0, row, caption, text_color = color.rgb(192, 201, 213), text_halign = text.align_left, text_size = f_panelSize(), bgcolor = bg)
table.cell(statsPanel, 1, row, value, text_color = valueColor, text_halign = text.align_right, text_size = f_panelSize(), bgcolor = bg)
f_drawLevel(int leftBar, int rightBar, float price, string caption, color strokeColor, color tagColor, color textColor, string lineStyle) =>
array.push(tradeLines, line.new(x1 = leftBar, y1 = price, x2 = rightBar, y2 = price, xloc = xloc.bar_index, color = strokeColor, style = lineStyle, width = levelWidth))
array.push(tradeLabels, label.new(x = rightBar, y = price, text = caption + " " + str.tostring(price, format.mintick), xloc = xloc.bar_index, yloc = yloc.price, style = label.style_label_left, color = tagColor, textcolor = textColor, size = f_tagSize()))
f_tp2ArcProgress(float phase) =>
1.0 - math.sqrt(math.max(0.0, 1.0 - phase * phase))
f_drawTP2Zone(int leftBar, int rightBar, float entry, float edgePrice, color edgeColor, bool waiting) =>
int span = rightBar - leftBar
if span > 0 and not na(edgePrice)
int steps = math.min(span, 120)
array<chart.point> outline = array.new<chart.point>()
for k = 0 to steps
float phase = float(k) / float(steps)
int x = leftBar + int(math.round(float(span) * phase))
float y = entry + (edgePrice - entry) * f_tp2ArcProgress(phase)
array.push(outline, chart.point.from_index(x, y))
array.push(outline, chart.point.from_index(leftBar, edgePrice))
array.push(drawings, polyline.new(outline, curved = false, closed = true, xloc = xloc.bar_index, line_color = edgeColor, fill_color = color.new(tp1Color, fillTransparency), line_style = waiting ? line.style_dashed : line.style_solid, line_width = levelWidth))
f_drawSetup(int leftBar, int rightBar, int tp2Bar, float waitingPrice, float entry, float stop, float target1, float target2, bool isBuy) =>
array.push(tradeBoxes, box.new(left = leftBar, top = math.max(entry, target1), right = rightBar, bottom = math.min(entry, target1), xloc = xloc.bar_index, border_color = tp1Color, border_width = levelWidth, bgcolor = color.new(tp1Color, fillTransparency)))
array.push(tradeBoxes, box.new(left = leftBar, top = math.max(entry, stop), right = rightBar, bottom = math.min(entry, stop), xloc = xloc.bar_index, border_color = slColor, border_width = levelWidth, bgcolor = color.new(slColor, fillTransparency)))
string oppositeName = isBuy ? "SELL" : "BUY"
string target2Text = "Waiting for " + oppositeName
if not na(target2)
float tp2Pips = (isBuy ? target2 - entry : entry - target2) / pipSize
color exitColor = tp2Pips >= 0 ? tpColor : slColor
f_drawTP2Zone(leftBar, tp2Bar, entry, target2, exitColor, false)
array.push(tradeLabels, label.new(x = tp2Bar, y = target2, text = "TP2 " + (isBuy ? "BUY" : "SELL") + " " + str.tostring(target2, format.mintick), xloc = xloc.bar_index, yloc = yloc.price, style = label.style_label_left, color = exitColor, textcolor = color.black, size = f_tagSize()))
target2Text := str.tostring(target2, format.mintick) + " | " + f_signedPips(tp2Pips)
else
f_drawTP2Zone(leftBar, tp2Bar, entry, waitingPrice, color.new(tpColor, 35), true)
array.push(tradeLabels, label.new(x = tp2Bar, y = waitingPrice, text = "TP2: " + target2Text, xloc = xloc.bar_index, yloc = yloc.price, style = label.style_label_left, color = tpColor, textcolor = color.black, size = f_tagSize(), tooltip = "No opposite closed signal yet. The dashed oval temporarily ends at the last closed candle price. This is not a fixed TP2 price. Stop-loss outcomes are calculated separately in the statistics."))
f_drawLevel(leftBar, rightBar, target1, "TP1", tp1Color, tp1Color, color.black, line.style_dashed)
f_drawLevel(leftBar, rightBar, entry, "ENTRY", slColor, entryColor, color.black, line.style_solid)
f_drawLevel(leftBar, rightBar, stop, "SL", slColor, slColor, color.white, line.style_solid)
string direction = isBuy ? "BUY" : "SELL"
string tip = direction + " | ENTRY " + str.tostring(entry, format.mintick) + "\nSL " + str.tostring(stop, format.mintick) + " | TP1 " + str.tostring(target1, format.mintick) + " | TP2: " + target2Text + "\nTP2 closes at the first " + oppositeName + " pivot candle close. TP2 and TP1 share the same fill color. The curved edge is visual only. If SL is hit first, statistics close the setup at SL.\nHistorical ZigZag: signals and TP2 can move later."
int anchorOffset = bar_index - leftBar
float candleHigh = high[anchorOffset]
float candleLow = low[anchorOffset]
float signalLabelGap = math.max((candleHigh - candleLow) * signalLabelGapPct / 100.0, syminfo.mintick * 5.0)
float signalLabelY = isBuy ? math.min(candleLow, math.min(entry, stop)) - signalLabelGap : math.max(candleHigh, math.max(entry, stop)) + signalLabelGap
array.push(tradeLabels, label.new(x = leftBar, y = signalLabelY, text = direction, xloc = xloc.bar_index, yloc = yloc.price, style = isBuy ? label.style_label_up : label.style_label_down, color = isBuy ? tpColor : slColor, textcolor = color.white, size = size.small, tooltip = tip))
var table wm = table.new(position.bottom_right, 1, 1)
if barstate.isfirst
table.cell(wm, 0, 0, "Telegram @SimpleForexTools", text_color = color.new(color.gray, 70), text_size = size.large)
var int observedPivotTime = na
var int observedSide = 0
var int pendingPivotTime = na
var int pendingSide = 0
var int pendingDueBar = na
var int lastAlertClock = na
bool peakAlert = false
bool troughAlert = false
bool calculateNow = barstate.islastconfirmedhistory or (barstate.islast and (not closedBarsOnly or barstate.isconfirmed))
if calculateNow
while array.size(drawings) > 0
polyline.delete(array.pop(drawings))
while array.size(pivotLabels) > 0
label.delete(array.pop(pivotLabels))
while array.size(tradeLines) > 0
line.delete(array.pop(tradeLines))
while array.size(tradeBoxes) > 0
box.delete(array.pop(tradeBoxes))
while array.size(tradeLabels) > 0
label.delete(array.pop(tradeLabels))
currentAVWAP := na
currentBias := 0
latestSide := 0
latestPivotTime := na
latestPivotPrice := na
latestPivotAge := na
displayedSegments := 0
fallbackBars := 0
latestEntry := na
latestSL := na
latestTP1 := na
latestTP := na
displayedSetups := 0
statsSignals := 0
tpCount := 0
slCount := 0
profitableCount := 0
openCount := 0
invalidCount := 0
ambiguousCount := 0
gapCount := 0
totalTP := 0.0
totalSL := 0.0
newestRiskPips := na
newestTargetPips := na
newestTP2Status := "Waiting for signal"
int oldest = math.min(historyBars - 1, bar_index + 1 - depth - backstep)
bool enoughBars = bar_index + 1 >= depth + backstep + 10 and oldest >= guard
if enoughBars
array<float> highs = array.new<float>(oldest + Показано первые 50% кода (символов: 24478)