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 aStrIsUpper()helper so you can detect uppercase strings, highlight chart states, and trigger alerts when text changes.
At a Glance
Section titled “At a Glance”| Difficulty | Beginner |
| Time to implement | 5-10 min |
| Category | Strings |
Quick Actions
Section titled “Quick Actions”Quick Start
Section titled “Quick Start”//@version=5indicator("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)Why It Matters
Section titled “Why It Matters”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.
What You’ll Learn
Section titled “What You’ll Learn”- 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
Quick Reference
Section titled “Quick Reference”| Call | Purpose |
|---|---|
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. |
Implementation Blueprint
Section titled “Implementation Blueprint”-
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 -
Test the strings you care about
Apply the helper to literal strings, inputs, or instrument metadata.symbolUpper = StrIsUpper(syminfo.ticker)descUpper = StrIsUpper(syminfo.description) -
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.islastlabel.new(bar_index, high, "Description uppercase? " + str.tostring(descUpper))
Example Playbook
Section titled “Example Playbook”//@version=5indicator("Uppercase watcher", overlay=true)
// 1. Helper functionStrIsUpper(string source) => transformed = str.upper(source) transformed != str.lower(source) and source == transformed
// 2. Evaluate instrument metadatadescIsUpper = StrIsUpper(syminfo.description)symbolIsUpper = StrIsUpper(syminfo.ticker)
// 3. React to uppercase descriptionsbgcolor(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.")- 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.
Pro Tips & Pitfalls
Section titled “Pro Tips & Pitfalls”- 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("")returnsfalsebecause there are no letters to validate.
Troubleshooting & FAQ
Section titled “Troubleshooting & FAQ”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.
Key Takeaways
Section titled “Key Takeaways”- 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.
Keep Going
Section titled “Keep Going”- Open AI Editor to apply the pattern with guided assistance
- Browse PineScript Examples for ready-to-run templates
- Connect to Live Trading when you are ready to automate
Adapted from tradingcode.net, optimised for Algo Trade Analytics users.