// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © fluxchart //@version=5 const bool DEBUG = false const int maxBoxesCount = 500 const float overlapThresholdPercentage = 0.0 int maxDistanceToLastBar = 1250 // Affects Running Time const int maxSDZones = 30 const int minZoneSize = 10 const int RETEST_COOLDOWN = 5 const int minDistanceBetweenZones = 5 const float maxZoneSizeATR = 1.5 indicator(title = 'Supply & Demand (MTF) | Flux Charts', shorttitle = "Supply and Demand (MTF) | Flux Charts", overlay = true, max_boxes_count = maxBoxesCount, max_labels_count = maxBoxesCount, max_lines_count = maxBoxesCount, max_bars_back = 2000) maxDistanceString = input.string("Normal", "Max Distance To Last Bar", options = ["High", "Normal", "Low"], group = "General Configuration", display = display.none) sdEndMethod = input.string("Close", "Zone Invalidation", options = ["Wick", "Close"], group = "General Configuration", display = display.none) combineSDs = DEBUG ? input.bool(true, "Combine Zones", group = "General Configuration", display = display.none) : true momentumBodyMult = DEBUG ? input.float(0.5, "Momentum Body Mult", step = 0.1, group = "General Configuration") : 0.5 momentumCount = DEBUG ? input.int(4,"Momentum Count", group = "General Configuration") : 4 momentumSpan = DEBUG ? input.int(4, "Momentum Span", group = "General Configuration") : 4 //zoneCount = input.string("High", 'Zone Count', options = ["High", "Medium", "Low", "One"], tooltip = "Number of S&D Zones to be rendered. Higher options will result in older S&Ds shown.", group = "General Configuration", display = display.none) zoneCount = "High" retestsEnabled = input.bool(true, "Retests", inline = "rb", group = "General Configuration", display = display.none) breaksEnabled = input.bool(false, "Breaks", inline = "rb", group = "General Configuration", display = display.none) showInvalidated = input.bool(true, "Show Historic Zones", group = "General Configuration", display = display.none) bullSDZoneColor = input(#08998180, 'Demand', inline = 'sdColor', group = 'General Configuration', display = display.none) bearSDZoneColor = input(#f2364680, 'Supply', inline = 'sdColor', group = 'General Configuration', display = display.none) demandZones = zoneCount == "One" ? 1 : zoneCount == "Low" ? 3 : zoneCount == "Medium" ? 5 : 30 supplyZones = zoneCount == "One" ? 1 : zoneCount == "Low" ? 3 : zoneCount == "Medium" ? 5 : 30 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) textColor = input.color(#ffffffcc, "Text Color", group = "Style") labelsAtSameLevel = DEBUG ? input.bool(true, "[DBG] Place Labels At Same Level", group = "Style") : true labelsAtSameLevelBreak = false atr = ta.atr(20) averageBodySize = ta.sma(math.abs(close - open), 20) maxDistanceToLastBar := maxDistanceString == "Low" ? 150 : maxDistanceString == "Normal" ? 500 : 1250 type sdZoneInfo float top float bottom string sdType int startTime int breakTime int guid string timeframeStr bool disabled = false string combinedTimeframesStr = na bool combined = false type sdZone sdZoneInfo info bool isRendered = false box sdBox = na line sdBoxLineTop = na line sdBoxLineMiddle = na line sdBoxLineBottom = na // box sdBoxText = na type retestLabelContainer int guid array