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

Skrip sumber terbuka

Dalam semangat TradingView yang sebenar, penulis skrip ini telah menerbitkannya dengan menggunakan sumber terbuka supaya pedagang-pedagang dapat memahami dan mengesahkannya. Sorakan kepada penulis! Anda dapat menggunakannya secara percuma tetapi penggunaan semula kod ini dalam penerbitan adalah dikawalselia oleh Peraturan Dalaman. Anda boleh menyukainya untuk menggunakannya pada carta.

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.

Ingin menggunakan skrip ini pada carta?