Starfield Scroller█ OVERVIEW
This script creates a visually appealing starfield effect on your chart. It generates and animates multiple star fields, each customizable with its own parameters. Explore the input options to adjust the number of stars, their speed, and color.
█ CONCEPTS
The script is a simple demonstration, and utilizes a custom `starfield` function and my `geo` library for point management. It simulates a parallax effect by creating stars at random positions and moving them across the chart at varying speeds.
Star Creation
• Stars are generated with random X and Y coordinates within defined boundaries.
• Each star is assigned a random speed factor, influencing its movement speed.
• Star color is also influenced by its speed; faster stars appear more transparent.
Star Movement & Management
• The script maintains a dynamic array of Star structures. Each Star structure holds the star's creation bar index, location (as a Point ), speed factor, and the label used to display it.
• On each new bar, new stars are created and added to the array.
• Stars are moved horizontally based on their speed factor.
• Stars that move off-screen are deleted to manage resource usage.
• The maximum number of stars for each starfield instance is controlled by an input parameter.
Parallax Effect
• The varying speeds of the stars create a parallax effect, giving the illusion of depth to the starfield.
█ FEATURES
This script includes two independent starfield instances, each configurable via inputs.
Starfield 1:
• Max Stars 1: Maximum number of stars in the first starfield.
• New Stars Per Bar 1: Number of new stars created per bar for the first starfield.
• Max Star Speed 1: Maximum speed of the stars in the first starfield.
• Star Color 1: Color of the stars in the first starfield.
Starfield 2:
• Max Stars 2: Maximum number of stars in the second starfield.
• New Stars Per Bar 2: Number of new stars created per bar for the second starfield.
• Max Star Speed 2: Maximum speed of the stars in the second starfield.
• Star Color 2: Color of the stars in the second starfield.
█ HOW TO USE
1 — Add the script to your chart.
2 — Adjust the input parameters for each starfield to customize its appearance and behavior.
3 — Observe the animated starfield effect.
█ LIMITATIONS
• Excessive numbers of stars may impact performance. Adjust the maximum number of stars and new stars per bar accordingly.
• The script uses labels for rendering stars, which can have limitations on certain chart timeframes and settings.
█ NOTES
This script is intended for visual enhancement and does not provide trading signals. It demonstrates the use of custom types, arrays, and functions for creating complex visual effects in Pine Script™. The `geo` library is used for consistent point calculations.
█ THANKS
Thanks to the TradingView community for inspiration and support.