Example:
//+------------------------------------------------------------------+ //| iIchimoku Get Value.mq5 | //| Copyright 2021, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2021, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" //--- input parameters input group "Ichimoku" input int Inp_Ichimoku_tenkan_sen = 9; // Ichimoku: period of Tenkan-sen input int Inp_Ichimoku_kijun_sen = 26; // Ichimoku: period of Kijun-sen input int Inp_Ichimoku_senkou_span_b = 52; // Ichimoku: period of Senkou Span B input group "Additional features" input bool InpPrintLog = false; // Print log //--- int handle_iIchimoku; // variable for storing the handle of the iIchimoku indicator //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { handle_iIchimoku=INVALID_HANDLE; //--- create handle of the indicator iIchimoku handle_iIchimoku=iIchimoku(Symbol(),Period(),Inp_Ichimoku_tenkan_sen, Inp_Ichimoku_kijun_sen,Inp_Ichimoku_senkou_span_b); //--- if the handle is not created if(handle_iIchimoku==INVALID_HANDLE) { //--- tell about the failure and output the error code PrintFormat("Failed to create handle of the iIchimoku indicator for the symbol %s/%s, error code %d", Symbol(), EnumToString(Period()), GetLastError()); //--- the indicator is stopped early return(INIT_FAILED); } ////--- //// ResetLastError(); //// if(!ChartIndicatorAdd(ChartID(),0,handle_iIchimoku)) //// { //// --- tell about the failure and output the error code //// PrintFormat("Failed to ChartIndicatorAdd, error code %d",GetLastError()); //// --- the indicator is stopped early //// return(INIT_FAILED); //// } //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- if(handle_iIchimoku!=INVALID_HANDLE) IndicatorRelease(handle_iIchimoku); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- double span_a[],span_b[]; ArraySetAsSeries(span_a,true); ArraySetAsSeries(span_b,true); int start_pos=0,count=3; if(!iGetArray(handle_iIchimoku,SENKOUSPANA_LINE,start_pos,count,span_a) || !iGetArray(handle_iIchimoku,SENKOUSPANB_LINE,start_pos,count,span_b)) return; //--- string text=""; for(int i=0; i<count; i++) { text=text+ " bar #"+IntegerToString(i)+": "+ " span_a "+DoubleToString(span_a[i],Digits()+1)+" span_b "+DoubleToString(span_b[i],Digits()+1)+"\n"; } Comment(text); } //+------------------------------------------------------------------+ //| Get value of buffers | //+------------------------------------------------------------------+ bool iGetArray(const int handle,const int buffer,const int start_pos, const int count,double &arr_buffer[]) { bool result=true; if(!ArrayIsDynamic(arr_buffer)) { PrintFormat("ERROR! EA: %s, FUNCTION: %s, this a no dynamic array!",__FILE__,__FUNCTION__); return(false); } ArrayFree(arr_buffer); //--- reset error code ResetLastError(); //--- fill a part of the iBands array with values from the indicator buffer int copied=CopyBuffer(handle,buffer,start_pos,count,arr_buffer); if(copied!=count) { //--- if the copying fails, tell the error code PrintFormat("ERROR! EA: %s, FUNCTION: %s, amount to copy: %d, copied: %d, error code %d", __FILE__,__FUNCTION__,count,copied,GetLastError()); //--- quit with zero result - it means that the indicator is considered as not calculated return(false); } return(result); } //+------------------------------------------------------------------+
Result:
Files:

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi
I am using iIchimoku indicator to write an expert and I need to know the values of spanA and spanB but I can only access the current candle values but what I need is the ahead of time values.
Can anybody help me with this?