Type/to search
Built-in Functions
Global
Version
Sleep
IsVirtual
Mail
Mail_Go
SetErrorFilter
GetPid
GetLastError
GetCommand
GetMeta
Dial
HttpQuery
HttpQuery_Go
Encode
UnixNano
Unix
GetOS
MD5
DBExec
UUID
EventLoop
__Serve
_G
_D
_N
_C
_Cross
JSON.parse
JSON.stringify
SetChannelData
GetChannelData
Log
Market
Trade
Account
Futures
NetSettings
Threads
threading
Thread
getThread
mainThread
currentThread
Lock
Condition
Event
Dict
pending
Thread
ThreadLock
ThreadEvent
ThreadCondition
ThreadDict
Web3
TA
Talib
talib.CDL2CROWS
talib.CDL3BLACKCROWS
talib.CDL3INSIDE
talib.CDL3LINESTRIKE
talib.CDL3OUTSIDE
talib.CDL3STARSINSOUTH
talib.CDL3WHITESOLDIERS
talib.CDLABANDONEDBABY
talib.CDLADVANCEBLOCK
talib.CDLBELTHOLD
talib.CDLBREAKAWAY
talib.CDLCLOSINGMARUBOZU
talib.CDLCONCEALBABYSWALL
talib.CDLCOUNTERATTACK
talib.CDLDARKCLOUDCOVER
talib.CDLDOJI
talib.CDLDOJISTAR
talib.CDLDRAGONFLYDOJI
talib.CDLENGULFING
talib.CDLEVENINGDOJISTAR
talib.CDLEVENINGSTAR
talib.CDLGAPSIDESIDEWHITE
talib.CDLGRAVESTONEDOJI
talib.CDLHAMMER
talib.CDLHANGINGMAN
talib.CDLHARAMI
talib.CDLHARAMICROSS
talib.CDLHIGHWAVE
talib.CDLHIKKAKE
talib.CDLHIKKAKEMOD
talib.CDLHOMINGPIGEON
talib.CDLIDENTICAL3CROWS
talib.CDLINNECK
talib.CDLINVERTEDHAMMER
talib.CDLKICKING
talib.CDLKICKINGBYLENGTH
talib.CDLLADDERBOTTOM
talib.CDLLONGLEGGEDDOJI
talib.CDLLONGLINE
talib.CDLMARUBOZU
talib.CDLMATCHINGLOW
talib.CDLMATHOLD
talib.CDLMORNINGDOJISTAR
talib.CDLMORNINGSTAR
talib.CDLONNECK
talib.CDLPIERCING
talib.CDLRICKSHAWMAN
talib.CDLRISEFALL3METHODS
talib.CDLSEPARATINGLINES
talib.CDLSHOOTINGSTAR
talib.CDLSHORTLINE
talib.CDLSPINNINGTOP
talib.CDLSTALLEDPATTERN
talib.CDLSTICKSANDWICH
talib.CDLTAKURI
talib.CDLTASUKIGAP
talib.CDLTHRUSTING
talib.CDLTRISTAR
talib.CDLUNIQUE3RIVER
talib.CDLUPSIDEGAP2CROWS
talib.CDLXSIDEGAP3METHODS
talib.AD
talib.ADOSC
talib.OBV
talib.ACOS
talib.ASIN
talib.ATAN
talib.CEIL
talib.COS
talib.COSH
talib.EXP
talib.FLOOR
talib.LN
talib.LOG10
talib.SIN
talib.SINH
talib.SQRT
talib.TAN
talib.TANH
talib.MAX
talib.MAXINDEX
talib.MIN
talib.MININDEX
talib.MINMAX
talib.MINMAXINDEX
talib.SUM
talib.HT_DCPERIOD
talib.HT_DCPHASE
talib.HT_PHASOR
talib.HT_SINE
talib.HT_TRENDMODE
talib.ATR
talib.NATR
talib.TRANGE
talib.BBANDS
talib.DEMA
talib.EMA
talib.HT_TRENDLINE
talib.KAMA
talib.MA
talib.MAMA
talib.MIDPOINT
talib.MIDPRICE
talib.SAR
talib.SAREXT
talib.SMA
talib.T3
talib.TEMA
talib.TRIMA
talib.WMA
talib.LINEARREG
talib.LINEARREG_ANGLE
talib.LINEARREG_INTERCEPT
talib.LINEARREG_SLOPE
talib.STDDEV
talib.TSF
talib.VAR
talib.ADX
talib.ADXR
talib.APO
talib.AROON
talib.AROONOSC
talib.BOP
talib.CCI
talib.CMO
talib.DX
talib.MACD
talib.MACDEXT
talib.MACDFIX
talib.MFI
talib.MINUS_DI
talib.MINUS_DM
talib.MOM
talib.PLUS_DI
talib.PLUS_DM
talib.PPO
talib.ROC
talib.ROCP
talib.ROCR
talib.ROCR100
talib.RSI
talib.STOCH
talib.STOCHF
talib.STOCHRSI
talib.TRIX
talib.ULTOSC
talib.WILLR
talib.AVGPRICE
talib.MEDPRICE
talib.TYPPRICE
talib.WCLPRICE
OS
Structures
Built-in Variables

