Script search bug?
▲ 4 r/pinescript+1 crossposts

Script search bug?

Is TradingView’s “Most Recent” scripts page lagging for anyone else? It’s August 16th, but when I sort Indicators and Strategies by Most Recent, the newest scripts I’m seeing are from August 14th. I’ve also tried it with the Open-source only filter, is anyone else getting the same results, or is it just on my end? I would expect a major public Pine repository like TradingView to receive publications considerably more frequently than once every two days.

u/LouZEverything — 5 days ago

State Machine Entry Debugger

//
@version=
6
indicator("State Machine Entry Debugger", overlay=true, max_labels_count=500)


//──────────────────────────────────────────────────────────────────────────────
// GROUP A — DEBUG SETTINGS
//──────────────────────────────────────────────────────────────────────────────


groupDebug = "A. Debug Settings"


showEventLabels = input.bool(true, "Show State Event Labels", group=groupDebug)
showBlockedLabels = input.bool(true, "Show Blocked-State Labels", group=groupDebug)
showStateBackground = input.bool(true, "Color Background by State", group=groupDebug)
showDebugTable = input.bool(true, "Show Debug Table", group=groupDebug)
showOnlyRecentBars = input.bool(true, "Limit Labels to Recent Bars", group=groupDebug)


recentBars = input.int(500, "Recent Bars to Debug", minval=50, maxval=5000, group=groupDebug)
maxBarsArmed = input.int(5, "Maximum Bars Allowed in ARM State", minval=1, group=groupDebug)
maxBarsTouched = input.int(5, "Maximum Bars Allowed After Touch", minval=1, group=groupDebug)


//=============================================================================
// GROUP B — PLACEHOLDER CONDITIONS
//=============================================================================
// Replace these conditions with the conditions from your actual strategy.
// These examples exist only so the debugger compiles and demonstrates its
// operation. They are not intended to be used as a trading system.
//=============================================================================


groupExample = "B. Placeholder Conditions"


fastLength = input.int(9, "Fast EMA", minval=1, group=groupExample)
slowLength = input.int(21, "Slow EMA", minval=1, group=groupExample)
breakoutLength = input.int(10, "Breakout Length", minval=1, group=groupExample)
extensionATR = input.float(1.5, "Maximum Extension ATR", minval=0.0, step=0.1, group=groupExample)


fastEMA = ta.ema(close, fastLength)
slowEMA = ta.ema(close, slowLength)
atrValue = ta.atr(14)


priorHigh = ta.highest(high, breakoutLength)[1]
pullbackLevel = fastEMA


//-----------------------------------------------------------------------------
// REPLACE THESE PLACEHOLDER CONDITIONS
//-----------------------------------------------------------------------------
bool
 touchCondition = low <= pullbackLevel and high >= pullbackLevel
bool
 trendFilter = fastEMA > slowEMA
bool
 qualityFilter = atrValue > 0 and math.abs(fastEMA - slowEMA) / atrValue > 0.10


float
 extensionDistance = atrValue > 0 ? math.abs(close - fastEMA) / atrValue : 0.0


bool
 extensionFilter = extensionDistance <= extensionATR
bool
 triggerCondition = not na(priorHigh) and close > priorHigh
bool
 entryPermission = true


//──────────────────────────────────────────────────────────────────────────────
// GROUP C — HELPER FUNCTIONS
//──────────────────────────────────────────────────────────────────────────────


yesNo(
bool
 condition) =>
    condition ? "PASS" : "FAIL"


formatInteger(
int
 value) =>
    na(value) ? "NA" : str.tostring(value)


stateToText(
int
 stateValue) => stateValue == 0 ? "IDLE" : stateValue == 1 ? "TOUCHED" : stateValue == 2 ? "ARMED" : stateValue == 3 ? "TRIGGERED" : stateValue == 4 ? "ENTERED" : "UNKNOWN"


//=============================================================================
// GROUP D — STATE CONSTANTS
//=============================================================================


