peacefulLizard50262

Daily Reset CWEMA/CWTEMA

This Pine Script code defines an indicator called "Daily Reset CWEMA" that plots a custom weighted moving average on a chart. The indicator takes three inputs: a source series (usually the close price of a security), a length parameter that specifies the number of periods over which the moving average is calculated, and a style parameter that specifies the type of moving average to use (either a custom weighted exponential moving average (CWEMA) or a custom weighted triple exponential moving average (CWTEMA)).

The code first checks the current time frame and adjusts the length parameter accordingly. If the time frame is daily, weekly, or monthly, the length parameter is used as-is. Otherwise, the length is set to the number of bars since the last day change, unless this value is less than the length parameter, in which case the length is set to the number of bars since the last day change.

The ema(), tema(), wma(), cwema(), and cwtema() functions are then defined. The ema() function calculates the exponential moving average of the source data using the number of bars since the last day change as the length. The tema() function calculates the triple exponential moving average of the source data using the number of bars since the last day change as the length. The wma() function calculates the weighted moving average of the source data using the given weights and the number of bars since the last day change as the length. The cwema() and cwtema() functions are similar to the wma() function, but use the ema() and tema() functions to calculate the moving average values instead of the source data directly.

Finally, the ma() function is defined, which takes the source data, length, and style as inputs and calls the appropriate moving average function based on the style parameter. The result of this function is then plotted on the chart.

Suggested by: @ASIFKERIM

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?