Attachments forums

List of attachments posted on this forum.


All files on forums: 135981

Re: Beatle's Trend Trading System

dmnik, Sat Dec 23, 2023 10:22 pm

Maybe someone can convert this script to MT4!

This script represents a Volume Weighted Average Price (VWAP) indicator with the option to display standard deviations from the VWAP line as bands. Let's go through the logic of the script step by step:

Declaration and parameter setup:

The Pine Script version is set to //@version=5.
The indicator is configured with the title VWAP and a short title VWAP, which is overlaid on the chart (overlay=true).
An input parameter hideonDWM is introduced to hide the VWAP on timeframes of 1D and above.
A variable anchor is introduced to determine the period for calculating VWAP (e.g., session, week, month, etc.).
An input parameter src is introduced to select the data source for calculating VWAP (default is HLC3 - the average of High, Low, and Close).
An input parameter offset is defined to offset the VWAP plot on the Y-axis.
Parameters are set for displaying standard deviation bands (showBand_X, stdevMult_X).
Volume check:

It checks if the script is on the last bar (barstate.islast) and if the cumulative volume is not equal to zero (ta.cum(volume) == 0). In the absence of volume, an error is generated.
Fetching event data (earnings, dividends, splits):

Functions request.earnings, request.dividends, and request.splits are used to obtain data about the corresponding events for the ticker.
Variables new_earnings, new_dividends, and new_split are created to track new data.
Determining a new period:

A switch statement is used based on the selected anchor to determine whether a new period has started (e.g., session, week, month, etc.).
If the period is set to "Earnings," "Dividends," or "Splits," a new period is considered to have started if the relevant data is available.
If the period is set to "Session," "Week," "Month," etc., it checks for a change in the time frame.
Calculation of VWAP and standard deviations:

The variable _vwap is assigned the VWAP value using the ta.vwap function.
The absolute value of the standard deviation (stdevAbs) is calculated based on the upper standard deviation band.
Displaying VWAP and standard deviations:

If hiding for timeframes of 1D and above is not set, the script displays VWAP and standard deviations.
The VWAP plot (plot) is displayed in orange.
Plots (plot) for each of the four standard deviation bands are displayed in different colors.
Areas between the upper and lower bands are filled to visualize standard deviations.
In summary, the script creates on the chart a Volume Weighted Average Price (VWAP) line and standard deviation bands, while also displaying events such as earnings reports, dividends, and stock splits.
All files in topic