Skip to content

Find out if a Pine Script string is uppercase text

Find out if a Pine Script string is uppercase text

Section titled “Find out if a Pine Script string is uppercase text”

TL;DR
Build a StrIsUpper() helper so you can detect uppercase strings, highlight chart states, and trigger alerts when text changes.

DifficultyBeginner
Time to implement5-10 min
CategoryStrings
//@version=5
indicator("Uppercase check", overlay=false)
StrIsUpper(string source) =>
sourceUpper = str.upper(source)
sourceUpper != str.lower(source) and source == sourceUpper
text = input.string("NASDAQ", "Text to inspect")
isUpper = StrIsUpper(text)
plotchar(isUpper, "Uppercase?", "✅", location=location.top)

Pine Script does not ship with a built-in uppercase detector. Comparing raw strings fails because "ABC" and "abc" are different even if you just want to know if the letters are capitalised. A helper that converts the input to both upper and lower case lets you answer questions like “Is the symbol description all caps?” or “Has my screener output changed format?”—useful for UI cues and alert conditions.

  • Build a reusable StrIsUpper() utility
  • Test instrument metadata (ticker, description) for uppercase text
  • React to uppercase detection with backgrounds, labels, or alerts
  • Handle edge cases for numbers, symbols, and empty strings
CallPurpose
str.upper(string)Returns an uppercase version of the string.
str.lower(string)Returns a lowercase version of the string.
StrIsUpper(string)Custom helper that checks if a string is uppercase text.
bgcolor(color)Highlights the chart when uppercase text is detected.
label.new(...)Displays the uppercase status directly on the chart.
  1. Write the helper function
    Convert the input to upper and lower case. Uppercase strings must differ from their lowercase version and match their uppercase version.

    StrIsUpper(string source) =>
    uppercase = str.upper(source)
    uppercase != str.lower(source) and source == uppercase
  2. Test the strings you care about
    Apply the helper to literal strings, inputs, or instrument metadata.

    symbolUpper = StrIsUpper(syminfo.ticker)
    descUpper = StrIsUpper(syminfo.description)
  3. React to the result
    Colour the background, raise alerts, or annotate the chart when uppercase text appears.

    bgcolor(symbolUpper ? color.new(color.green, 80) : na)
    if barstate.islast
    label.new(bar_index, high, "Description uppercase? " + str.tostring(descUpper))
//@version=5
indicator("Uppercase watcher", overlay=true)
// 1. Helper function
StrIsUpper(string source) =>
transformed = str.upper(source)
transformed != str.lower(source) and source == transformed
// 2. Evaluate instrument metadata
descIsUpper = StrIsUpper(syminfo.description)
symbolIsUpper = StrIsUpper(syminfo.ticker)
// 3. React to uppercase descriptions
bgcolor(descIsUpper ? color.new(color.teal, 78) : na)
if barstate.islastconfirmedhistory
txt = "Ticker uppercase: " + str.tostring(symbolIsUpper) +
"\nDescription uppercase: " + str.tostring(descIsUpper)
label.new(bar_index, high, txt, style=label.style_label_up, textcolor=color.white, bgcolor=color.new(color.blue, 65))
alertcondition(descIsUpper, "Description uppercase", "Instrument description switched to uppercase.")
Why this works.
  • Numbers or symbols alone return `false` because uppercase/lowercase versions match.
  • Strings with at least one letter that is not capitalised return `false` due to the equality check.
  • The helper function is pure and reusable—drop it into any script that needs uppercase detection.
  • Strip whitespace before testing if trailing spaces are possible (str.trim()).
  • Combine with str.replace() to filter out characters you want to ignore before checking.
  • Cache the helper in a separate include file if multiple scripts use it.
  • Remember that StrIsUpper("") returns false because there are no letters to validate.

The function returns true for strings like “12345”

Section titled “The function returns true for strings like “12345””

Use the double comparison (upper != lower) to ensure at least one alphabetical character exists. Without this clause numeric strings would incorrectly return true.

Can I reuse the helper for lowercase detection?

Section titled “Can I reuse the helper for lowercase detection?”

Yes—swap the comparisons so you test lower case against upper case or write a complementary StrIsLower() using the same pattern.

  • Pine Script lacks a built-in uppercase tester, so a lightweight helper fills the gap.
  • Comparing upper and lower transformations ensures the string has letters and they are capitalised.
  • Use the detection to power UI cues, alerts, or data validation workflows.
  • Handle edge cases (empty strings, numbers) to keep results predictable.

Adapted from tradingcode.net, optimised for Algo Trade Analytics users.