やっぱりかなり勝手が違いますね・・・
ちょっとした事でハマってしまいます(´・ω・`)
取り合えずなんとかMAクロスで矢印描画が出来たので、なんとかなりそうです。
これでシグナル系のインジは作れるって事になりますが、データの作り方に少し不安があるので、もう少し修行してみるとします。
あ、なんでこんな事をしているのかというと、自分でシステムを作るためです。
既にMT5用のインジケーターも多数でておりますが、やはりまだまだMT4が主流です。
こういう作業は自分で触らないと覚えないので、人のコードを読み解きながら自分なりに理解して行く必要があるのです。
ある程度くめるようにならないと人のコードすら読めませんからね〜
ちなみに今回のはまりポイントは矢印描画がされなかったことです。
原因としては PlotIndexSetInteger(0,PLOT_ARROW,233);のSetが正解なんですが、Getで記述していたためずっと矢印がでませんでした。
気が付くとくだらないんですが、はまっている最中は呪いかと思うくらい原因が分からないものです。
これも経験、同じ事は二度としないようになるので、次回からの生産性アップに繋がります!
//+------------------------------------------------------------------+ //| MACrossArrow.mq5 | //| Copyright 2017, Forex related to FX trading. | //| http://fxtrading.greeds.net | //+------------------------------------------------------------------+ #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 2 #property indicator_plots 2 #property indicator_label1 "CrossUP" #property indicator_type1 DRAW_ARROW #property indicator_color1 LightCyan #property indicator_width1 4 #property indicator_label2 "CorssDn" #property indicator_type2 DRAW_ARROW #property indicator_color2 LightPink #property indicator_width2 4 double CrossUpArrow[]; double CrossDnArrow[]; int FastMaHandle; int SlowMaHandle; input int FastPeriod=10; input int SlowPeriod=20; input int shift=0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { FastMaHandle = iMA(NULL,0,FastPeriod,shift,MODE_EMA,PRICE_CLOSE); SlowMaHandle = iMA(NULL,0,SlowPeriod,shift,MODE_EMA,PRICE_CLOSE); SetIndexBuffer(0,CrossUpArrow,INDICATOR_DATA); SetIndexBuffer(1,CrossDnArrow,INDICATOR_DATA); PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,0); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,0); PlotIndexSetInteger(0,PLOT_ARROW,233); PlotIndexSetInteger(1,PLOT_ARROW,234); PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0); ArraySetAsSeries(CrossUpArrow,true); ArraySetAsSeries(CrossDnArrow,true); IndicatorSetInteger(INDICATOR_DIGITS,_Digits); 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(FastMaHandle)<rates_total) return(0); if(BarsCalculated(SlowMaHandle)<rates_total) return(0); int limit,to_copy; if(prev_calculated>rates_total || prev_calculated<=0) to_copy=rates_total; else { to_copy=rates_total-prev_calculated; to_copy++; } double FastMA[],SlowMA[]; if(CopyBuffer(FastMaHandle,0,0,to_copy,FastMA)<=0) return(0); if(CopyBuffer(SlowMaHandle,0,0,to_copy,SlowMA)<=0) return(0); ArraySetAsSeries(open,true); ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); ArraySetAsSeries(close,true); ArraySetAsSeries(FastMA,true); ArraySetAsSeries(SlowMA,true); if(prev_calculated>rates_total || prev_calculated<=0) { limit=rates_total; } else { limit=rates_total-prev_calculated; } for(int i=0;i<limit;i++) { if(FastMA[i]>SlowMA[i]&&FastMA[i+1]<SlowMA[i+1]) CrossUpArrow[i]=low[i]; if(FastMA[i]<SlowMA[i]&&FastMA[i+1]>SlowMA[i+1]) CrossDnArrow[i]=close[i]; } return(rates_total); }