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. קרא עוד בתנאים וההגבלות.

רוצה להשתמש בסקריפ זה בגרף?