Created
December 14, 2025 16:52
-
-
Save steveast/fc23630d98219f405205502d59629664 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //@version=6 | |
| indicator("Master Spread 2 - Multi Pairs", overlay=false, max_labels_count=30, max_lines_count=30) | |
| // ---------- Настройки ---------- | |
| symbolB = input.symbol("", "Leg 2") | |
| symbolC = input.symbol("", "Leg 3") | |
| symbolD = input.symbol("", "Leg 4") | |
| symbolE = input.symbol("", "Leg 5") | |
| symbolF = input.symbol("", "Leg 6") | |
| symbolG = input.symbol("", "Leg 7") | |
| symbolH = input.symbol("", "Leg 8") | |
| symbolI = input.symbol("", "Leg 9") | |
| symbolJ = input.symbol("", "Leg 10") | |
| entryLevel = input.float(2, "Entry Level (%)", step=0.01) | |
| showWeekends = input.bool(true, "Подсвечивать выходные") | |
| weekendClr = input.color(color.new(color.black, 80), "Цвет выходных") | |
| lineWidth = input.int(1, "Толщина линий", minval=1, maxval=5) | |
| // Цвета для 9 легов | |
| colB = input.color(color.new(color.orange, 0), "Цвет Leg 2") | |
| colC = input.color(color.new(color.yellow, 0), "Цвет Leg 3") | |
| colD = input.color(color.new(color.fuchsia, 0), "Цвет Leg 4") | |
| colE = input.color(color.new(color.aqua, 0), "Цвет Leg 5") | |
| colF = input.color(color.new(color.teal, 0), "Цвет Leg 6") | |
| colG = input.color(color.new(color.purple, 0), "Цвет Leg 7") | |
| colH = input.color(color.new(color.red, 0), "Цвет Leg 8") | |
| colI = input.color(color.new(color.blue, 0), "Цвет Leg 9") | |
| colJ = input.color(color.new(color.green, 0), "Цвет Leg 10") | |
| // ---------- Функция: только название биржи ---------- | |
| f_exchangeName(_symbol) => | |
| parts = str.split(_symbol, ":") | |
| array.size(parts) > 1 ? array.get(parts, 0) : _symbol | |
| // ---------- Данные ---------- | |
| a = request.security(syminfo.tickerid, timeframe.period, close, lookahead = barmerge.lookahead_on) | |
| b = symbolB != "" ? request.security(symbolB, timeframe.period, close, lookahead = barmerge.lookahead_on) : na | |
| c = symbolC != "" ? request.security(symbolC, timeframe.period, close, lookahead = barmerge.lookahead_on) : na | |
| d = symbolD != "" ? request.security(symbolD, timeframe.period, close, lookahead = barmerge.lookahead_on) : na | |
| e = symbolE != "" ? request.security(symbolE, timeframe.period, close, lookahead = barmerge.lookahead_on) : na | |
| f = symbolF != "" ? request.security(symbolF, timeframe.period, close, lookahead = barmerge.lookahead_on) : na | |
| g = symbolG != "" ? request.security(symbolG, timeframe.period, close, lookahead = barmerge.lookahead_on) : na | |
| h = symbolH != "" ? request.security(symbolH, timeframe.period, close, lookahead = barmerge.lookahead_on) : na | |
| i = symbolI != "" ? request.security(symbolI, timeframe.period, close, lookahead = barmerge.lookahead_on) : na | |
| j = symbolJ != "" ? request.security(symbolJ, timeframe.period, close, lookahead = barmerge.lookahead_on) : na | |
| // Расчёт спредов | |
| spreadB = not na(b) ? (a / b - 1) * 100 : na | |
| spreadC = not na(c) ? (a / c - 1) * 100 : na | |
| spreadD = not na(d) ? (a / d - 1) * 100 : na | |
| spreadE = not na(e) ? (a / e - 1) * 100 : na | |
| spreadF = not na(f) ? (a / f - 1) * 100 : na | |
| spreadG = not na(g) ? (a / g - 1) * 100 : na | |
| spreadH = not na(h) ? (a / h - 1) * 100 : na | |
| spreadI = not na(i) ? (a / i - 1) * 100 : na | |
| spreadJ = not na(j) ? (a / j - 1) * 100 : na | |
| // ---------- Графика (без вывода в легенду и шкалу) ---------- | |
| plot(spreadB, color=colB, style=plot.style_stepline, linewidth=lineWidth, display=display.data_window + display.pane) | |
| plot(spreadC, color=colC, style=plot.style_stepline, linewidth=lineWidth, display=display.data_window + display.pane) | |
| plot(spreadD, color=colD, style=plot.style_stepline, linewidth=lineWidth, display=display.data_window + display.pane) | |
| plot(spreadE, color=colE, style=plot.style_stepline, linewidth=lineWidth, display=display.data_window + display.pane) | |
| plot(spreadF, color=colF, style=plot.style_stepline, linewidth=lineWidth, display=display.data_window + display.pane) | |
| plot(spreadG, color=colG, style=plot.style_stepline, linewidth=lineWidth, display=display.data_window + display.pane) | |
| plot(spreadH, color=colH, style=plot.style_stepline, linewidth=lineWidth, display=display.data_window + display.pane) | |
| plot(spreadI, color=colI, style=plot.style_stepline, linewidth=lineWidth, display=display.data_window + display.pane) | |
| plot(spreadJ, color=colJ, style=plot.style_stepline, linewidth=lineWidth, display=display.data_window + display.pane) | |
| plot(0, color=color.new(color.white, 40), linewidth=1, display=display.pane) | |
| plot(entryLevel, color=color.new(color.lime, 40), linewidth=1) | |
| plot(-entryLevel,color=color.new(color.lime, 40), linewidth=1) | |
| // Подсветка выходных | |
| isWeekend = dayofweek == dayofweek.saturday or dayofweek == dayofweek.sunday | |
| bgcolor(showWeekends and isWeekend ? weekendClr : na) | |
| // ---------- Подписи: только название биржи на последнем баре ---------- | |
| var label lblB = na | |
| var label lblC = na | |
| var label lblD = na | |
| var label lblE = na | |
| var label lblF = na | |
| var label lblG = na | |
| var label lblH = na | |
| var label lblI = na | |
| var label lblJ = na | |
| if barstate.islast | |
| if not na(spreadB) and symbolB != "" | |
| string exchB = f_exchangeName(symbolB) | |
| label.delete(lblB) | |
| lblB := label.new(bar_index, spreadB, exchB, style=label.style_label_left, color=color.new(colB, 100), textcolor=colB, size=size.small, xloc=xloc.bar_index, yloc=yloc.price) | |
| if not na(spreadC) and symbolC != "" | |
| string exchC = f_exchangeName(symbolC) | |
| label.delete(lblC) | |
| lblC := label.new(bar_index, spreadC, exchC, style=label.style_label_left, color=color.new(colC, 100), textcolor=colC, size=size.small, xloc=xloc.bar_index, yloc=yloc.price) | |
| if not na(spreadD) and symbolD != "" | |
| string exchD = f_exchangeName(symbolD) | |
| label.delete(lblD) | |
| lblD := label.new(bar_index, spreadD, exchD, style=label.style_label_left, color=color.new(colD, 100), textcolor=colD, size=size.small, xloc=xloc.bar_index, yloc=yloc.price) | |
| if not na(spreadE) and symbolE != "" | |
| string exchE = f_exchangeName(symbolE) | |
| label.delete(lblE) | |
| lblE := label.new(bar_index, spreadE, exchE, style=label.style_label_left, color=color.new(colE, 100), textcolor=colE, size=size.small, xloc=xloc.bar_index, yloc=yloc.price) | |
| if not na(spreadF) and symbolF != "" | |
| string exchF = f_exchangeName(symbolF) | |
| label.delete(lblF) | |
| lblF := label.new(bar_index, spreadF, exchF, style=label.style_label_left, color=color.new(colF, 100), textcolor=colF, size=size.small, xloc=xloc.bar_index, yloc=yloc.price) | |
| if not na(spreadG) and symbolG != "" | |
| string exchG = f_exchangeName(symbolG) | |
| label.delete(lblG) | |
| lblG := label.new(bar_index, spreadG, exchG, style=label.style_label_left, color=color.new(colG, 100), textcolor=colG, size=size.small, xloc=xloc.bar_index, yloc=yloc.price) | |
| if not na(spreadH) and symbolH != "" | |
| string exchH = f_exchangeName(symbolH) | |
| label.delete(lblH) | |
| lblH := label.new(bar_index, spreadH, exchH, style=label.style_label_left, color=color.new(colH, 100), textcolor=colH, size=size.small, xloc=xloc.bar_index, yloc=yloc.price) | |
| if not na(spreadI) and symbolI != "" | |
| string exchI = f_exchangeName(symbolI) | |
| label.delete(lblI) | |
| lblI := label.new(bar_index, spreadI, exchI, style=label.style_label_left, color=color.new(colI, 100), textcolor=colI, size=size.small, xloc=xloc.bar_index, yloc=yloc.price) | |
| if not na(spreadJ) and symbolJ != "" | |
| string exchJ = f_exchangeName(symbolJ) | |
| label.delete(lblJ) | |
| lblJ := label.new(bar_index, spreadJ, exchJ, style=label.style_label_left, color=color.new(colJ, 100), textcolor=colJ, size=size.small, xloc=xloc.bar_index, yloc=yloc.price) | |
| // ---------- Оповещения ---------- | |
| anyCrossLevel = ( | |
| ta.cross(spreadB, entryLevel) or ta.cross(spreadB, -entryLevel) or | |
| ta.cross(spreadC, entryLevel) or ta.cross(spreadC, -entryLevel) or | |
| ta.cross(spreadD, entryLevel) or ta.cross(spreadD, -entryLevel) or | |
| ta.cross(spreadE, entryLevel) or ta.cross(spreadE, -entryLevel) or | |
| ta.cross(spreadF, entryLevel) or ta.cross(spreadF, -entryLevel) or | |
| ta.cross(spreadG, entryLevel) or ta.cross(spreadG, -entryLevel) or | |
| ta.cross(spreadH, entryLevel) or ta.cross(spreadH, -entryLevel) or | |
| ta.cross(spreadI, entryLevel) or ta.cross(spreadI, -entryLevel) or | |
| ta.cross(spreadJ, entryLevel) or ta.cross(spreadJ, -entryLevel) | |
| ) | |
| anyCrossZero = ta.cross(spreadB, 0) or ta.cross(spreadC, 0) or ta.cross(spreadD, 0) or ta.cross(spreadE, 0) or | |
| ta.cross(spreadF, 0) or ta.cross(spreadG, 0) or ta.cross(spreadH, 0) or ta.cross(spreadI, 0) or | |
| ta.cross(spreadJ, 0) | |
| alertcondition(anyCrossLevel, title="Spread Level Cross (any leg)", | |
| message="Спред достиг уровня ±0.15% на одном из легов {{ticker}} {{interval}} Close: {{close}}") | |
| alertcondition(anyCrossZero, title="Equal Price Cross (any leg)", | |
| message="Цены сравнялись (спред = 0%) на одном из легов {{ticker}} {{interval}} Close: {{close}}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment