//--- 입력 매개변수
input int InpPeriod = 10; // 이동 평균 계산 기간
input ENUM_MA_METHOD InpMethod = MODE_SMA; // 이동 평균 계산 방법
input ENUM_APPLIED_PRICE InpPrice = PRICE_CLOSE; // 이동 평균 계산 가격
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//--- 이동 평균 기간을 1보다 작은 값으로 설정하면 기본값(10)이 사용됩니다.
int period=(InpPeriod<1 ? 10 : InpPeriod);
//--- 이동 평균 지표 핸들 생성
int handle=iMA(Symbol(),Period(),period,0,InpMethod,InpPrice);
if(handle==INVALID_HANDLE)
{
Print("이동 평균 지표 핸들을 생성하지 못했습니다. Error ",GetLastError());
return;
}
//--- 현재 Bid 가격을 가져옵니다.
double bid=0;
ResetLastError();
if(!SymbolInfoDouble(Symbol(),SYMBOL_BID,bid))
{
Print("Bid 가격을 가져오지 못했습니다. Error ",GetLastError());
return;
}
//--- 현재 바의 이동 평균 값을 가져옵니다.
double array[1];
int copied=CopyBuffer(handle,0,0,1,array);
if(copied!=1)
{
Print("이동 평균 데이터를 가져오지 못했습니다. Error ",GetLastError());
return;
}
//--- 둘 중 가장 높은 가격(Bid 가격과 이동 평균 값)을 구하고 결과 데이터를 저널에 표시합니다.
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"));
}
|