const
 
int
 STATE_IDLE = 0
const
 
int
 STATE_TOUCHED = 1
const
 
int
 STATE_ARMED = 2
const
 
int
 STATE_TRIGGERED = 3
const
 
int
 STATE_ENTERED = 4


var 
int
 tradeState = STATE_IDLE


//=============================================================================
// GROUP E — PERSISTENT TIMELINE VALUES
//=============================================================================


var 
int
 touchBar = na
var 
int
 armBar = na
var 
int
 triggerBar = na
var 
int
 entryBar = na


var 
float
 touchPrice = na
var 
float
 armPrice = na
var 
float
 triggerPrice = na
var 
float
 entryPrice = na


var 
string
 lastBlockReason = "None"
var 
string
 lastEvent = "Waiting"


//=============================================================================
// GROUP F — PER-BAR EVENT FLAGS
//=============================================================================


bool
 newTouch = false
bool
 newArm = false
bool
 newTrigger = false
bool
 newEntry = false


bool
 resetEvent = false
bool
 touchExpired = false
bool
 armExpired = false


bool
 trendBlocked = false
bool
 qualityBlocked = false
bool
 extensionBlocked = false
bool
 triggerBlocked = false
bool
 permissionBlocked = false


//=============================================================================
// GROUP G — BAR AGE CALCULATIONS
//=============================================================================


int
 barsSinceTouch = not na(touchBar) ? bar_index - touchBar : na
int
 barsSinceArm = not na(armBar) ? bar_index - armBar : na
int
 barsSinceTrigger = not na(triggerBar) ? bar_index - triggerBar : na


bool
 touchStillValid = not na(barsSinceTouch) and barsSinceTouch <= maxBarsTouched
bool
 armStillValid = not na(barsSinceArm) and barsSinceArm <= maxBarsArmed


//=============================================================================
// GROUP H — STATE TRANSITION LOGIC
//=============================================================================
// This intentionally permits only one transition per bar.
//
// That means:
// Bar 1 = Touch
// Bar 2 = ARM
// Bar 3 = Trigger
// Bar 4 = Entry
//
// This structure helps expose whether your original strategy is producing
// delays because each stage must begin the bar in the required prior state.
//=============================================================================


if tradeState == STATE_IDLE
    if touchCondition
        tradeState := STATE_TOUCHED


        touchBar := bar_index
        touchPrice := close


        armBar := na
        triggerBar := na
        entryBar := na


        armPrice := na
        triggerPrice := na
        entryPrice := na


        newTouch := true
        lastEvent := "Touch"
        lastBlockReason := "None"


else if tradeState == STATE_TOUCHED
    if not touchStillValid
        tradeState := STATE_IDLE
        touchExpired := true
        resetEvent := true
        lastEvent := "Touch Expired"
        lastBlockReason := "Touch expired before ARM"


    else if not trendFilter
        trendBlocked := true
        lastBlockReason := "Trend filter"


    else if not qualityFilter
        qualityBlocked := true
        lastBlockReason := "Quality filter"


    else if not extensionFilter
        extensionBlocked := true
        lastBlockReason := "Extension filter"


    else
        tradeState := STATE_ARMED
        armBar := bar_index
        armPrice := close
        newArm := true
        lastEvent := "ARM"
        lastBlockReason := "None"


else if tradeState == STATE_ARMED
    if not armStillValid
        tradeState := STATE_IDLE
        armExpired := true
        resetEvent := true
        lastEvent := "ARM Expired"
        lastBlockReason := "ARM expired before Trigger"


    else if not triggerCondition
        triggerBlocked := true
        lastBlockReason := "Trigger condition"


    else
        tradeState := STATE_TRIGGERED
        triggerBar := bar_index
        triggerPrice := close
        newTrigger := true
        lastEvent := "Trigger"
        lastBlockReason := "None"


