ma_colored
Download scriptThis script is designed to provide a versatile and visually intuitive moving average tool for your trading charts. It simplifies market analysis by smoothing out price fluctuations and using color changes to highlight momentum shifts.
Here is a breakdown of how the logic functions:
Core Functionality
The script serves as an all-in-one moving average indicator. Instead of needing multiple separate tools, this single script allows you to choose between four different calculation methods to determine the average price of an asset over a specific period:
- Simple Moving Average (SMA): The standard average where every data point in the period carries equal weight.
- Exponential Moving Average (EMA): A moving average that reacts more quickly to recent price changes by giving greater importance to newer data.
- Smoothed Moving Average (SMMA): A calculation designed to reduce "noise" and provide a very fluid, steady trend line.
- Linear Weighted Moving Average (LWMA): A method that gives progressively more weight to the most recent prices.
Customization Options
Users can tailor the indicator's behavior using three primary settings:
- Period: Defines the look-back window (e.g., looking at the last 9 candles vs. the last 50).
- Method: Lets you toggle between the four calculation types listed above.
- Applied Price: This determines which price point the average is based on—such as the Closing price, Opening price, High/Low range, or a custom calculation like the Median or Typical price.
Visual Intelligence: Dynamic Coloring
One of the standout features of this script is its ability to change color dynamically based on price action. Rather than just being a static line, it monitors the direction of the moving average:
- Upward Momentum: When the current value of the average is higher than the previous one, the indicator will reflect a specific color (traditionally green).
- Downward Momentum: When the current value drops below the previous one, the indicator shifts to another color (traditionally red).
This provides an immediate visual cue for trend direction, helping traders identify whether the market's average momentum is accelerating upward or cooling down.
Technical Efficiency
The internal logic is structured to be "fast and flexible." It handles the heavy lifting of price data processing in the background, ensuring that the charts remain responsive while providing a clean, professional display that adapts to whichever timeframe or asset you choose to trade.
ÿþ/ * *
* C l a s s i c M o v i n g A v e r a g e s w i t h c o l o r s
*
* S i m p l e m o v i n g a v e r a g e
* E x p o n e n t i a l m o v i n g a v e r a g e
* S m o o t h e d m o v i n g a v e r a g e
* L i n e a r w e i g h t e d m o v i n g a v e r a g e
* S m o o t h e d m o v i n g a v e r a g e
*
* T h e i n d i c a t o r d i s p l a y s a c o l o r e d m o v i n g a v e r a g e .
*
* I t h a s t h r e e p a r a m e t e r s :
* * P e r i o d c a l c u l a t i o n p e r i o d
* * M e t h o d c a l c u l a t i o n m e t h o d
* * P r i c e a p p l i e d p r i s e u s e d f o r c a l c u l a t i o n
*
* T h i s v e r s i o n i s f a s t e r a n d c o d e i s m o r e f l e x i b l e a n d r e u s a b l e
* /
/ / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# p r o p e r t y c o p y r i g h t "