We've been working hard to make LitScript faster, better and stronger.
In order to achieve that, we had to break down everything and to rebuild it again from scratch. This isn't the first time we've done it, few months back LitScript was rewritten in order to provide better error handling which to be honest was horrendous back then.
Hopefully this will be end up as our 1st stable version of LitScript.
Like mentioned previously, this is the stepping stone for server-side scripts and alerts.
New script, new rules
We'll use this code to illustrate the changes:
study("My Script") fast = 12, slow = input("Slow", 26) fastMA = ema(close, fast) slowMA = ema(close, slow) macd = fastMA - slowMA signal = sma(macd, 9) plot(macd, color=blue) plotshape(signal, "up", 10, color=#ff0)
//@version=1 study("My Script") const fast = 12, slow = input("Slow", 26) var fastMA = ema(close, fast) var slowMA = ema(close, slow) seq macd = fastMA - slowMA var signal = sma(macd, 9) plot(macd, color=color.blue) plotshape(signal, shape.up, 10, color=#ff0)
That's it !
So now you have to define type of variable, you can't just start writing the name or compiler will complain.
This change was fundamental for many reasons.
var *— By default just write
varin front of every defined variable
seq *— Some functions such as
ema()require series variables, our new compiler will complain if you try to use a non-series variable. In this case you use
seq( short for sequence ) when defining your sequence variable.
const *— Use it for values that don't change afterwards. Useful when you don't want to accidentally overwrite a value.
color.*— Built-in colors are now all part of color object. e.g.
shape.*— Shapes are no longer written in string, they're all part of shape object. e.g.
plots[*] *— Array/Matrix plots are now defined as a type. e.g.
test = becomes
No Memory Usage — We've moved the heavy parts to our server so that your device doesn't have to struggle anymore! We hope this also fixes crashes some of our users were experiencing while writing indicators.
Fast Compilation — Scripts should compile much faster than before.
Smarter Compiler — Our new compiler should throw much clearer errors, it should be smarter than a trained parrot.
Inline Shapes — You can now use expressions to define shapes on one line, e.g.
plotshape(close, close>open? shape.up : shape.down)
Fixed shorthands —
value+=1, now works properly
We're not activating this by default, but once we iron out all the bugs and issues, we will completely kill the previous LitScript.
Since we built this from ground up, there's always a chance we made mistakes. We hope you'll help us finding out all those edge-cases we missed.
Quick migration guide
In order to activate new LitScript, just simply add the following snippet on the first line of your script.
varin front of every initial variable definition
Change it to
seqevery time compiler complains
color.in front of every pre-defined color you used
For plotshape and matrix/array plots, see Important Details section above
- LitScript rewrite is currently being tested
- Added some minor optimizations to new LitScript
- Fixed code editor block comment highlighting
- Fixed code editor indentation issues
- Fixed error highlighting being stuck
- Fixed some typos on the website