else if tradeState == STATE_TRIGGERED
    if not entryPermission
        permissionBlocked := true
        lastBlockReason := "Entry permission"


    else
        tradeState := STATE_ENTERED
        entryBar := bar_index
        entryPrice := close
        newEntry := true
        lastEvent := "Entry"
        lastBlockReason := "None"


else if tradeState == STATE_ENTERED
    tradeState := STATE_IDLE
    resetEvent := true
    lastEvent := "Reset"


//=============================================================================
// GROUP I — TIMELINE MEASUREMENTS
//=============================================================================


int
 touchToArmBars = not na(touchBar) and not na(armBar) ? armBar - touchBar : na
int
 armToTriggerBars = not na(armBar) and not na(triggerBar) ? triggerBar - armBar : na
int
 triggerToEntryBars = not na(triggerBar) and not na(entryBar) ? entryBar - triggerBar : na
int
 touchToEntryBars = not na(touchBar) and not na(entryBar) ? entryBar - touchBar : na


//=============================================================================
// GROUP J — SAME-BAR TRANSITION CHECKS
//=============================================================================


bool
 touchAndArmSameBar = newArm and not na(touchBar) and bar_index == touchBar
bool
 armAndTriggerSameBar = newTrigger and not na(armBar) and bar_index == armBar
bool
 triggerAndEntrySameBar = newEntry and not na(triggerBar) and bar_index == triggerBar


//=============================================================================
// GROUP K — LABEL WINDOW
//=============================================================================


bool
 insideDebugWindow = not showOnlyRecentBars or bar_index >= last_bar_index - recentBars


//=============================================================================
// GROUP L — EVENT LABELS
//=============================================================================


if showEventLabels and insideDebugWindow
    if newTouch
        label.new(bar_index, low, "TOUCH\nBar: " + str.tostring(bar_index), style = label.style_label_up, textcolor = color.white, color = color.new(color.blue, 0), size = size.tiny)
    if newArm
        label.new(bar_index, low, "ARM\nTouch delay: " + formatInteger(touchToArmBars) + " bars", style = label.style_label_up, textcolor = color.white, color = color.new(color.orange, 0), size = size.tiny)
    if newTrigger
        label.new(bar_index, high, "TRIGGER\nARM delay: " + formatInteger(armToTriggerBars) + " bars", style = label.style_label_down, textcolor = color.white, color = color.new(color.purple, 0), size = size.tiny)
    if newEntry
        label.new(bar_index, high, "ENTRY\nTouch → Entry: " + formatInteger(touchToEntryBars) + " bars", style = label.style_label_down, textcolor = color.white, color = color.new(color.green, 0), size = size.small)


//=============================================================================
// GROUP M — BLOCKED-CONDITION LABELS
//=============================================================================


if showBlockedLabels and insideDebugWindow
    if trendBlocked
        label.new(bar_index, high, "BLOCKED\nTrend", style = label.style_label_down, textcolor = color.white, color = color.new(color.red, 25), size = size.tiny)


    if qualityBlocked
        label.new(bar_index, high, "BLOCKED\nQuality", style = label.style_label_down, textcolor = color.white, color = color.new(color.red, 25), size = size.tiny)


    if extensionBlocked
        label.new(bar_index, high, "BLOCKED\nExtension\n" + str.tostring(extensionDistance, "#.##") + " ATR", style = label.style_label_down, textcolor = color.white, color = color.new(color.red, 25), size = size.tiny)


    if triggerBlocked
        label.new(bar_index, high, "WAITING\nTrigger", style = label.style_label_down, textcolor = color.white, color = color.new(color.gray, 35), size = size.tiny)


    if permissionBlocked
        label.new(bar_index, high, "BLOCKED\nEntry Permission", style = label.style_label_down, textcolor = color.white, color = color.new(color.red, 25), size = size.tiny)


    if touchExpired
        label.new(bar_index, high, "RESET\nTouch Expired", style = label.style_label_down, textcolor = color.white, color = color.new(color.black, 0), size = size.tiny)


    if armExpired
        label.new(bar_index, high, "RESET\nARM Expired", style = label.style_label_down, textcolor = color.white, color = color.new(color.black, 0), size = size.tiny)


