New Features of version2
● Use = for the first assignment, such as
a = 10
● Use := for subsequent assignments, such as
a := 10
● Scope handling, variables defined using if, for, func, etc., cannot be used outside the structure
b = 0 // Define global variable
if (close > open){
a = 1 // Define variable inside if, cannot be used outside if
b := 1 // Change global variable
}
plot(a) // Error
plot(b) // Okay
● Array handling
N1 = 1;
N2 = 2;
a = [1,2,3,N1,N2];
b = a{1} // Access array using index{}
● Function handling
recursion(int a) {
if (a == 1) {
return 1;
}
return a * recursion(a-1);
}
int a = recursion(5);
funcma(x, y) { sum = 0.0 for(i = 0; i < y; i++){ sum := sum + x[i]/y } return sum } a = funcma(high,10) // Calculate 10-day moving average equivalent to ma(high,10)
● Semicolons at the end of statements can be omitted
● Conditional drawing is supported, color can be assigned using the ternary operator, such as:
color = close > open ? 'red' : 'green'
● Data types
int: integer
float: floating point number
string: string
bool: boolean
byte: byte
any: any type
● plot and alert only support calculation of regular expressions, do not support function calls or if statements
Old version:
plot(if close > open {close } else {open})
New version:
plot(close > open ? close : open)
● The expression of the ternary operator does not support variable definition, variable assignment can be used
Old version:
close > open ? a = close : a = open
New version:
a = close > open ? close : open
● The indicator function can only be used once
indicator(precision = 2)
indicator(precision = 2) // Error
● plot and alert cannot be defined within local scopes such as if, for, func, etc.
// Error
if close > open {
plot(close)
} else {
plot(open)
}
● Indicator function variables
[mb, up, dn] = boll(close,20, 2)
// Brackets can be omitted, such as
mb, up, dn = boll(close,20, 2)
● The result of division operation defaults to float type, such as
1/2=0.5
● not can be used without parentheses, such as
not a > 1
● Multi-line comments can use /* */, single-line comments use //
// Single-line comment
/*
Multi-line comment
*/
● break and continue can be used to end the loop early in for loops
for i=0;i<10;i++{
if i == 5 {
break
}
// println is used as an example, please use plot or alert in actual use
println(i) // 0,1,2,3,4
}
for i=0;i<10;i++{
if i == 5 {
continue
}
// println is used as an example, please use plot or alert in actual use
println(i)
}
● If return is used in for, the function will end early, using return in the outermost for will end the script early
for i=0;i<10;i++{
if i == 5 {
return
}
// println is used as an example, please use plot or alert in actual use
println(i)
}
// Will not be executed
println("end")
● Using indicators or method functions in for loops will result in duplicate calculations, it is recommended to calculate outside the for loop and then use
a = nan
ma5 = ma(close,5)
for i=0;i<10;i++{
a := ma(close,i) // Only calculates ma(close,0), which is not as expected
}
● For loops support using the range function, currently only supports iterating over arrays
a = [1,2,3,4,5]
for i in range(a){
// println is used as an example, please use plot or alert in actual use
println(i) // 0,1,2,3,4
}
● The stored values of sequence variables are only for 500 periods, all historical data references have a maximum value of 499
a = close[0] // Okay
a = close[499] // Okay
a = close[500] // Error
● The maximum value for array initialization is 1000
● In division operations, if the divisor is 0, it returns an empty value or nan
a = 1/0 // Returns an empty value
免责声明:本文章仅代表作者个人观点,不代表本平台的立场和观点。本文章仅供信息分享,不构成对任何人的任何投资建议。用户与作者之间的任何争议,与本平台无关。如网页中刊载的文章或图片涉及侵权,请提供相关的权利证明和身份证明发送邮件到support@aicoin.com,本平台相关工作人员将会进行核查。