MathMax

이 함수는 두 값의 최대값을 반환합니다.

double  MathMax(
   double  value1,     // 첫번째 값
   double  value2      // 두번째 값
   );

Parameter

value1

[in]  첫번째 숫자 값.

value2

[in]  두번째 숫자 값.

반환값

두 값 중 더 큰 값.

참고

MathMax() 대신에 fmax()를 사용하실 수 있습니다. 함수 fmax(), fmin(), MathMax(), MathMin()는 정수 형식을 double 형식으로 타이프캐스팅하지 않고 사용할 수 있습니다.

다른 유형의 파라미터가 함수에 전달되면 작은 유형의 파라미터가 큰 유형에 자동으로 캐스트됩니다. 반환 값의 유형은 보다 큰 유형에 해당합니다.

동일한 유형의 데이터를 통과하면 캐스팅이 수행되지 않습니다.

 

Example:

//--- input parameters
input int                  InpPeriod = 10;            // Moving average calculation period
input ENUM_MA_METHOD       InpMethod = MODE_SMA;      // Moving average calculation method
input ENUM_APPLIED_PRICE   InpPrice  = PRICE_CLOSE;   // Moving average calculation price
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- if the moving average period is set to a value less than 1, then the default value (10) is used
   int period=(InpPeriod<1 ? 10 : InpPeriod);
//--- create the Moving Average indicator handle
   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;
     }
//--- get the current Bid price
   double bid=0;
   ResetLastError();
   if(!SymbolInfoDouble(Symbol(),SYMBOL_BID,bid))
     {
      Print("Failed to get Bid price. Error ",GetLastError());
      return;
     }
//--- get the moving average value on the current bar
   double array[1];
   int    copied=CopyBuffer(handle,0,0,1,array);
   if(copied!=1)
     {
      Print("Failed to get Moving Average data. Error ",GetLastError());
      return;
     }
//--- get the highest price of the two (Bid price and Moving Average value) and display the resulting data in the journal
   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"));
  }