As you can see it made some mistakes. It made up the function that doesn't exist (AddHorizontalLine) and it mistyped StDev as StdDev. It also does not understand that AFL is case insensitive and that therefore he can't use rsi
(lowercase) as variable name because the name is reserved for RSI
function. But other than that the formulas were good.
It is also able to "explain" the formulas, for example when I fed it with Relative Performance formula saying:
Explain the code:
NumBars = 20;
fvb = Status("firstvisiblebar");
Plot( 100 * ( C - C[ fvb ] ) / C[ fvb ], Name(), colorBlue );
for( i = 0; ( symbol = StrExtract( TickerList, i ) ) != ""; i++ )
{
fc = Foreign( symbol, "C" );
if( ! IsNull( fc[ 0 ] ) )
{
Plot( 100 * ( fc - fc[ fvb ] )/ fc[ fvb ], symbol, colorLightOrange + ( (2*i) % 15 ), styleLine );
}
}
PlotGrid( 0, colorYellow );
_N( Title = "{{NAME}} - Relative Performance [%]: {{VALUES}}" );
ChatGPT responded with:
Sure! Here is an explanation of the code you provided:
_N( TickerList = ParamStr("Tickers", "^DJI,MSFT,GE") );
This line of code initializes the TickerList
variable with a string containing a list of ticker symbols separated by commas. The ParamStr()
function is used to retrieve the value of the "Tickers" parameter from the formula's input. If the "Tickers" parameter is not specified, the default value "^DJI,MSFT,GE" is used. The _N()
function is used to suppress any error messages that may be generated by the formula.
NumBars = 20;
This line of code sets the value of the NumBars
variable to 20.
fvb = Status("firstvisiblebar");
This line of code retrieves the index of the first visible bar on the chart and assigns it to the fvb
variable. The Status()
function is used to retrieve the value of the "firstvisiblebar" status variable, which contains the index of the first visible bar on the chart.
Plot( 100 * ( C - C[ fvb ] ) / C[ fvb ], Name(), colorBlue );
This line of code plots the relative performance of the current symbol as a percentage on the chart. The Plot()
function is used to draw a line on the chart, and it takes three arguments:
- The data to be plotted (in this case, the relative performance calculated using the current close price and the close price of the first visible bar)
- The label for the line (in this case, the name of the current symbol)
- The color of the line
for( i = 0; ( symbol = StrExtract( TickerList, i ) ) != ""; i++ )
{
fc = Foreign( symbol, "C" );
if( ! IsNull( fc[ 0 ] ) )
{
Plot( 100 * ( fc - fc[ fvb ] )/ fc[ fvb ], symbol, colorLightOrange + ( (2*i) % 15 ), styleLine );
}
}
This loop iterates over the list of ticker symbols in the TickerList
variable. The StrExtract()
function is used to extract each symbol from the list, and the Foreign()
function is used to retrieve the close prices for the symbol. If the close prices are not null, the relative performance of the symbol is plotted on the chart using the Plot()
function. The colorLightOrange + ( (2*i) % 15 )
expression is used to assign a different color to each line plotted on the chart.
PlotGrid( 0, colorYellow );
This line of code plots a horizontal gridline at the price 0 on the chart, using the color yellow.
_N( Title = "{{NAME}} - Relative Performance [%]: {{VALUES}}" );
This line of code sets the title for the chart using the Title
formula parameter. The {{NAME}}
and {{VALUES}}
placeholder variables are replaced with the name of the current symbol and the values of the plotted data, respectively. The _N()
function is used to suppress
Me: It is quite scary to realize that this explanation was generated by computer and how precise it is.