SWEETLIFE 2
Похожие материалы по тегам
Сообщите нам, если считаете, что материал размещён без разрешения.
Сообщить о материале
Обращение по товару «sweetlife 2_5976621784668052075.pine» отправится на рассмотрение. Укажите контакт для ответа и опишите причину.
О программе
SWEETLIFE 2 — это индикатор для TradingView, предназначенный для анализа уровней поддержки и сопротивления на графике цены. Он определяет ключевые пивоты (разворачивающие точки) по нескольким таймфреймам и отображает линии или зоны на уровне цен, где цена неоднократно разворачивалась. Индикатор визуализирует пробои и ретесты этих уровней, помогая трейдеру отслеживать актуальные зоны интереса. Настройки позволяют гибко управлять количеством отображаемых уровней, чувствительностью, стилем отображения и параметрами таймфреймов.
Настройки программы
| Настройка | Описание |
|---|---|
| resistanceSupportCount | Количество уровней поддержки и сопротивления (Support & Resistance Count). |
| pivotRange | Диапазон для расчёта пивотов (Pivot Range). |
| strength | Сила — во сколько раз цена должна коснуться уровня, чтобы он считался поддержкой или сопротивлением (Strength). |
| invalidationType | Тип подтверждения пробоя уровня: по закрытию (Close) или по свече (Wick) (Invalidation). |
| expandLines | Расширить линии и зоны (Expand Lines & Zones). |
| enableZones | Включить отображение зон поддержки и сопротивления (Enable Zones). |
| zoneWidthType | Тип ширины зоны: фиксированная или динамическая (Zone Width Type). |
| zoneWidth | Фиксированная ширина зоны (Fixed Zone Width). |
| timeframe1Enabled | Включить первый таймфрейм (Timeframe 1 Enabled). |
| timeframe1 | Первый таймфрейм для анализа (Timeframe 1). |
| timeframe2Enabled | Включить второй таймфрейм (Timeframe 2 Enabled). |
| timeframe2 | Второй таймфрейм для анализа (Timeframe 2). |
| timeframe3Enabled | Включить третий таймфрейм (Timeframe 3 Enabled). |
| timeframe3 | Третий таймфрейм для анализа (Timeframe 3). |
| showBreaks | Показать пробои (Show Breaks). |
| showRetests | Показать ретесты (Show Retests). |
| avoidFalseBreaks | Избегать ложных пробоев (Avoid False Breaks). |
| falseBreakoutVolumeThresholdOpt | Порог объёма для определения пробоя (Break Volume Threshold). |
| inverseBrokenLineColor | Инвертировать цвет линии после пробоя (Inverse Color After Broken). |
| lineStyle | Стиль линий (Line Style). |
| lineWidth | Толщина линий (Line Width). |
| supportColor | Цвет уровней поддержки (Support Color). |
| resistanceColor | Цвет уровней сопротивления (Resistance Color). |
| textColor | Цвет текста (Text Color). |
| enableRetestAlerts | Включить алерты ретестов (Enable Retest Alerts). |
| enableBreakAlerts | Включить алерты пробоев (Enable Break Alerts). |
| memoryOptimizatonEnabled | Включить оптимизацию памяти (Enable Memory Optimization). |
| enabledHistory | Включить отображение истории уровней (Enable History). |
| anchor | Использовать альтернативный таймфрейм якоря для расчёта скользящих средних (0=нет, макс=1440 (мин,D,W)). |
| src | Источник данных для EMA (EMA Source). |
| ShowBreak | Показать стрелки алертов пробоя тренда (Show Trend Break Arrow Alerts). |
| ShowSwing | Показать стрелки алертов свинга (Show Swing Arrow Alerts). |
| ShowCon | Давать только алерты при совпадении быстрой и медленной группировки (Give Only Fast+Slow Confluence Alerts). |
| uOCCswing | Добавить изменение цвета свечей к алертам свинга (Add Bar Colour Changes to Swing Alerts). |
| Lookback | Длина откатов для алертов (Lookback Length). |
| ShowAvgs | Показать средние кривые быстрой и медленной группировки Гуппи (Show Average Fast and Slow Guppy Curves). |
| show200 | Показать кривую 200 EMA (Show 200 EMA Curve). |
| emaFilter | Фильтровать алерты с помощью 200 EMA (Filter Alerts with 200ema). |
| clrBars | Окрасить свечи в соответствии с состоянием тренда Гуппи (Colour Candles to Guppy Trend state). |
| lenF1 | Быстрая EMA 1 (Fast EMA 1). |
| lenF2 | Быстрая EMA 2 (Fast EMA 2). |
| lenF3 | Быстрая EMA 3 (Fast EMA 3). |
| lenF4 | Быстрая EMA 4 (Fast EMA 4). |
| lenF5 | Быстрая EMA 5 (Fast EMA 5). |
| lenF6 | Быстрая EMA 6 (Fast EMA 6). |
| lenF7 | Быстрая EMA 7 (Fast EMA 7). |
| lenF8 | Быстрая EMA 8 (Fast EMA 8). |
| lenF9 | Быстрая EMA 9 (Fast EMA 9). |
| lenF10 | Быстрая EMA 10 (Fast EMA 10). |
| lenF11 | Быстрая EMA 11 (Fast EMA 11). |
| lenS1 | Медленная EMA 1 (Slow EMA 1). |
| lenS2 | Медленная EMA 2 (Slow EMA 2). |
| lenS3 | Медленная EMA 3 (Slow EMA 3). |
| lenS4 | Медленная EMA 4 (Slow EMA 4). |
| lenS5 | Медленная EMA 5 (Slow EMA 5). |
| lenS6 | Медленная EMA 6 (Slow EMA 6). |
| lenS7 | Медленная EMA 7 (Slow EMA 7). |
| lenS8 | Медленная EMA 8 (Slow EMA 8). |
| lenS9 | Медленная EMA 9 (Slow EMA 9). |
| lenS10 | Медленная EMA 10 (Slow EMA 10). |
| lenS11 | Медленная EMA 11 (Slow EMA 11). |
| lenS12 | Медленная EMA 12 (Slow EMA 12). |
| lenS13 | Медленная EMA 13 (Slow EMA 13). |
| lenS14 | Медленная EMA 14 (Slow EMA 14). |
| lenS15 | Медленная EMA 15 (Slow EMA 15). |
| lenS16 | Медленная EMA 16 (Slow EMA 16). |
| len | Длина 200 EMA (EMA 200 Length). |
| channel2 | Включить/выключить канал тела свечи (Candle Body Channel On/Off). |
| channel | Включить/выключить канал сопротивления 2 (Resistance Channel 2 On/Off). |
| RST | Длина для расчёта уровней поддержки и сопротивления (Support / Resistance length). |
| length | Длина для расчёта фракталов (Fractal Length). |
| filterFractals | Включить/выключить фильтрацию сигналов (Signal Filter On/Off). |
| len0 | Длина 2 EMA (EMA 2 Length). |
| atrMulti | Чувствительность сигнала (Signal Sensitivity). |
| atrPeriod | Сглаживание (Smoothing). |
| maPeriod | Реактивность (Reactivity). |
| strongest | Сила сильного сигнала (Strong Signal Strength). |
| trendType | Тип расчёта тренда (Trend Calculation Type). |
| maType | Тип расчёта сигналов (Signals Calculation Type). |
| sigs | Показать сигналы (Signal). |
| lines | Показать линию сигнала (Signal Line). |
| extend | Обратный подсчёт сигналов (Reverse Signal Count). |
| confalert | Настройка соединения оповещений (Alert Connect). |
| alert2 | Настройка оповещения сигналов (Signals Alert). |
| mtfResolution | Резолюция мультитаймфрейма (Multi-Timeframe Resolution). |
| atrMultiq | Чувствительность сигнала на мультитаймфрейме (MTF Signal Sensitivity). |
| atrPeriodq | Сглаживание на мультитаймфрейме (MTF Smoothing). |
| maPeriodq | Реактивность на мультитаймфрейме (MTF Reactivity). |
| trendTypeq | Тип расчёта тренда на мультитаймфрейме (MTF Trend Calculation Type). |
| maTypeq | Тип расчёта сигналов на мультитаймфрейме (MTF Signals Calculation Type). |
| sigsq | Показать сигналы на мультитаймфрейме (Multi-Timeframe Signal). |
| linesq | Показать линию сигнала на мультитаймфрейме (Multi-Timeframe Signal Line). |
Поиск по коду файла
const bool DEBUG = false
indicator("SWEETLIFE 2", overlay = true, max_labels_count = 500, max_lines_count = 500, max_boxes_count = 500, max_bars_back = 300, dynamic_requests = true)
const int timeframeCount = 3
const float touchATR = 1.0 / 30.0
const float retestATR = 1.0 / 30.0
const float labelOffsetY = 1.5
const int labelOffsetsXIndex = 30
const int maxPivotsBackSR = 15
const int retestLabelEveryXBars = 3
const int maxTraverse = 275 // Affects bar history limit. Default value 275.
const int maxRetestLabels = 100
const int maxSupports = 3
const int maxResistances = 3
const int debug_maxPivotLabels = 25
const int maxDistanceToLastBar = 450 // Affects Running Time
insideSession = (bar_index > last_bar_index - maxDistanceToLastBar)
resistanceSupportCount = input.int(3, "Support & Resistance Count", options = [1, 2, 3], group = "General Configuration", display = display.none)
pivotRange = input.int(15, "Pivot Range", options = [5, 15, 30], tooltip = "Increase for more general pivots, decrease for more private pivots.", group = "General Configuration", display = display.none)
strength = input.int(1, "Strength", options = [1, 2, 3, 4], tooltip = "X many times price touched relative price area in order to be considered a support/resistance zone.", group = "General Configuration", display = display.none)
invalidationType = input.string("Close", "Invalidation", options = ["Close", "Wick"], group = "General Configuration", display = display.none)
expandLines = input.bool(true, "Expand Lines & Zones", group = "General Configuration", display = display.none)
enableZones = input.bool(false, "Enable Zones", group = "Support & Resistance Zones", display = display.none)
zoneWidthType = input.string("Dynamic", "Zone Width Type", options = ["Fixed", "Dynamic"], group = "Support & Resistance Zones", display = display.none)
zoneWidth = input.int(1, "Fixed Zone Width", options = [1, 2, 3], group = "Support & Resistance Zones", display = display.none)
timeframe1Enabled = input.bool(true, title = "", group = "Timeframes", inline = "timeframe1", display = display.none)
timeframe1 = input.timeframe("", title = "", group = "Timeframes", inline = "timeframe1", display = display.none)
timeframe2Enabled = input.bool(false, title = "", group = "Timeframes", inline = "timeframe2", display = display.none)
timeframe2 = input.timeframe("15", title = "", group = "Timeframes", inline = "timeframe2", display = display.none)
timeframe3Enabled = input.bool(false, title = "", group = "Timeframes", inline = "timeframe3", display = display.none)
timeframe3 = input.timeframe("30", title = "", group = "Timeframes", inline = "timeframe3", display = display.none)
showBreaks = input.bool(true,"Show Breaks", group = "Breaks & Retests", inline = "ShowBR", display = display.none)
showRetests = input.bool(true,"Show Retests", group = "Breaks & Retests", inline = "ShowBR", display = display.none)
avoidFalseBreaks = input.bool(true, "Avoid False Breaks", group = "Breaks & Retests", display = display.none)
falseBreakoutVolumeThresholdOpt = input.float(0.3, "Break Volume Threshold", minval = 0.1, maxval = 1.0, step = 0.1, group = "Breaks & Retests", tooltip = "Only taken into account if Avoid False Breakouts is enabled.\nHigher values mean it's less likely to be a break.", display = display.none)
inverseBrokenLineColor = input.bool(true, "Inverse Color After Broken", tooltip = "Needs Show Breaks & Expand Lines option enabled.", group = "Breaks & Retests", display = display.none)
falseBreakoutVolumeThreshold = falseBreakoutVolumeThresholdOpt * 100.0
lineStyle = input.string("____", "Line Style", ["____", "----", "...."], group = "Style", display = display.none)
lineWidth = input.int(2, "Line Width", minval = 1, group = "Style", display = display.none)
supportColor = input.color(#08998180, "Support Color", group = "Style", inline = "RScolors", display = display.none)
resistanceColor = input.color(#f2364580, "Resistance Color", group = "Style", inline = "RScolors", display = display.none)
textColor = input.color(#ffffff80, "Text Color", group = "Style", inline = "RScolors", display = display.none)
labelsAlign = DEBUG ? input.string("Right", "Align Labels", options = ["Right"], group = "Style", tooltip = "Will only work when zones are disabled.", display = display.none) : "Right"
enableRetestAlerts = input.bool(true, "Enable Retest Alerts", tooltip = "Needs Show Retests option enabled.", group = "Alerts", display = display.none)
enableBreakAlerts = input.bool(true, "Enable Break Alerts", group = "Alerts", display = display.none)
memoryOptimizatonEnabled = input.bool(false, "Enable Memory Optimization", tooltip = "Enable this option if you encounter memory errors.", group = "Advanced", display = display.none)
enabledHistory = input.bool(true, "Enable History", group = "Advanced")
debug_labelPivots = not DEBUG ? "None" : input.string("None", title = "[DBG] Label Pivots", group = "DEBUG", options = ["All", "RS", "None"], tooltip = "All -> Debugs all pivot labels.\nRS -> Debugs RS pivot labels.\nNone -> Debugs none of the last R&S pivots.")
debug_pivotLabelText = not DEBUG ? false : input.bool(false, title = "[DBG] Pivot Label Text", group = "DEBUG")
debug_showBrokenOnLabel = not DEBUG ? false : input.bool(false, "[DBG] Show Broken Text On Label", group = "DEBUG")
debug_removeDuplicateRS = not DEBUG ? true : input.bool(true, "[DBG] Remove Duplicate RS", group = "DEBUG")
debug_lastXResistances = not DEBUG ? 3 : input.int(3, "[DBG] Show Last X Resistances", minval = 0, maxval = maxResistances, group = "DEBUG")
debug_lastXSupports = not DEBUG ? 3 : input.int(3, "[DBG] Show Last X Supports", minval = 0, maxval = maxSupports, group = "DEBUG")
debug_maxHistoryRecords = not DEBUG ? 10 : input.int(10, "[DBG] Max History Records", options = [1, 2, 5, 10, 25], group = "DEBUG")
atr = ta.atr(30)
createRSLine (color) =>
line.new(na, na, na, na, extend = expandLines ? extend.both : extend.none, xloc=xloc.bar_time, color = color, width = lineWidth, style = lineStyle == "----" ? line.style_dashed : lineStyle == "...." ? line.style_dotted : line.style_solid)
createRSBox (color, xlocType) =>
box.new(na, na, na, na, text_size = size.normal, xloc = xlocType, extend = extend.both, bgcolor = color, text_color = textColor, text_halign = expandLines ? text.align_right : text.align_center, border_color = #00000000)
createRSLabel () =>
label.new(na, na, "", style = label.style_none, textcolor = textColor)
createBreakLabel (RSType) =>
label.new(na,na,"B",style = RSType == "Resistance" ? label.style_label_up : label.style_label_down, color=color.blue, textcolor = color.white, xloc = xloc.bar_time, size = size.small)
createRetestLabel (RSType) =>
label.new(na,na,"R",style = RSType == "Resistance" ? label.style_label_down : label.style_label_up, color = RSType == "Resistance" ? resistanceColor : supportColor, textcolor = color.white, xloc = xloc.bar_time, size = size.small)
moveLine(_line, _x, _y, _x2) =>
line.set_xy1(_line, _x, _y)
line.set_xy2(_line, _x2, _y)
moveBox (_box, _topLeftX, _topLeftY, _bottomRightX, _bottomRightY) =>
box.set_lefttop(_box, _topLeftX, _topLeftY)
box.set_rightbottom(_box, _bottomRightX, _bottomRightY)
moveRSInfoBox (_box, _startPointX, _price, _endPointX) =>
zoneWidthPercent = zoneWidth == 1 ? 0.05 : zoneWidth == 2 ? 0.06 : 0.075
if zoneWidthType == "Dynamic"
zoneWidthPercent := ((atr) / _price) * 100 / 3.0
topY = _price * (1.0 + (zoneWidthPercent / 2.0 / 100.0))
bottomY = _price * (1.0 - (zoneWidthPercent / 2.0 / 100.0))
moveBox(_box, _startPointX, topY, _endPointX, bottomY)
type customPoint
int t
float price
type RSInfo
bool isBroken = na
int brokenTime = na
string RSType = na
float price = na
line line = na
box box = na
label priceLabel = na
customPoint[] points = na
label[] debugPoints = na
label breakLabel = na
label[] retestLabels = na
line breakLine = na
box breakBox = na
curTR = ta.tr(true)
lowPivot = ta.pivotlow(low, pivotRange, pivotRange)
highPivot = ta.pivothigh(high, pivotRange, pivotRange)
pivotTime = time[pivotRange]
newRSInfo (RSType) =>
newRSInfoF = RSInfo.new()
newRSInfoF.RSType := RSType
newRSInfoF.price := na
newRSInfoF.isBroken := false
newRSInfoF.brokenTime := na
newRSInfoF.line := enableZones ? na : createRSLine(RSType == "Resistance" ? resistanceColor : supportColor)
newRSInfoF.box := enableZones ? createRSBox(RSType == "Resistance" ? resistanceColor : supportColor, xloc.bar_time) : na
newRSInfoF.priceLabel := enableZones ? na : createRSLabel()
newRSInfoF.points := array.new<customPoint>(0)
newRSInfoF.debugPoints := array.new<label>(0)
newRSInfoF.retestLabels := array.new<label>(0)
newRSInfoF.breakLabel := na
newRSInfoF.breakLine := na
newRSInfoF.breakBox := na
newRSInfoF
histRSInfo (RSInfo RSInfoF) =>
RSType = RSInfoF.RSType
newRS = RSInfo.new()
newRS.RSType := RSType
newRS.price := RSInfoF.price
newRS.debugPoints := array.new<label>(0)
newRS.retestLabels := array.new<label>(0)
newRS.points := array.new<customPoint>(0)
histText = "History | " + str.tostring(newRS.price, format.mintick)
startTime = math.min(time, RSInfoF.points.get(RSInfoF.points.size() - 1).t)
endTime = RSInfoF.isBroken ? RSInfoF.brokenTime : time
if enableZones
newRS.box := createRSBox(RSType == "Resistance" ? resistanceColor : supportColor, xloc.bar_time)
moveRSInfoBox(newRS.box, startTime, newRS.price, endTime)
box.set_extend(newRS.box, expandLines ? extend.both : extend.none)
box.set_text(newRS.box, histText)
else
newRS.line := line.copy(RSInfoF.line)
moveLine(newRS.line, startTime, newRS.price, endTime)
line.set_extend(newRS.line, expandLines ? extend.both : extend.none)
newRS.priceLabel := label.copy(RSInfoF.priceLabel)
label.set_text(newRS.priceLabel, histText)
label.set_xloc(newRS.priceLabel, (startTime + endTime) / 2, xloc.bar_time)
if not na(newRS.breakLabel)
newRS.breakLabel := label.copy(RSInfoF.breakLabel)
newRS
derenderRSInfo (RSInfo RSInfoF) =>
if not na(RSInfoF)
line.delete(RSInfoF.line)
box.delete(RSInfoF.box)
label.delete(RSInfoF.priceLabel)
if RSInfoF.debugPoints.size() > 0
for i = 0 to RSInfoF.debugPoints.size() - 1
label.delete(RSInfoF.debugPoints.get(i))
if RSInfoF.retestLabels.size() > 0
for i = 0 to RSInfoF.retestLabels.size() - 1
label.delete(RSInfoF.retestLabels.get(i))
label.delete(RSInfoF.breakLabel)
line.delete(RSInfoF.breakLine)
box.delete(RSInfoF.breakBox)
safeDeleteRSInfo (RSInfo RSInfoF) =>
if not na(RSInfoF)
derenderRSInfo(RSInfoF)
RSInfoF.points.clear()
RSInfoF.debugPoints.clear()
RSInfoF.retestLabels.clear()
type timeframeInfo
int index = na
string timeframeStr = na
bool isEnabled = false
RSInfo[] resistances = na
RSInfo[] supports = na
float[] highPivots = na
float[] highTRs = na
int[] highTimes = na
float[] lowPivots = na
float[] lowTRs = na
int[] lowTimes = na
newTimeframeInfo (index, timeframeStr, isEnabled) =>
newTFInfo = timeframeInfo.new()
newTFInfo.index := index
newTFInfo.isEnabled := isEnabled
newTFInfo.timeframeStr := timeframeStr
newTFInfo.resistances := array.new<RSInfo>(debug_lastXResistances)
newTFInfo.supports := array.new<RSInfo>(debug_lastXSupports)
newTFInfo.highPivots := array.new<float>()
newTFInfo.highTRs := array.new<float>()
newTFInfo.highTimes := array.new<int>()
newTFInfo.lowPivots := array.new<float>()
newTFInfo.lowTRs := array.new<float>()
newTFInfo.lowTimes := array.new<int>()
newTFInfo
var timeframeInfo[] timeframeInfos = array.from(newTimeframeInfo(1, timeframe1, timeframe1Enabled), newTimeframeInfo(2, timeframe2, timeframe2Enabled), newTimeframeInfo(3, timeframe3, timeframe3Enabled))
var bool initRun = true
var float[] allLowPivots = array.new<float>(0)
var float[] allHighPivots = array.new<float>(0)
var int[] allLowTimes = array.new<int>(0)
var int[] allHighTimes = array.new<int>(0)
var float[] allHighTR = array.new<float>(0)
var float[] allLowTR = array.new<float>(0)
var RSInfo[] history = array.new<RSInfo>(0)
RSInfo[] curRSList = array.new<RSInfo>(0)
RSInfo[] oldRSList = array.new<RSInfo>(0)
int maxPivotsAllowed = memoryOptimizatonEnabled ? 7 : 15 // Affects memory limit. Default value 15.
doValuesTouch (float value1, float value2, float tr) =>
if math.abs(value1 - value2) <= tr * touchATR
true
else
false
doValuesTouch (float value1, float value2, float tr, float customATRRatio) =>
if math.abs(value1 - value2) <= tr * customATRRatio
true
else
false
findLatestRS (timeframeInfo timeframeInfoF, string RSType, pivots, times, trs, bannedValues) =>
RSInfo latestRSF = na
pivotsCount = pivots.size()
if pivotsCount > 0
for i = 0 to pivotsCount - 1
if i >= maxTraverse
break
index = pivotsCount - i - 1
occurances = 0
invalidValue = false
pivotValue1 = pivots.get(index)
if bannedValues.size() > 0
for a = 0 to bannedValues.size() - 1
if doValuesTouch(pivotValue1, bannedValues.get(a), trs.get(index))
invalidValue := true
break
if invalidValue
continue
for j = 0 to pivotsCount - 1
if j >= maxTraverse
break
index2 = pivotsCount - j - 1
pivotValue2 = pivots.get(index2)
if doValuesTouch(pivotValue1, pivotValue2, trs.get(index))
occurances += 1
if occurances >= strength
latestRSF := newRSInfo(RSType)
latestRSF.price := pivotValue1
break
if math.abs(index - index2) > maxPivotsBackSR * strength
break
if not na(latestRSF)
break
if not na(latestRSF)
cnt = 0
if pivotsCount > 0
for i = 0 to pivotsCount - 1
if i >= maxTraverse
break
index = pivotsCount - i - 1
pivotValue = pivots.get(index)
if doValuesTouch(pivotValue, latestRSF.price, trs.get(index))
labelTime = times.get(index)
latestRSF.points.push(customPoint.new(labelTime, pivotValue))
cnt += 1
if cnt == strength
break
if not (debug_labelPivots == "None")
if not (debug_labelPivots == "All")
if not na(latestRSF)
cnt = 0
if pivotsCount > 0
for i = 0 to pivotsCount - 1
index = pivotsCount - i - 1
pivotValue = pivots.get(index)
if doValuesTouch(pivotValue, latestRSF.price, trs.get(index))
labelTime = times.get(index)
latestRSF.debugPoints.push(RSType == "Resistance" ? label.new(labelTime,pivotValue,text=debug_pivotLabelText ? str.tostring(pivotValue) : "",xloc=xloc.bar_time, color=resistanceColor, textcolor=color.white) : label.new(labelTime,pivotValue,text=debug_pivotLabelText ? str.tostring(pivotValue) : "",xloc=xloc.bar_time, color=supportColor,style = label.style_label_up, textcolor=color.white))
cnt += 1
if cnt == strength
break
else
if not na(latestRSF)
if pivotsCount > 0
for i = 0 to pivotsCount - 1
index = pivotsCount - i - 1
pivotValue = pivots.get(index)
labelTime = times.get(index)
latestRSF.debugPoints.push(RSType == "Resistance" ? label.new(labelTime,pivotValue,text=debug_pivotLabelText ? str.tostring(pivotValue) : "",xloc=xloc.bar_time, color=resistanceColor, textcolor=color.white) : label.new(labelTime,pivotValue,text=debug_pivotLabelText ? str.tostring(pivotValue) : "",xloc=xloc.bar_time, color=supportColor,style = label.style_label_up, textcolor=color.white))
if latestRSF.debugPoints.size() > debug_maxPivotLabels
break
latestRSF
findLatestNthRS (timeframeInfo timeframeInfoF, string RSType, pivots, times, trs, n) =>
float[] bannedValues = array.new<float>()
foundRS = 0
RSInfo foundLatestRS = na
while foundRS < n
foundLatestRS := findLatestRS(timeframeInfoF, RSType, pivots, times, trs, bannedValues)
if not na(foundLatestRS)
foundRS += 1
bannedValues.push(foundLatestRS.price)
else
break
foundLatestRS
isTimeframeLower (timeframe1F, timeframe2F) =>
timeframe.in_seconds(timeframe1F) < timeframe.in_seconds(timeframe2F)
getMinTimeframe (timeframe1F, timeframe2F) =>
if isTimeframeLower(timeframe1F, timeframe2F)
timeframe1F
else
timeframe2F
getMaxTimeframe (timeframe1F, timeframe2F) =>
if isTimeframeLower(timeframe1F, timeframe2F)
timeframe2F
else
timeframe1F
getFirstBreak (RSInfo rsInfo) =>
if na(rsInfo)
[na, na]
curIndex = 0
float foundBreakLevel = na
int foundBreakTime = na
float foundBreakTR = na
while true
if curIndex >= maxTraverse
break
oldPriceRes = (invalidationType == "Close" ? close[curIndex + 1] : high[curIndex + 1])
newPriceRes = (invalidationType == "Close" ? close[curIndex] : high[curIndex])
oldPriceSup = (invalidationType == "Close" ? close[curIndex + 1] : low[curIndex + 1])
newPriceSup = (invalidationType == "Close" ? close[curIndex] : low[curIndex])
isBarBreak = (rsInfo.RSType == "Resistance" ? (oldPriceRes <= rsInfo.price and newPriceRes > rsInfo.price) : (oldPriceSup >= rsInfo.price and newPriceSup < rsInfo.price))
if isBarBreak
isTrueBreakout = true
if avoidFalseBreaks
shortTerm = 2
longTerm = 15
shortSum = 0.0
longSum = 0.0
for i = 0 to shortTerm
shortSum += volume[curIndex + i]
for i = 0 to longTerm
longSum += volume[curIndex + i]
shortVolumeAvg = shortSum / shortTerm
longVolumeAvg = longSum / longTerm
volumeRatio = ((shortVolumeAvg - longVolumeAvg) / longVolumeAvg) * 100.0
isTrueBreakout := (volumeRatio >= falseBreakoutVolumeThreshold)
if isTrueBreakout
foundBreakLevel := rsInfo.RSType == "Resistance" ? low[curIndex] : high[curIndex]
foundBreakTime := time[curIndex]
foundBreakTR := high[curIndex] - low[curIndex]
curIndex += 1
if time[curIndex] <= rsInfo.points.get(rsInfo.points.size() - 1).t
break
[foundBreakLevel, foundBreakTime, foundBreakTR]
getRetests (RSInfo rsInfo) =>
if na(rsInfo)
[na,na]
curIndex = 0
lastRetestIndex = -999
int[] retestTimes = array.new<int>()
float[] retestLevels = array.new<float>()
float[] retestTRs = array.new<float>()
while true
if curIndex >= maxTraverse
break
if retestLevels.size() == maxRetestLabels
break
if rsInfo.isBroken and time[curIndex] >= rsInfo.brokenTime
curIndex += 1
continue
tr = high[curIndex] - low[curIndex]
isRetest = (rsInfo.RSType == "Resistance" ? (doValuesTouch(rsInfo.price, close[curIndex], tr, retestATR) or doValuesTouch(rsInfo.price, high[curIndex], tr, retestATR)) : (doValuesTouch(rsInfo.price, close[curIndex], tr, retestATR) or doValuesTouch(rsInfo.price, low[curIndex], tr, retestATR)))
if isRetest and curIndex - lastRetestIndex >= retestLabelEveryXBars
retestLevels.push(rsInfo.RSType == "Resistance" ? high[curIndex] : low[curIndex])
retestTimes.push(time[curIndex])
retestTRs.push(high[curIndex] - low[curIndex])
lastRetestIndex := curIndex
curIndex += 1
if time[curIndex] <= rsInfo.points.get(rsInfo.points.size() - 1).t
break
[retestLevels, retestTimes, retestTRs]
formatTimeframeString (formatTimeframe) =>
timeframeF = formatTimeframe == "" ? timeframe.period : formatTimeframe
if str.contains(timeframeF, "D") or str.contains(timeframeF, "W") or str.contains(timeframeF, "S") or str.contains(timeframeF, "M")
timeframeF
else
seconds = timeframe.in_seconds(timeframeF)
if seconds >= 3600
hourCount = int(seconds / 3600)
str.tostring(hourCount) + " Hour" + (hourCount > 1 ? "s" : "")
else
timeframeF + " Min"
handleRSInfo (timeframeInfo timeframeInfoF, RSInfo RSInfoF, int index, string RSType) =>
if not na(RSInfoF)
if not na(timeframeInfoF)
curRSList.push(RSInfoF)
[foundBreakLevel, foundBreakTime, foundBreakTR] = getFirstBreak(RSInfoF)
RSInfoF.isBroken := na(foundBreakLevel) ? false : true
RSInfoF.brokenTime := na(foundBreakLevel) ? na : foundBreakTime
if not na(foundBreakLevel)
if showBreaks
if na(RSInfoF.breakLabel)
RSInfoF.breakLabel := createBreakLabel(RSInfoF.RSType)
label.set_xy(RSInfoF.breakLabel, foundBreakTime, foundBreakLevel + (RSInfoF.RSType == "Resistance" ? (-foundBreakTR / labelOffsetY) : foundBreakTR / labelOffsetY))
if expandLines
if na(RSInfoF.breakLine) and enableZones == false
RSInfoF.breakLine := createRSLine(color.black)
if na(RSInfoF.breakBox) and enableZones == true
RSInfoF.breakBox := createRSBox(color.black, xloc.bar_time)
if not enableZones
line.set_extend(RSInfoF.breakLine, extend.right)
else
box.set_extend(RSInfoF.breakBox, extend.right)
if inverseBrokenLineColor and showBreaks
if not enableZones
line.set_color(RSInfoF.breakLine, RSInfoF.RSType == "Resistance" ? supportColor : resistanceColor)
else
box.set_bgcolor(RSInfoF.breakBox, RSInfoF.RSType == "Resistance" ? supportColor : resistanceColor)
else
if not enableZones
line.set_color(RSInfoF.breakLine, RSInfoF.RSType == "Resistance" ? resistanceColor : supportColor)
else
box.set_bgcolor(RSInfoF.breakBox, RSInfoF.RSType == "Resistance" ? resistanceColor : supportColor)
if showRetests
[retestLevels, retestTimes, retestTRs] = getRetests(RSInfoF)
if not na(retestLevels) and retestLevels.size() > 0
for i = 0 to retestLevels.size() - 1
newRetestLabel = createRetestLabel(RSInfoF.RSType)
label.set_xy(newRetestLabel, retestTimes.get(i), retestLevels.get(i) + (RSInfoF.RSType == "Support" ? (-retestTRs.get(i) / labelOffsetY) : retestTRs.get(i) / labelOffsetY))
RSInfoF.retestLabels.push(newRetestLabel)
timeSkipOffset = 0
if enableZones
zoneEndX = time + timeSkipOffset + timeframe.in_seconds(timeframe.period) * 1000 * labelOffsetsXIndex
startTime = math.min(time, RSInfoF.points.get(RSInfoF.points.size() - 1).t)
moveRSInfoBox(RSInfoF.box, startTime, RSInfoF.price, na(foundBreakTime) ? zoneEndX : foundBreakTime)
moveRSInfoBox(RSInfoF.breakBox, foundBreakTime, RSInfoF.price, zoneEndX)
else
endTime = time + timeSkipOffset + timeframe.in_seconds(timeframe.period) * 1000
startTime = math.min(time, RSInfoF.points.get(RSInfoF.points.size() - 1).t)
moveLine(RSInfoF.line, startTime, RSInfoF.price, na(foundBreakTime) ? endTime : foundBreakTime)
moveLine(RSInfoF.breakLine, foundBreakTime, RSInfoF.price, endTime)
if expandLines
if not enableZones
line.set_extend(RSInfoF.line, (na(foundBreakTime)) ? extend.both : extend.left)
else
box.set_extend(RSInfoF.box, (na(foundBreakTime)) ? extend.both : extend.left)
else
if not enableZones
line.set_extend(RSInfoF.line, na(foundBreakTime) ? extend.right : extend.none)
else
box.set_extend(RSInfoF.box, na(foundBreakTime) ? extend.right : extend.none)
labelTitle = formatTimeframeString(timeframeInfoF.timeframeStr) + " | " + str.tostring(RSInfoF.price,format.mintick) + ((debug_showBrokenOnLabel and RSInfoF.isBroken) ? " [B]" : "")
if not enableZones
label.set_text(RSInfoF.priceLabel, enableZones ? "" : labelTitle)
label.set_y(RSInfoF.priceLabel, RSInfoF.price)
else
box.set_text(RSInfoF.box, (RSInfoF.isBroken and expandLines) ? "" : labelTitle)
box.set_text(RSInfoF.breakBox, labelTitle)
if expandLines or not RSInfoF.isBroken
if not enableZones
if labelsAlign == "Right"
label.set_xloc(RSInfoF.priceLabel, bar_index + labelOffsetsXIndex, xloc.bar_index)
else
box.set_text_halign(RSInfoF.breakBox, text.align_right)
box.set_text_halign(RSInfoF.box, text.align_right)
else
if not enableZones
label.set_xloc(RSInfoF.priceLabel, (RSInfoF.points.get(RSInfoF.points.size() - 1).t + RSInfoF.brokenTime) / 2, xloc.bar_time)
else
box.set_text_halign(RSInfoF.box, text.align_center)
box.set_text_halign(RSInfoF.breakBox, text.align_center)
else
log.error("Couldn't find timeframe " + str.tostring(timeframeInfoF.index) + " " + str.tostring(index + 1) + "th " + RSType + " . Try decreasing pivot range in the settings.")
handleTimeframe (timeframeIndex, lowPivots, highPivots, lowTimes, highTimes, lowTRs, highTRs) =>
timeframeInfoF = timeframeInfos.get(timeframeIndex - 1)
timeframeInfoF.lowPivots.clear()
timeframeInfoF.highPivots.clear()
timeframeInfoF.lowTimes.clear()
timeframeInfoF.highTimes.clear()
timeframeInfoF.lowTRs.clear()
timeframeInfoF.highTRs.clear()
timeframeInfoF.lowPivots := lowPivots
timeframeInfoF.highPivots := highPivots
timeframeInfoF.lowTimes := lowTimes
timeframeInfoF.highTimes := highTimes
timeframeInfoF.lowTRs := lowTRs
timeframeInfoF.highTRs := highTRs
getHigherTFData (timeframeStr) =>
if timeframe.in_seconds() < timeframe.in_seconds(timeframeStr)
request.security(syminfo.tickerid, getMaxTimeframe(timeframe.period, timeframeStr), [allLowPivots, allHighPivots, allLowTimes, allHighTimes, allLowTR, allHighTR], calc_bars_count = maxTraverse)
else if timeframe.in_seconds() == timeframe.in_seconds(timeframeStr)
[allLowPivots, allHighPivots, allLowTimes, allHighTimes, allLowTR, allHighTR]
pushHighPivots (timeframeInfoF, highPivotF, timeF, trF) =>
if not na(highPivotF)
timeframeInfoF.highPivots.push(highPivotF)
timeframeInfoF.highTimes.push(timeF)
timeframeInfoF.highTRs.push(trF)
pushLowPivots (timeframeInfoF, lowPivotF, timeF, trF) =>
if not na(lowPivotF)
timeframeInfoF.lowPivots.push(lowPivotF)
timeframeInfoF.lowTimes.push(timeF)
timeframeInfoF.lowTRs.push(trF)
handleTimeframeIfLower (timeframeInfo timeframeInfoF, highs, lows, int[] timesF, float[] trsF) =>
if timeframeInfoF.isEnabled and isTimeframeLower(timeframeInfoF.timeframeStr, timeframe.period)
if not na(highs)
if highs.size() > 0
for i = 0 to highs.size() - 1
timeF = timesF.get(i)
pushHighPivots(timeframeInfoF, highs.get(i), timeF, trsF.get(i))
if not na(lows)
if lows.size() > 0
for i = 0 to lows.size() - 1
timeF = timesF.get(i)
pushLowPivots(timeframeInfoF, lows.get(i), timeF, trsF.get(i))
getLowerTFData (timeframeStr) =>
if timeframe.in_seconds(timeПоказано первые 50% кода (символов: 45243)
Открыть по тарифу
Купите тариф с пакетом открытий или войдите, если тариф уже есть. Открытый файл останется в вашем кабинете навсегда.
Разовая покупка файла
На этой странице откроется полный исходный код файла вместо ознакомительного фрагмента.
Зачем нужен email? После подтверждения оплаты файл сохранится в кабинете на этот email. Если аккаунта ещё нет, мы создадим его и пришлём ссылку для задания пароля. Если аккаунт уже есть, покупка добавится в него. Укажите адрес, к которому у вас есть доступ.
Чтобы оформить заказ, введите email и перейдите к оплате.