トレンドラインにタッチでエントリーなどのEAを作成するために、便利な関数をご紹介します。
目次
ObjectGetValueByShift関数を使う
ObjectGetValueByShift()関数では、指定したシフト数に対する価格を取得することができます。
トレンドラインや水平線の価格を取得することが出来るので、ラインタッチによる転換を狙うEAなどを簡単に作成することができます。
double ObjectGetValueByShift(string name, int shift);引数の意味は以下です。
| 引数名 | 詳細 |
|---|---|
| name | オブジェクト名を指定します。 |
| shift | 取得したい価格のシフト数を指定します。 |
サンプルコード
トレンドラインにタッチでアラートを鳴らします。
以下サンプルコードです。
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time;[],
const double &open;[],
const double &high;[],
const double &low;[],
const double &close;[],
const long &tick;_volume[],
const long &volume;[],
const int &spread;[])
{
double linePrice = ObjectGetValueByShift("オブジェクト名", 0);
if (Open[0] > linePrice && Close[0] <= linePrice){
Alert("Line touch!!");
}
if (Open[0] < linePrice && Close[0] >= linePrice){
Alert("Line touch!!");
}
return(rates_total);
}