Use an AI assistant to write WealthScript


Have an AI assistant write your WealthScript indicator


WealthScript is the formula language of WealthCharts, so an assistant that has never met it will guess at names - and guess wrong. Give it the reference first and it stops guessing. The reference is generated from the compiler itself, so it always matches what the compiler accepts: every function, every value and every error code, with an example for each, and the few things the language refuses on purpose.


Your assistant needs to be able to open a web page. Give it this address and ask it to read the whole page before it writes anything:


https://app.wealthcharts.com/chart/wealthscript-llm.md

Then send it the instructions below. They are short on purpose: they name the handful of rules the language will not bend on, and they tell the assistant to admit a gap instead of inventing a word.


You are helping me write a script for WealthCharts'
WealthScript language. Read this reference first and use
nothing else:
https://app.wealthcharts.com/chart/wealthscript-llm.md
It is generated from the compiler and lists every word
the language has.

Follow these rules:
- Write WealthScript only. Do not borrow syntax or names
  from another scripting language.
- Use only functions, values and header attributes that
  appear in the reference. If what I ask for is not in
  there, say so instead of inventing a name.
- A script runs once per bar, oldest bar first. There are
  no loops and no arrays: keep a value across bars with
  var, and read an earlier bar with name[1].
- Anything that is not on the price scale needs
  [PlotSubchart(n, 1)] in the header, or it will squash
  the candles.
- Every script has to draw something with plotN or place
  an order.
- Read the reference itself, not a summary of it. If your
  tools hand you a shortened version instead of the file,
  say so before you write anything.
- Give me the finished script in one block, with the
  inputs at the top, and one line on what each line
  does.

Now ask for what you want, in plain English. For this tutorial we asked for exactly this:


Plot a fast and a slow moving average on the price
chart, colour the bar when the fast average is above the
slow one, and raise an alert on the bar where the two
averages cross.

This is what came back, and it is what we compiled and applied - unedited:


[Name = "Fast/Slow MA Cross"]
input FastLen(10);
input SlowLen(30);
let fastMA = Average(close, FastLen);
let slowMA = Average(close, SlowLen);
plot1(fastMA, "fast MA");
plot2(slowMA, "slow MA");
if fastMA > slowMA then
  ColorBar(Green);
end;
if (CrossOver(fastMA, slowMA) or CrossUnder(fastMA, slowMA)) and CheckAlert() then
  Alert("Fast/slow MA cross");
end;

Go to the Main Menu on WealthCharts, find WealthScript and load it onto your layout. Paste the script in, save it, then Compile it. Once it compiles, apply it to a chart.


You should see two averages drawn on price, named fast MA and slow MA in the legend; the bars painted while the fast average sits above the slow one, and back to their own colour when it is not; and an alert on the bar where the two cross. The two numbers at the top of the script are inputs: open the indicator's settings and change them without touching the code.


When the compiler refuses


An assistant will sometimes reach for a word the language does not have. The compiler catches it, and the message carries a number. 61 means the word is not part of WealthScript and nothing with that name has been declared. 176 and 177 mean the wrong number of arguments for a function. -1 means the language refuses the shape by design - which is what a loop or an array gets, because a script runs once per bar and the platform already keeps the history for you.


Click View details next to the message to open the explanation for that number. Then copy the message itself, number and all, back into the chat and ask for a fix. One round is usually enough: the reference the assistant is holding explains every code the compiler can raise.


Every word, every value and every error code lives on one page: the WealthScript reference.


What the assistant cannot do for you


It cannot see your chart, your symbols or your timeframe, so it cannot tell you whether the numbers it produced are the right ones - only the chart can. It does not know which indicators your account holds, so a script that imports one you do not have will not compile, and the compiler will say so. And it will sound just as certain when it is wrong as when it is right. Compile it, apply it and look at the chart before you rely on it.



Related Articles