MathMin

函数返回两个值中的最小值。

double  MathMin(
   double  value1,     // 第一值
   double  value2      // 第二值
   );

参量

value1

[in]  第一数字值。

value2

[in]  第二数字值

返回值

两值中最小的。

注释

取代MathMin()可以使用 fmin()。函数 fmax(), fmin(), MathMax()MathMin() 是整型,而非铸字的双精度类型。

如果是不同类型参量传递到函数中,副类型参量自动 到主类型。返回值类型与主类型相同。

如果数据类型传递,不需要执行铸字。

 

示例:

//--- 输入参数
input uint  InpBars  =  100000;  // Desired number of bars
 
//+------------------------------------------------------------------+
//| 脚本程序起始函数                                                   |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- 获得服务器上可用柱形图的数量
   uint bars_total = Bars(Symbol(),Period());
   if(bars_total==0)
     {
      PrintFormat("Data for timeseries %s %s not yet generated in the terminal. Please try again later.",Symbol(),StringSubstr(EnumToString(Period()),7));
      return;
     }
//--- 从两个值中获取最小柱形图数量 - 从服务器上可用的值和从设置中请求的值
   int bars = (int)MathMin(bars_total,InpBars);
//--- 如果请求的柱形图数量多于服务器上可用的柱形图,请在日志中报告此情况
   if(bars_total<InpBars)
      PrintFormat("Number of bars on the server (%u) is less than requested (%u)",bars_total,InpBars);
//--- 在日志中显示可用于工作的柱形图数量
   Print("Bars available for work: ",bars);
  }