MathMax
MathMax
函数返回最大的量个值。
double MathMax(
double value1, // 第一值
double value2 // 第二值
);参量
- value1
[in] 第一个数字值。
- value2
[in] 第二个数字值。
返回值
两个值中的最大值。
注释
取代MathMax()可以使用 fmax()。 函数 fmax(), fmin(), MathMax(), MathMin() 是整型的,而非铸字的双精度类型。
如果不同类型参量通过函数传递,副类型参量自动转到主类型。该类型返回值相当于主类型返回值。
如果相同数据类型传递,不用执行铸字。
示例:
//--- 输入参数
input int InpPeriod = 10; // 移动平均线计算周期
input ENUM_MA_METHOD InpMethod = MODE_SMA; // 移动平均线计算方法
input ENUM_APPLIED_PRICE InpPrice = PRICE_CLOSE; // 移动平均线计算价格
//+------------------------------------------------------------------+
//| 脚本程序起始函数 |
//+------------------------------------------------------------------+
void OnStart()
{
//--- 如果移动平均线周期设置为小于1的值,则使用默认值(10)
int period=(InpPeriod<1 ? 10 : InpPeriod);
//--- 创建移动平均线指标句柄
int handle=iMA(Symbol(),Period(),period,0,InpMethod,InpPrice);
if(handle==INVALID_HANDLE)
{
Print("Failed to create the Moving Average indicator handle. Error ",GetLastError());
return;
}
//--- 获得当前卖价
double bid=0;
ResetLastError();
if(!SymbolInfoDouble(Symbol(),SYMBOL_BID,bid))
{
Print("Failed to get Bid price. Error ",GetLastError());
return;
}
//--- 获得当前柱形图的移动平均线值
double array[1];
int copied=CopyBuffer(handle,0,0,1,array);
if(copied!=1)
{
Print("Failed to get Moving Average data. Error ",GetLastError());
return;
}
//--- 获取两者中最高的价格(卖价和移动平均线值),并在日志中显示结果数据
double max_price=MathMax(bid,array[0]);
PrintFormat("Bid: %.*f, Moving Average: %.*f, highest price of the two: %.*f",_Digits,bid,_Digits,array[0],_Digits,max_price);
PrintFormat("Bid price %s moving average",(bid>array[0] ? "higher" : bid<array[0] ? "lower" : "equal to"));
}