Note

深度解析MQL4编程语言中的整数类型及其应用

· Views 166

在MetaQuotes Language 4 (MQL4)中,整数是通过11种不同的类型来表示的。根据编程逻辑的需要,某些类型可以和其他类型一起使用,但在这种情况下,必须记住类型转换的规则。每一种类型都有其特定的特征,下表列出了每种类型的详细信息,包括大小(字节),最小值,最大值,以及对应的C++类型。

类型大小(字节)最小值最大值C++对应类型char1-128127charuchar10255unsigned char, BYTEbool10(false)1(true)boolshort2-32 76832 767short, wchar_tushort2065 535unsigned short, WORDint4– 2 147 483 6482 147 483 647intuint404 294 967 295unsigned int, DWORDcolor4-116 777 215int, COLORREFlong8-9 223 372 036 854 775 8089 223 372 036 854 775 807__int64ulong8018 446 744 073 709 551 615unsigned __int64datetime80 (1970.01.01 0:00:00)32 535 244 799 (3000.12.31 23:59:59)__time64_t

整数类型的值也可以表现为数字常量、颜色字面值、日期时间字面值、字符常量和枚举。下面将详细阐述几个示例。

例如,我们可以使用int类型来计数或表示某些物体的数量。int的范围从 – 2 147 483 648 到 2 147 483 647。如果你有一个变量appleCount来表示苹果的数量,那么你可以这样声明和使用它:

复制

int appleCount = 100;
appleCount = appleCount + 50; //现在,appleCount为150

另一个常见的类型是bool,它只有两个值:0(假)和1(真)。通常在判断条件或控制循环结构时使用。例如:

复制

bool isMarketOpen = true;
if (isMarketOpen)
{
   // 执行相关操作
}

datetime类型用于表示日期和时间,范围从1970年1月1日0点到3000年12月31日23:59:59。例如,我们可以使用它来跟踪交易开始的时间:

复制

datetime startTime = TimeCurrent();
// 执行交易

操作...

以上就是MQL4中整数类型的基本介绍和使用,每种类型都有其特定的用途,选择合适的类型可以帮助提高代码的可读性和效率。


Disclaimer: The content above represents only the views of the author or guest. It does not represent any views or positions of FOLLOWME and does not mean that FOLLOWME agrees with its statement or description, nor does it constitute any investment advice. For all actions taken by visitors based on information provided by the FOLLOWME community, the community does not assume any form of liability unless otherwise expressly promised in writing.

FOLLOWME Trading Community Website: https://www.followme.com

If you like, reward to support.
avatar

Hot

No comment on record. Start new comment.