スプレッド比較と無料攻略法
ドル円 | ユーロ円 | ポンド円 | 豪ドル円 | ユーロドル | キャッシュバック | ||
---|---|---|---|---|---|---|---|
GMOクリック証券 | 0.1銭 | 0.3銭 | 0.6銭 | 0.4銭 | 0.3pips | 最大 30,000円 | 攻略法 |
みんなのFX | 0.2銭 | 0.4銭 | 0.8銭 | 0.6銭 | 0.3pips | 総額 1,000万円 |
攻略法 |
マネーパートナーズ | 0.3銭 | 0.4銭 | 0.9銭 | 0.6銭 | 0.4pips | ![]() マル秘レポート | 攻略法 |
当サイト限定キャンペーン
限定レポート | 『FXマル秘レポート』マネーパートナーズ | 『特別レポート(非売品)』ひまわり証券 |
---|---|---|
キャッシュバック | 最大50万8,000円 FXプライム byGMO | 最大5,000円 LINE FX |
★取引必要なし | 図書カード3,000円 FXTS | 売買シグナルインジケーター XM |
【動画】MQLによる移動平均線インジケーターの自作プログラミング
MT4で移動平均線インジケーターを自作する
まず、前回のソースコード。ローソク足の高値をラインで結ぶ、というものでした。線を1本引いただけで、インジケーターとはいいがたいものでしたので、今回は移動平均線を作ってみます。
前回のソースコードの、チャートが動くたび実行されるOnCalculate関数の中身を、高値のラインから移動平均線へと変えていきます。試しに5日移動平均線を作ってみたいのですが、移動平均線の仕組みはこのようになっています。
移動平均線の計算説明

if文を使う部分の説明

for文を使う部分の説明

移動平均線インジケーターのソースコード
//+------------------------------------------------------------------+
//| 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{
Label1Buffer[i]=0;
for(j=0; j{
Label1Buffer[i]=Label1Buffer[i]+Close[i+j];
}
Label1Buffer[i]=Label1Buffer[i]/MA_Period;
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
最終更新日 : 2020-11-12