//=============================================================================
// GROUP N — STATE BACKGROUND
//=============================================================================


color
 stateBackground =
     tradeState == STATE_IDLE ?
     na :
     tradeState == STATE_TOUCHED ?color.new(color.blue, 90) :
     tradeState == STATE_ARMED ?color.new(color.orange, 88) :
     tradeState == STATE_TRIGGERED ?color.new(color.purple, 88) :
     tradeState == STATE_ENTERED ?color.new(color.green, 85) :
     na


bgcolor(showStateBackground ? stateBackground : na)


//=============================================================================
// GROUP O — VISUAL PLOTS
//=============================================================================


plot(fastEMA, "Fast EMA", color=color.orange)
plot(slowEMA, "Slow EMA", color=color.blue)
plot(priorHigh, "Trigger Reference", color=color.new(color.purple, 25), style=plot.style_linebr)


plotshape(newTouch, "Touch Event", shape.circle, location.belowbar, color=color.blue, size=size.tiny, text="T", textcolor=color.white)
plotshape(newArm, "ARM Event", shape.square, location.belowbar, color=color.orange, size=size.tiny, text="A", textcolor=color.white)
plotshape(newTrigger, "Trigger Event", shape.diamond, location.abovebar, color=color.purple, size=size.tiny, text="TR", textcolor=color.white)
plotshape(newEntry, "Entry Event", shape.triangleup, location.belowbar, color=color.green, size=size.small, text="E", textcolor=color.white)


//=============================================================================
// GROUP P — DATA WINDOW VALUES
//=============================================================================
// These values can be inspected one historical bar at a time through the
// TradingView Data Window.
//=============================================================================


plot(tradeState, "Debug State Number", display=display.data_window)


plot(touchCondition ? 1 : 0, "Touch Condition", display=display.data_window)
plot(trendFilter ? 1 : 0, "Trend Filter", display=display.data_window)
plot(qualityFilter ? 1 : 0, "Quality Filter", display=display.data_window)
plot(extensionFilter ? 1 : 0, "Extension Filter", display=display.data_window)
plot(triggerCondition ? 1 : 0, "Trigger Condition", display=display.data_window)
plot(entryPermission ? 1 : 0, "Entry Permission", display=display.data_window)


plot(extensionDistance, "Extension Distance ATR", display=display.data_window)


plot(barsSinceTouch, "Bars Since Touch", display=display.data_window)
plot(barsSinceArm, "Bars Since ARM", display=display.data_window)
plot(barsSinceTrigger, "Bars Since Trigger", display=display.data_window)


plot(touchAndArmSameBar ? 1 : 0, "Touch and ARM Same Bar", display=display.data_window)
plot(armAndTriggerSameBar ? 1 : 0, "ARM and Trigger Same Bar", display=display.data_window)
plot(triggerAndEntrySameBar ? 1 : 0, "Trigger and Entry Same Bar", display=display.data_window)


plot(barstate.isconfirmed ? 1 : 0, "Bar Confirmed", display=display.data_window)
plot(barstate.isrealtime ? 1 : 0, "Realtime Bar", display=display.data_window)


//=============================================================================
// GROUP Q — DEBUG TABLE
//=============================================================================
 
var 
table
 debugTable = table.new(position.bottom_left, 2, 17, border_width=1)


string
 stateText = stateToText(tradeState)


