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

開源腳本

本著真正的TradingView精神,該腳本的作者將其開源發布,以便交易者可以理解和驗證它。為作者喝彩吧!您可以免費使用它,但在出版物中重複使用此代碼受網站規則的約束。 您可以收藏它以在圖表上使用。

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。

想在圖表上使用此腳本?