File object that provides file read/write, positioning and other operations.

Close the file and release associated resources.

close()

Examples

Example of proper file operation workflow.

javascript
function main() { let file = os.open("data.txt", "w") file.write("Hello FMZ!") file.close() // 必须关闭文件 }

See Also

Remarks

This method must be called after using the file object to release system resources.

Write one or more strings to a file.

puts(data1, data2, ...dataN)

Examples

Write multiple strings to a file.

javascript
function main() { let file = os.open("output.txt", "w+") let bytes = file.puts("Hello", " ", "World", "!") Log("Bytes written:", bytes) // Bytes written: 12 file.seek(0, 0) let data = file.read() Log("data:", data) // If using os.open("output.txt", "w") may result in data being undefined // data: Hello World! // file.puts() // error: puts requires at least 1 argument at main file.puts(", Hello FMZ!") file.seek(0, 0) data = file.read() Log("data:", data) // data: Hello World!, Hello FMZ! file.close() }

Returns

TypeDescription

number

Returns the actual number of bytes written.

Arguments

NameTypeRequiredDescription

data

string

Yes

String data to be written, multiple parameters can be passed.

See Also

Remarks

Multiple string parameters can be written at once, they will be concatenated in order and then written.

Write formatted data to file.

printf(format)
printf(format, arg1, arg2, ...argN)

Examples

Write formatted trading data.

javascript
function main() { let file = os.open("trade_log.txt", "w+") let price = 100.25 let volume = 1000 let bytes = file.printf("Price: %.2f, Volume: %d\n", price, volume) Log("Formatted bytes written:", bytes) file.seek(0, 0) let data = file.read() Log("data:", data) // data: Price: 100.25, Volume: 1000 // file.printf("| Price: %.2f, Volume: %d\n") // "| Price: %!f(MISSING), Volume: %!d(MISSING)" // file.seek(0, 0) // data = file.read() // Log("data:", data) file.close() }

Returns

TypeDescription

number

Returns the actual number of bytes written.

Arguments

NameTypeRequiredDescription

format

string

Yes

Format string.

args

any (any type supported by the platform)

No

Format arguments.

See Also

Flush the file buffer to ensure data is written to disk.

flush()

Examples

Write important log data in real-time.

javascript
function main() { let logFile = os.open("critical.log", "a") logFile.printf("[%s] Critical event occurred\n", new Date().toISOString()) // [2025-09-09T03:15:43.895Z] Critical event occurred logFile.flush() // Immediately write data to disk // Continue with other operations... logFile.close() }

See Also

Get the current file pointer position.

tell()

Examples

Track position during file operations.

javascript
function main() { let file = os.open("data.txt", "r+") Log("Initial position:", file.tell()) // Initial position: 0 file.write("Hello") Log("After write position:", file.tell()) // After write position: 5 file.close() }

Returns

TypeDescription

number

Returns the current file pointer position (offset in bytes).

See Also

Remarks

Returns the byte offset of the current file pointer relative to the beginning of the file.

Move the file pointer to a specified position.

seek(offset, whence)

Examples

Read characters in reverse order.

javascript
function main() { let str = "Hello FMZ!" let file = os.open("data.txt", "w+") file.write(str) // If i > str.length: will throw InternalError: seek .../xxx/data.txt: invalid argument at main for (let i = 1; i <= str.length; i++) { file.seek(-i, 2) let data = file.read(1) Log("i:", i, ", data:", data) } file.close() }

Returns

TypeDescription

number

Returns the new file pointer position.

Arguments

NameTypeRequiredDescription

offset

number

Yes

Offset (in bytes).

whence

number

Yes

Reference position: 0=beginning of file, 1=current position, 2=end of file.

See Also

Remarks

Used to position the file pointer, the offset parameter can be negative (indicating backward movement).

Check if the file pointer has reached the end of file.

eof()

Examples

Read file line by line until end of file.

javascript
function main() { let file = os.open("data.txt", "r") let lineCount = 0 while (!file.eof()) { let line = file.getline() if (line) { lineCount++ Log("Line", lineCount + ":", line) } } Log("Total lines:", lineCount) file.close() }

Returns

TypeDescription

bool

Returns true if end of file has been reached, otherwise returns false.

See Also

Remarks

Used to determine whether all content has been read when reading a file.

Read data from a file.

read()
read(size)

Examples

Read file content in chunks.

javascript
function main() { let file = os.open("data.txt", "r") // data.txt // This is a test line: Line 1. // This is a test line: Line 2. // ... let chunkSize = 29 let totalBytes = 0 while (!file.eof()) { let chunk = file.read(chunkSize) if (chunk) { totalBytes += chunk.length || chunk.byteLength Log("Read chunk, total bytes so far:", totalBytes, ", chunk:", chunk) } } file.close() }

Returns

TypeDescription

string / ArrayBuffer / undefined

Returns the content read. Returns undefined when the end of file is reached.

Arguments

NameTypeRequiredDescription

size

number

No

Number of bytes to read. If not specified, reads all remaining content in the file.

See Also

Remarks

Can read a specified number of bytes or all remaining content in the file. The return type may be string or ArrayBuffer.

Write string data to a file.

write(data)

Examples

Writing trade records

javascript
function main() { let file = os.open("trades.log", "a") let timestamp = new Date().toISOString() let tradeInfo = `${timestamp},BUY,50000,1\n` let bytes = file.write(tradeInfo) Log("Trade record written, bytes:", bytes) file.close() }

Returns

TypeDescription

number

Returns the actual number of bytes written.

Arguments

NameTypeRequiredDescription

data

string

Yes

The string data to be written.

See Also

Remarks

Writes string data to the current position in the file.

Read the next line from the file.

getline()

Examples

Read file line by line until the end.

javascript
function main() { let file = os.open("data.txt", "r") let lineCount = 0 while (!file.eof()) { let line = file.getline() if (line) { lineCount++ Log("Line", lineCount + ":", line) } } Log("Total lines:", lineCount) file.close() }

Returns

TypeDescription

string / undefined

Returns the next line content, returns undefined when reaching end of file.

See Also

Remarks

Read file content line by line in sequential order.

Get the string representation of the file object.

toString()

Examples

Get the description information of the file object.

javascript
function main() { let file = os.open("data/data.txt", "r") Log("File info:", file.toString()) // File info: File(data/data.txt) file.close() }

Returns

TypeDescription

string

Returns the string description information of the file object.

See Also

Remarks

Returns the description information of the file object.