PINE LIBRARY

ScaleValidator

84
🛡️ ScaleValidator Library - Input Validation for PineScript

📢 ABOUT

ScaleValidator is a lightweight utility library that provides robust input validation for PineScript. It ensures your scripts receive valid arguments and throws helpful runtime errors when they don't.

FEATURES

🛡️ Validation Methods
Validate inputs and throw descriptive runtime errors if invalid:
• isValidLocation() — Validate location strings
• isValidPosition() — Validate position strings
• isValidFormat() — Validate format strings
• isValidPOV() — Validate point-of-view (extend) strings

🔍 Helper Methods
Quick boolean checks without throwing errors:
• isLocationAbove() / isLocationBelow() — Check vertical location
• isPositionAbove() / isPositionCenter() / isPositionBelow() — Check position row
• isPositionLeft() / isPositionRight() — Check position column

💡 USAGE EXAMPLE

Pine Script®
//@version=6 indicator("Validator Demo", overlay = true) import cryptolinx/ScaleValidator/1 as v // Validate inputs before using them userPosition = input.string(position.top_center, "Position") if v.isValidPosition(userPosition) // Safe to use the position label.new(bar_index, high, "Valid!", xloc = xloc.bar_index, style = label.style_label_down, textcolor = color.white) // Quick checks without throwing errors if v.isPositionAbove(userPosition) // Position is in top row plotchar(close, char = "▲", location = location.abovebar)


📊 VALID CONSTANTS REFERENCE

Locations
• location.top — Top of pane
• location.bottom — Bottom of pane
• location.abovebar — Above price bar
• location.belowbar — Below price bar
• location.absolute — Absolute position

Positions (3x3 Grid)
• Top Row: top_left, top_center, top_right
• Middle Row: middle_left, middle_center, middle_right
• Bottom Row: bottom_left, bottom_center, bottom_right

Formats
• format.inherit — Inherit from parent
• format.percent — Percentage format

Point of View (Extend)
• extend.both — Extend in both directions
• extend.left — Extend to the left
• extend.right — Extend to the right

🔧 METHOD REFERENCE

Validators (throw runtime error if invalid)
• isValidLocation(string) → bool
• isValidPosition(string) → bool
• isValidFormat(string) → bool
• isValidPOV(string) → bool

Helpers (return bool, no errors)
• isLocationAbove(string) → bool
• isLocationBelow(string) → bool
• isPositionAbove(string) → bool
• isPositionCenter(string) → bool
• isPositionBelow(string) → bool
• isPositionLeft(string) → bool
• isPositionRight(string) → bool

🚀 WHY USE THIS?

• 🛡️ Defensive Programming — Catch invalid inputs early
• 📖 Helpful Errors — Descriptive messages show valid options
• ⚡ Lightweight — No dependencies, minimal overhead
• 🔗 Companion to ScalesDEV — Used internally by the Scale library

📋 CHANGELOG

✅ Added method badges (helper/validator)
✅ Created reference tables for valid constants
✅ Improved parameter descriptions
✅ Formatted return types

🙏 RELATED LIBRARIES

Check out Scales for building beautiful scale visualizations that use this validator!


Battries included! 🔋Happy coding! 🚀 cryptolinx for the TradingView community

Exención de responsabilidad

La información y las publicaciones no constituyen, ni deben considerarse como asesoramiento o recomendaciones financieras, de inversión, de trading o de otro tipo proporcionadas o respaldadas por TradingView. Más información en Condiciones de uso.