【MT4のプログラミングをやってみる】簡単MA

 

まえがき

こんにちは、こんばんは、脱初心者トレーダーさつま芋です。

 

ちょっと調べたり考えたりすれば分かるような盲点情報などをシェアしたいと思います。

 

 

MT4のインジを作ってみる

素人ですが、取引ツールMT4でプログラミング(MQL)の勉強を始めました。

 

折角なので、自分好みのインジケーターやEAを作りたいと思っています。

 

同じような志の人がいるかもしれませんので、勉強の足跡を残してみます。

 

とりあえずネットで学べそうな気がしているので、最初は お金をかけず、必要が出てくれば本などを買ってみようと考えています。

 

 

HTのMQL習得 Step1 簡単MA

参考にするのはHTさんの動画です。

 

今回は次の動画をタイピングしてみました。

 

www.youtube.com

 

コード

今回、実際にタイピングしたのは太字部分だけです。

 

//+------------------------------------------------------------------+
//| MA_demo.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 MA
#property indicator_label1 "MA"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- indicator buffers
double MABuffer;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,MABuffer);

//---
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[])
{
//---
for (int i = 0; i < Bars; i++) {
MABuffer[i] = iMA(NULL, 0, 20, 0, MODE_SMA, PRICE_CLOSE, i);
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+

 

 

あとがき

バッファ(Buffer)とか意味わかりませんが、とりあえずコンパイル&実行したら動作しました。

 

f:id:satsumaim0:20200626073943p:plain

 

以上、さつま芋でした。