【MT4】MQLによる移動平均線インジケーターのプログラミング
※当ページはプロモーションが含まれています
【動画】MQLによる移動平均線インジケーターの自作プログラミング
移動平均線インジケーターのソースコード
//+------------------------------------------------------------------+
//| ma.mq4 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
//--- plot Label1
#property indicator_label1 "Label1"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrYellow
#property indicator_style1 STYLE_SOLID
#property indicator_width1 3
//--- indicator buffers
double Label1Buffer[];
extern int MA_Period=5;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,Label1Buffer);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
//---
int i;
int j;
int limit;
if(prev_calculated==0){
limit=rates_total-1;
}
else
{
limit=rates_total-prev_calculated;
}
for(i=limit; i>=0; i--)
{
if(i+MA_Period-1<rates_total)
{
Label1Buffer[i]=0;
for(j=0; j<ma_period; j++)<br="">{
Label1Buffer[i]=Label1Buffer[i]+Close[i+j];
}
Label1Buffer[i]=Label1Buffer[i]/MA_Period;
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
</ma_period;></rates_total)MT4で移動平均線インジケーターを自作する
まず、前回のソースコード。ローソク足の高値をラインで結ぶ、というものでした。線を1本引いただけで、インジケーターとはいいがたいものでしたので、今回は移動平均線を作ってみます。 前回のソースコードの、チャートが動くたび実行されるOnCalculate関数の中身を、高値のラインから移動平均線へと変えていきます。試しに5日移動平均線を作ってみたいのですが、移動平均線の仕組みはこのようになっています。移動平均線の計算説明

if文を使う部分の説明

for文を使う部分の説明

まぐまぐ殿堂入りメルマガ
毎朝6時、今日の為替相場予想が届く
無料メールマガジン「マナブ式FX」
ドル円・ユーロ円の予想レンジ、経済指標の結果と予定、ドル円の板情報。 その日のトレードに必要な材料を、相場が動き出す前にまとめて受け取れます。
- 著書7冊(成美堂出版・扶桑社・実業之日本社)
- DVD3本(パンローリング)
- ダイヤモンドZAi・FX攻略.com ほか掲載多数
- まぐまぐ殿堂入り
東京仲値EA「サイバーゴトビ」を無料プレゼント
メールアドレスを入力するだけ
利用規約
- メルマガへの登録を希望する場合、登録ボタンの押下で登録申し込みをするものとします。
- 登録アドレスに対し、当メルマガを配信できるものとします。
- メルマガの内容の信頼性、正確性又は合法性等について、一切の責任を負いません。
- 購読は無料です。配信停止は各メール末尾のリンクからいつでも行えます。
- 登録されたメールアドレスは本メルマガおよび関連するご案内の配信にのみ使用し、第三者に提供しません。
送信者情報
発行者:株式会社サイバーネット 斉藤学
お問い合わせ:kamiturejp@yahoo.co.jp










