MT4と言うか、MQL4にかなり慣れてしまったので、MT5の開発言語であるMQL5に違和感しか感じません。
でも、せっかくMT5に触れたことだし、しばらくMT5ベースの開発に触れてみることにします。
使える使えないの判断はもう少し触ってみないと分からないので、ひょっとすると凄く良いかもしれませんしね!
とりあえず基本中の基本として移動平均線を描画させるインジケーターを作って見ました。
//+------------------------------------------------------------------+ //| MALine.mq5 | //| Copyright 2017, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2017, Forex related to FX trading." #property link "http://fxtrading.greeds.net" #property version "1.00" #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 #property indicator_label1 "MALine" #property indicator_type1 DRAW_LINE #property indicator_color1 Gold #property indicator_style1 STYLE_SOLID #property indicator_width1 3 input int period=20; input int shift=0; double maLine[]; int maLineHandle; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { SetIndexBuffer(0,maLine,INDICATOR_DATA); maLineHandle = iMA(NULL,0,period,shift,MODE_EMA,PRICE_CLOSE); 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[]) { if(BarsCalculated(maLineHandle)<rates_total) return(0); int to_copy; if(prev_calculated>rates_total || prev_calculated<=0) to_copy=rates_total; else { to_copy=rates_total-prev_calculated; to_copy++; } if(CopyBuffer(maLineHandle,0,0,to_copy,maLine)<=0) return(0); return(rates_total); }
MQL4での実装とは全然違う感じになってしまいました。
MQL5ではプラットフォーム部分が計算部分を手伝ってくれるらしいので、こう言う記述になるようですが、どうにもスッキリしません。
コード的にはスッキリしているんですが、やっぱり違和感がありますね。
今回は基本中の基本であるインジケーターの作成で練習してみたので、次からは矢印や、複数バッファを試してみたいと思います。