Skip to content

Xopry/TradingLite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

TradingLite - LitScript Documentation

The idea of LitScript is to be as close to PineScript as possible, we intend to make the experience of switching from one to another as effortless as possible.

This documentation will serve you to some extent.

Table Of Contents


PineScript Quickstart Script That Works With LitScript

study("My Script")
fast = 12, slow = 26
fastMA = ema(close, fast)
slowMA = ema(close, slow)
macd = fastMA - slowMA
signal = sma(macd, 9)
plot(macd, color=#00f)
plot(signal, color=#ff0)

Function Declaration Examples

Explicit variable type definition for functions

func MyFunc(mySeriesVar:series, myConstantVar:var) => mySeriesVar * myConstantVar`

single line functions

study("My Script")
func zigzag(val:series) => val[2] == 0 ? 50 : 0
test = zigzag(test)
plot(test, color=#0ff)

multi-line functions

study("My Script")
func mipmap(val:series){
    temp = val[1]
    if (temp == -10)
        temp = -20
    else
        temp = -10
    return temp
}
hiya = mipmap(hiya)
plot(hiya, color=#ff0)

Arrays Support, Loops, Overlay - Example

overlay

study("array overlaid example", overlay=true)
levelsA = [32] // array allows us to generate 32 charts easily
levelsB = [10]

// simple for loop
for (i=0;i<32;i++) {
  append(levelsA, sma(open,i*2)+i*20, lighten(#509,i*5))  // append is how we fill the data for arrays plots
}

for (i=0;i<100;i+=10) { // step by 10
  append(levelsB, sma(open,i*2)-i*20, darken(#B09,i*2))
}

plot(levelsA)
plot(levelsB)

non-series

Arrays ( non-series ), darken, lighten

crazy visualizations

Array plots can also have various colors for some crazy visualizations like these.

Supported Functionality

study()

The function sets a number of study properties.

study("my script name", overlay = true) // name of the script + overlay it on the last existing pane ( true ) or new pane ( false / default behavior )

input()

input("Field Name", 0) . This allows public scripts to be used without touching the code. Only limited to numbers, booleans for now input("Color", green) ( can't be modified for now ) input("Source", open) ( can't be modified for now )

myValue = input("My Label", 123)

series

series = open + 10 // any defined value can become a series variable, you can access it by doing series[1]

multiple definitions per single line

seriesA = open, seriesB=close // multiple definitions can be stacked on one line using a comma

var

Special var keyword used for assigning and one-time initializing of the variable (not the same as defining values directly).

example define variables that stay in memory ( just like in PineScript)

var myValue = 5 // (taken from pinescript) this allows the value of the variable to be automatically saved between bars

Plot Built-In Functions

plot()

Plots a series of data on the chart in the form of a line. Plots with no color set will default to white ( e.g. plot(open) )

plot(series, color=#FFF) // plot a linechart

plotbar()

Plots ohlc bars on the chart.

plotbar(open,high,low,close) // plot candles

histogram()

Plots a series of data on the chart in the form of a histogram.

histogram(price, color=#af5, trasp=50)

plotshape()

Plots visual shapes on the chart. List of all available shapes here.

plotshape(price, "icon", size, color=#af5)

plotshape(value, "icon", size, color) (experimental)

fill()

fill(price1, price2, color=#af5, trasp=50)

bgcolor()

bgcolor(#af5, trasp=50)

stepped linechart

linewidth setting

linewidth support for plots!

study("MyScript")
mycolor = blend(#f00,#0f0,(open-open[1])/50)
plot(open, lineType=1, linewidth=10, color=mycolor)

offset

offset parameter to plot, fill

transp

transp ( transparency ) parameter for histogram, fill, bgcolor

Arrays & Conditional Statements

arrays

array/matrix plots max limit - 64 plots

array = [size] // size is a positive value, represents the amount of charts to create
append(array, value, #FF00FF) // fill the first chart's array data

if else statements

if (condition1) {
} else if (condition2) {
} else { }
// optional scopes for single line statements
if (test==2) test=1
else test=2

shorthand conditional expressions

test = (condition) ? true : false // (ternary conditional operator)
test = iff(condition,true,false) // if ... then ... else ... // less efficient than ?:

Rest Of The Syntax

It is pretty close to JavaScript, with some minor differences and restrictions

Loops are limited to 1000 iterations for your own safety.

for()

for(i=0;i<10;i++) { /* code */ }  // no need to specify type of iterator ( i )
for(j=1;j>0;j-=0.05) { /* code */ }  // reverse loop with fractions

while()

while(condition) { /* code */ } // this is self explanatory

switch()

switch(somevariable){ // switch statements !
case 0:
     /* code */
    break
case 1:
case 2:
     /* code */
    break
default:
     /* code */
    break
}

Operators

or

or, ||

and

and, &&

equal to

==

not equal to

!=

others

*, /, %, |, ~, ^
++,--
+=,-=
// ...pretty much every other operator javascript supports

Series Math Functions

// --- Series math functions ---
lowest(series, range) // lowest value ( for a given number of candles back )
highest(series, range) // highest value ( for a given number of candles back )
sum(series, range) // sum all values ( for a given number of candles back )
sma(series, range) // simple moving average ( for a given number of candles back )
ema(series, range) // exponential moving average ( for a given number of candles back )
stdev(series, range) // standard deviation ( for a given number of candles back )
mom(series, range) // momentum ( for a given number of candles back )
rma(series, alpha) // rolling moving average series function

Built-In Math Functions

min(value1, value2, value3, ...) // returns smallest value of all arguments passed
max(value1, value2, value3, ...) // returns highest value of all arguments passed

radians(degrees) // transforms degrees into radians
degrees(radians) // transforms radians into degrees
isfinite(value) // returns false if value is Infinity or NaN
isnan(value) // returns true if value is NaN
sqrt(value) // returns squareroot of value
abs(value) // returns absolute value
ceil(value) // returns round number up
floor(value) // returns round number down
round(value) // returns rounds number 
trunc(value) // returns the integer part of a number by removing any fractional
exp(value) //  returns Euler's number power of value
sign(value) // returns 1 if value is positive, -1 if negative, 0 if it's 0
sin(value) // returns sinus
cos(value) // returns cosinus
tan(value) // returns tangent
asin(value) // returns arcsine (in radians)
acos(value) // returns arccosine (in radians)
atan(value) // returns arctangent (in radians)

log(value) // returns the base-e logarithm of value
log2(value) // returns the base-2 logarithm of value
log10(value) // returns  the base-10 logarithm of value
pow(value, pow) // returns value power of pow

Colors

built-in color functions

brightness(color, amount) // adjusts color's brightness by a value ( 0-255 )
darken(color, amount) // alias to brightness(color, -amount)
lighten(color, amount) // alias to brightness(color, amount)
blend(colorA, colorB, amount) //  blends between two colors by amount ( 0.0-1.0 )

custom colors

test = #F0b // can be defined using 3 character hexadecimal notation
test = #FF00BB // can be defined using 6 character hexadecimal notation
test = magenta // can be defined using a static color name ( see list below )

list of static colors

black, white, red, lime, blue, yellow, cyan, magenta, silver, gray, maroon, olive, green, purple, teal, navy

color blending

Sometimes some random math such as (close-open) can give good enough results. Everything negative is the first color, everything positive the second color. Blend color value requires a normalized value between 0-1 instead of -1 to 1

study("MyScript")
mycolor = blend(#f00,#0f0,(open-open))
plot(open, lineType=1, linewidth=10, color=mycolor)

Currently Available Data Series

time

time

price

open, high, low, close
ohlc4, hlc3, hl2 // or averages
study("Price Candles", overlay=false)
plotbar(open, high, low, close) // candle plots

volume

vbuy, vsell
study("Volume", overlay=false)
v = (vbuy + vsell)
histogram(v, color = close<open ? red : green, title="Volume")

volume delta

study("Volume Delta", overlay=false)
vd = (vbuy - vsell)
histogram(vd, color = vd<0 ? red : green, title="Volume Delta")

cvd

cumulative volume delta

study("CVD (Cumulative Volume Delta)")
vd = vbuy-vsell, cvd = cum(vd)
plot(cvd,color=#00ff00,title="CVD")

open interest

Open Interest has a built-in layer. It is also available in LitScript. Data series: oi_open, oi_high, oi_low, oi_close. Open Interest is available for all subscribers. It updates automatically.

study("Open Interest in LitScript", overlay=false)
plotbar(oi_open, oi_high, oi_low, oi_close)
oi_open, oi_high, oi_low, oi_close
oi_ohlc4, oi_hlc3, oi_hl2 // or averages

bids & asks

Bid/Ask Sum accepts range ( experimental and slow, only for full range ) ( in %, e.g. bid_sum(120) 120% range of its current closing price )

bid/ask sum

study("[example] Bid/Ask Sum")
plot(bid_sum(),color=#AF0)
plot(ask_sum(),color=#F30)

bid/ask range sum bands

study("Bid/Ask Range Sum Bands")

divide = input("Divide by", 7)
asks = [10]
bids = [10]

for (i=1;i<=10;i++) append(asks,ask_sum((i*i)/divide), darken(#FFAA00,i*10))
for (i=1;i<=10;i++) append(bids,-bid_sum((i*i)/divide), darken(#AAFFAA,i*10))

plot(asks)
plot(bids)

plot(ask_sum())
plot(-bid_sum())

plot(0, color=#333) // middle line

Built-In Variables

na support

Additional Built-In Functions

cum(series) // cumulative value ( like sum but for whole range )

na(value) // same as isnan() checks for NaN value
nz(value) // returns 0 if value is NaN otherwise it returns the value itself

normalize(value, min, max) // transforms value from min/max range to normalized value (0.0-1.0)
denormalize(normalized, min, max) // transforms normalized value (0.0-1.0) to min/max range
lerp(start, end, amount) // same as denormalize(1-amount, start, end)
clamp(value, min, max) // clamps/restricts value to min and max
saturate(value) // same as clamp(value, 0, 1)
maplinear(value, fromStart, fromEnd, toStart, toEnd) // map a value from a range to another range
wrap(value, min, max) // wraps value to min/max range

radians(degrees) // transform degrees to radians
degrees(radians) // transform radians to degrees 

step(a, value)
fmod(a, b)
smoothstep(value, min, max)

List of shapes for plotshape()

plotshape() examples here.

adjust
air
alert
arrow-combo
attach
attention
battery
bell
block
bookmark
bookmarks
bullseye
camera
cancel
cancel-circled
cancel-squared
cd
chart-area
chart-bar
chart-pie
check
circle
circle-empty
circle-thin
clock
cloud
cloud-thunder
cog
database
dot-circled
down
down-bold
down-circled
down-dir
down-open
down-open-big
down-thin
droplet
erase
eye
fast-backward
fast-forward
feather
flag
flash
gauge
heart
heart-empty
help
help-circled
info
info-circled
key
lamp
left
left-bold
left-circled
left-dir
left-open
left-open-big
left-thin
light-down
light-up
link
location
lock
lock-open
magnet
minus
minus-circled
minus-squared
moon
music
note
note-beamed
pause
play
plus
plus-circled
plus-squared
progress-0
progress-1
progress-2
progress-3
quote
record
right
right-bold
right-circled
right-dir
right-open
right-open-big
right-thin
rocket
rss
search
signal
star
star-empty
stop
tag
target
thermometer
thumbs-down
thumbs-up
to-end
to-start
traffic-cone
trophy
up
up-bold
up-circled
up-dir
up-open
up-open-big
up-thin
water

LitScript compilation and execution errors

Ignore the mystery error numbers. It's unknown if anyone actually managed to trigger those. Most important of all: Open Interest is only available to subscribers. Compiler errors for litscripts are shown on main tab.

Error Codes Meaning
Value unused?
00001
Historical value of a series variable is read-only!
Constant "${name}" cannot be modified
Matrix "${name}" cannot be redefined
Matrix "${name}" size cannot exceed [2-${maxSize}] size
Can't assign "${name}" before initialization
00005
Error 00010
"${name}()" can only be used in the root scope
Shape "${shape}" doesn't exist
append(matrix, value, color) : argument mismatch!
append(matrix, value, color) "${matrix}" : argument needs to be a matrix
Study title can't be empty
Study title can't be longer than 100 characters!
Function "${name}" doesn't exist!
00006
Error 00009
Can't declare a function inside a function !
Variable/function "${name}" cannot be redefined
00008
Constant "${name}" cannot be modified
00101
Constant "${name}" cannot be redeclared
Variable "${name}" cannot be redeclared
00008
Constant "${name}" cannot be modified
Unexpected INTERNAL decl: + stmnt.typ
00004
Function "${name}" requires arguments!
Inline series math not supported yet. Temporary solution: Put the argument contents into a separate variable.
First argument needs to be a string
Second argument missing
Function "${name}" doesn't exist!
Variable "${name}" doesn't exist
00007
Cannot assign a value in an expression ( did you mean == ?)
Open Interest is only available to subscribers

Auto-Complete And Syntax Highlighting

Script Vault

Script Vault: the humble beginning of user-made script library Make your scripts private/unlisted/public or simply use scripts made by others

private scripts

the script is private and only you can see its source code and edit it.

unlisted scripts

only users with the link can use the script and view its source code and only you can edit it.

public scripts

anyone can see the source code of the script and they can also make a copy of it.

Script Manager

LitScript can be saved. Separated window.

LitScript Editor

Editor undo / redo history is cleared when changing scripts Multi-Script support ! Separated LitScript window. The LitScript labels of the panes can be toggled ( hidden by default ) Active LitScripts are Sorted by pane order EA+ users: - LitScript slots extended to 5 LitScripts can have descriptions. Descriptions are visible in the Vault.

LitScript Editor size is a fully flexible draggable window.

Official Indicators

Official Indicators tab in Indicators window

free indicators

free built-in indicators that can be used by anyone

volume

free built-in volume indicator that can be used by anyone it has the volume delta incorporated

vpvr

volume profile visible range Value Area for VPVR

heatmap

heatmap lens

subscription indicators

open interest built-in

Layer Settings

layer system

LitScript can create panes. Multi-pane features (add, remove and move layers) You can have more than 2 panes!

Last Price Line option added to all candle layers ( incl. OI ) Panes: Smaller the pane = more price axis ticks will be displayed Price Axis: digits separator for larger numbers Price Axis: auto-scale padding is now flexible ( smaller panes = smaller padding, more chart less empty space ) You have to enable Last Price Line on main candles manually, it's a layer option

auto-scale

Smooth updates when moving multi-pane chart with auto-scale ALL plots will be taken in account heatmap & vpvr will also auto-scale ( so you'll be able to put it in a separate pane ) You can auto-scale panes individually, double-click on axis to set auto-scale Auto-scale button is only linked to the first pane

cross-hair

Cross-hair spans across all panes + candle/volume info is always visible Line charts are not cut off at start and end of visible range

Other Features

  • Large values are supported
  • NaN or Infinite value plots don't break the price axis
  • Block comments color in script editor
  • Series functions range ( it acts like pinescript where 1 is current candle instead of 0 )
  • Reactive Compiling... message

  • Custom charts layout is persistent
  • Script is automatically loaded on start
  • Navigation UI drop-down menus are a bit sexier
  • LitScript plots are grouped under one layer

  • Layer settings are accessible straight from the script editor
  • Layer Settings: Add/Remove pane buttons
  • Ability to filter scripts in Script Vault
  • Max personal scripts limit - 20
  • Plot lines have proper size on high-dpi displays
  • Ability to draw on any pane!
  • Add/Remove pane buttons

  • UTF-16 support
  • Maximize Pane - feature ( + double click shortcut )
  • Pane separator lines are visible in screenshots
  • Accurate latency algorithm, now called RTT
  • Network compression enabled

About

TradingLite - LitScript Documentation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published