//--- 入力パラメータ
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;
}
//--- 現在のBid値を取得する
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;
}
//--- 2つの価格(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"));
}
|