if barstate.islast
    if showDebugTable
        table.cell(debugTable, 0, 0, "Debug Item", text_color=color.white, bgcolor=color.new(color.gray, 20))
        table.cell(debugTable, 1, 0, "Current Value", text_color=color.white, bgcolor=color.new(color.gray, 20))


        table.cell(debugTable, 0, 1, "State")
        table.cell(debugTable, 1, 1, stateText)


        table.cell(debugTable, 0, 2, "Last Event")
        table.cell(debugTable, 1, 2, lastEvent)


        table.cell(debugTable, 0, 3, "Last Block")
        table.cell(debugTable, 1, 3, lastBlockReason)


        table.cell(debugTable, 0, 4, "Touch")
        table.cell(debugTable, 1, 4, yesNo(touchCondition))


        table.cell(debugTable, 0, 5, "Trend")
        table.cell(debugTable, 1, 5, yesNo(trendFilter))


        table.cell(debugTable, 0, 6, "Quality")
        table.cell(debugTable, 1, 6, yesNo(qualityFilter))


        table.cell(debugTable, 0, 7, "Extension")
        table.cell(debugTable, 1, 7, yesNo(extensionFilter))


        table.cell(debugTable, 0, 8, "Trigger")
        table.cell(debugTable, 1, 8, yesNo(triggerCondition))


        table.cell(debugTable, 0, 9, "Entry Permission")
        table.cell(debugTable, 1, 9, yesNo(entryPermission))


        table.cell(debugTable, 0, 10, "Bars Since Touch")
        table.cell(debugTable, 1, 10, formatInteger(barsSinceTouch))


        table.cell(debugTable, 0, 11, "Bars Since ARM")
        table.cell(debugTable, 1, 11, formatInteger(barsSinceArm))


        table.cell(debugTable, 0, 12, "Bars Since Trigger")
        table.cell(debugTable, 1, 12, formatInteger(barsSinceTrigger))


        table.cell(debugTable, 0, 13, "Extension ATR")
        table.cell(debugTable, 1, 13, str.tostring(extensionDistance, "#.###"))


        table.cell(debugTable, 0, 14, "Confirmed Bar")
        table.cell(debugTable, 1, 14, barstate.isconfirmed ? "YES" : "NO")


        table.cell(debugTable, 0, 15, "Realtime")
        table.cell(debugTable, 1, 15, barstate.isrealtime ? "YES" : "NO")


        table.cell(debugTable, 0, 16, "Bar Index")
        table.cell(debugTable, 1, 16, str.tostring(bar_index))


    else
        table.clear(debugTable, 0, 0, 1, 16)


//=============================================================================
// GROUP R — ALERT DEBUGGING
//=============================================================================


alertcondition(newTouch, "Debug Touch", "State-machine debug event: Touch")
alertcondition(newArm, "Debug ARM", "State-machine debug event: ARM")
alertcondition(newTrigger, "Debug Trigger", "State-machine debug event: Trigger")
alertcondition(newEntry, "Debug Entry", "State-machine debug event: Entry")
reddit.com
u/LouZEverything — 1 month ago

Wiring advice over the years

When I was a teenager, I worked with my uncle wiring houses. Back then we were installing 100 amp boxes, running wire, setting outlets, and doing what at the time was considered a solid residential setup.(Think this was around the 80's)

Years later, when my wife and I were building our home, I called him for advice because I knew things had changed. I remember him telling me that kitchens had become huge power users compared to the old days. He said almost everything in a kitchen needed its own breaker and that you really didn’t want more than two outlets sharing a circuit in there anymore.(to keep from having breakers trip on holidays from hot pots being pluged in and such)

One thing he told me that always stuck with me was to dedicate at least one outlet in each bedroom to its own circuit. He said as people get older, you never know when you or your wife might need some kind of medical equipment, and the last thing you’d want is a breaker tripping because too many things were running on the same line.

He also told me that if a house was wired correctly, you’d end up using nearly every space in a 40-space 200 amp panel. That conversation was over 15 or 20 years ago, and it got me wondering how much has residential wiring changed since then? My uncle has passed away so I would like to ask your opinions on if a home was built now would those standards still be true?(I don't know that it helps in anyway but we built aroun 2020 so still a landline phone but it never got use they were being phased out by cell and such)

I am not trying to get advice more just want to sort of ask about the changes over time?

reddit.com
u/LouZEverything — 3 months ago