mt4函数和编程必备(7)

2020-04-14 06:25

:: 输入参数 date - 输入日期

示例:

int day=TimeDay(D'2003.12.31'); // day is 31

int TimeDayOfWeek( datetime date) 返回输入日期中的日期是星期几 (0-6)

:: 输入参数 date - 输入日期

示例:

int weekday=TimeDayOfWeek(D'2004.11.2'); // day is 2 - tuesday

int TimeDayOfYear( datetime date) 返回输入日期中的日期在当年中的第几天

:: 输入参数 date - 输入日期

示例:

int day=TimeDayOfYear(CurTime());

int TimeHour( datetime time) 返回输入日期中的小时

:: 输入参数 date - 输入日期

示例:

int h=TimeHour(CurTime());

int TimeMinute( datetime time) 返回输入日期中的分钟

:: 输入参数 date - 输入日期

示例:

int m=TimeMinute(CurTime());

int TimeMonth( datetime time) 返回输入日期中的月份

:: 输入参数 date - 输入日期

示例:

int m=TimeMonth(CurTime());

int TimeSeconds( datetime time) 返回输入日期中的秒钟

:: 输入参数 date - 输入日期

示例:

int m=TimeSeconds(CurTime());

int TimeYear( datetime time) 返回输入日期中的年份

:: 输入参数 date - 输入日期

示例:

int y=TimeYear(CurTime());

int TimeYear( datetime time) 返回当前年份 示例:

// return if date before 1 May 2002 if(Year()==2002 && Month()<5) return(0); 文件处理函数 [File Functions]

void FileClose(int handle) 关闭正在已经打开的文件.

:: 输入参数

handle - FileOpen()返回的句柄

示例:

int handle=FileOpen(\if(handle>0) { // working with file ... FileClose(handle); }

void FileDelete(string filename)

删除文件,如果发生错误可以通过GetLastError()来查询 注:你只能操作terminal_dir\\experts\\files目录下的文件

:: 输入参数

filename - 目录和文件名

示例:

// file my_table.csv will be deleted from terminal_dir\\experts\\files directory int lastError; FileDelete(\lastError=GetLastError(); if(laseError!=ERR_NOERROR) { Print(\,\return(0); }

void FileFlush(int handle) 将缓存中的数据刷新到磁盘上去

:: 输入参数

handle - FileOpen()返回的句柄

示例:

int bars_count=Bars; int handle=FileOpen(\if(handle>0) { FileWrite(handle, \for(int i=0;i

bool FileIsEnding(int handle) 检查是否到了文件尾.

:: 输入参数

handle - FileOpen()返回的句柄

示例:

if(FileIsEnding(h1)) { FileClose(h1); return(false); }

bool FileIsLineEnding( int handle) 检查行是否到了结束

:: 输入参数

handle - FileOpen()返回的句柄

示例:

if(FileIsLineEnding(h1)) { FileClose(h1); return(false); }

int FileOpen( string filename, int mode, int delimiter=';') 打开文件,如果失败返回值小于1,可以通过GetLastError()获取错误 注:只能操作terminal_dir\\experts\\files目录的文件

:: 输入参数

filename - 目录文件名

mode - 打开模式 FILE_BIN, FILE_CSV, FILE_READ, FILE_WRITE. delimiter - CSV型打开模式用的分割符,默认为分号(;).

示例:

int handle; handle=FileOpen(\if(handle<1) { Print(\return(false); }

int FileOpenHistory( string filename, int mode, int delimiter=';') 打开历史数据文件,如果失败返回值小于1,可以通过GetLastError()获取错误

:: 输入参数

filename - 目录文件名

mode - 打开模式 FILE_BIN, FILE_CSV, FILE_READ, FILE_WRITE. delimiter - CSV型打开模式用的分割符,默认为分号(;).

示例:

int handle=FileOpenHistory(\if(handle<1) { Print(\return(false); } // work with file // ... FileClose(handle);

int FileReadArray( int handle, object& array[], int start, int count) 将二进制文件读取到数组中,返回读取的条数,可以通过GetLastError()获取错误

注:在读取之前要调整好数组大小

:: 输入参数

handle - FileOpen()返回的句柄 array[] - 写入的数组 start - 在数组中存储的开始点 count - 读取多少个对象

示例:

int handle; double varray[10]; handle=FileOpen(\if(handle>0) { FileReadArray(handle, varray, 0, 10); FileClose(handle); }

double FileReadDouble( int handle, int size=DOUBLE_VALUE)

从文件中读取浮点型数据,数字可以是8byte的double型或者是4byte的float型。

:: 输入参数

handle - FileOpen()返回的句柄

size - 数字个是大小,DOUBLE_VALUE(8 bytes) 或者 FLOAT_VALUE(4 bytes).

示例:

int handle; double value; handle=FileOpen(\if(handle>0) { value=FileReadDouble(handle,DOUBLE_VALUE); FileClose(handle); }

int FileReadInteger( int handle, int size=LONG_VALUE) 从文件中读取整形型数据,数字可以是1,2,4byte的长度

:: 输入参数

handle - FileOpen()返回的句柄

size - 数字个是大小,CHAR_VALUE(1 byte), SHORT_VALUE(2 bytes) 或者 LONG_VALUE(4 bytes).

示例:

int handle; int value; handle=FileOpen(\if(handle>0) { value=FileReadInteger(h1,2); FileClose(handle);


mt4函数和编程必备(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:江苏省机关第六届万人学法知识竞赛 网上答题试卷4

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: