Skip to content

WaiSiuKei/finscript

Repository files navigation

Finscript

Technical analysis domain specific language for creating reusable indicator calculator

Demo

Doc

Primitive types

  • Number:
a = 1
b = 2.3
  • Boolean
a = true
b = false
  • String
a = 'blah blah'
b = "blah blah"
c = '中文'
  • Object
a = {}
b = { a: 1, b: 2 }
c = { a, b }
d = { c, f: {} }
  • Array
a = [1, 2, 3]
b = [{ open: 10, close: 12 }, { open: 12, close: 14 }]
  • Color
a = #fff
b = #123456
c = #123456ff
  • Null
a = null

Comment

  • Single-line comment
// FIXME
  • Multi-line comment
/*
  blah
  blah
  blah
*/

Operator

  • Assign:=
  • Add:+
  • Subtract:-
  • Multiply:*
  • Divide:/
  • Modulus:%
  • Pow:^
  • Greater than:>
  • Less than:<
  • Greater than or equal:>=
  • Less than or equal:<=
  • Equal:==
  • Not equal:!==
  • And:and
  • Or:or
  • Not:not
  • Conditional operator: condition ? expression : expression

statement

  • if statement:
if a ==1 :
  // do something
else if a == 2:
  // do something
end
  • For loop:
for i in array:
  // do something
end
  • While loop:
while true:
  // do something
end

Function

  • Function declaration:
def print(a):
  Console.log(a)
end
  • Arrow function:
add = (a, b) => a + b
inc = a => a + 1
  • Function call:
Console.log(1)

Indicator operator

  • Open price:OPEN O

  • Close price:CLOSE C

  • High price:HIGH H

  • Low price:LOW L

  • Bar volume:VOLUME V VOL

  • Absolute value:ABS

ABS(O - C)
  • Arctangent:ATAN
ATAN(C)
  • Ceil: CEIL
CEIL(2.3) // 3 
  • Constant:CONST
CONST(1)
  • Cosine:COS
COS(C)
  • Count bars if condition is true:COUNT
COUNT(CLOSE > OPEN, 10)
  • Exponentially weighted moving average:EMA
EMA(C, 10)
  • Exponential Function: EXP
EXP(2) // e^2
  • Expmema: EXPMEMA
EXPMEMA(C, 10)
  • Floor: FLOOR
FLOOR(2.5) // 2
  • Max value of n bars:HHV
HHV(MAX(O, C), 60)
  • Min value of n bars:LLV
LLV(MIN(O, C), 60)
  • Natural logarithm:LN
LN(C)
  • Base-10 logarithmic:LOG
LOG(C)
  • Moving average:MA
MA(C, 60)
  • Greater of two or more values:MAX
MAX(O, C)
MAX(O, C, 100)
  • Smaller of two or more values:MIN
MIN(O, C)
MIN(O, C, 100, REF(C, 1))
  • Mathematical power function: POW
POW(C, 2)
  • Round: ROUND
ROUND(C)
  • Previous values :REF
REF(C, 10)
  • Sar:SAR
step = 2
  • Sine:COS
SIN(C)
  • Simple moving average:SMA
SMA(C, 10)
  • Square root :SQRT
SQRT(C)
  • Standard deviation:STD
STD(C, 10)
  • Sliding sum: SUM
SUM(C, 10)
  • Trigonometric tangent:TAN
TAN(C)

Creating new operator

prevClose = REF(C, 1)
prevLow = REF(L, 1)
true_range = MAX(H - L, H - prevLow, L - prevClose)

Indicator

Checkout demo

Built-in funciton

Number

  • Number.parseInt
  • Number.parseFloat
  • Number.prototype.toExponential
  • Number.prototype.toFixed
  • Number.prototype.toPrecision

Console

  • Console.log

About

Technical analysis DSL for creating reusable indicator calculator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published