The values of the target array of CopyBuffer() are always 0
Indicator:
//+------------------------------------------------------------------+ //| Test.mq5 | //| 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 indicator_separate_window #property indicator_buffers 1 #property indicator_plots 1 //--- plot Value #property indicator_label1 "Value" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- input parameters input int Input1=9; //--- indicator buffers double ValueBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,ValueBuffer,INDICATOR_DATA); //--- an empty value PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); //--- 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 limit=prev_calculated-1; if(prev_calculated==0) { for(int i=0; i<rates_total; i++) ValueBuffer[0]=0.0; limit=rates_total; } for(int i=limit; i<rates_total; i++) { ValueBuffer[i]=2.0; ValueBuffer[i-1]=3.0; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
EA:
//+------------------------------------------------------------------+ //| Test.mq5 | //| 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" //--- input parameters input int Input1=9; //--- int handle_iCustom; // variable for storing the handle of the iCustom indicator //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- create handle of the indicator iCustom handle_iCustom=iCustom(Symbol(),Period(),"Test"); //--- if the handle is not created if(handle_iCustom==INVALID_HANDLE) { //--- tell about the failure and output the error code PrintFormat("Failed to create handle of the iCustom indicator for the symbol %s/%s, error code %d", Symbol(), EnumToString(Period()), GetLastError()); //--- the indicator is stopped early return(INIT_FAILED); } //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- double array_test[]; ArraySetAsSeries(array_test,true); int start_pos=0,count=3; int copied=CopyBuffer(handle_iCustom,0,start_pos,count,array_test); if(copied!=count) { //--- if the copying fails, tell the error code PrintFormat("ERROR! EA: amount to copy: %d, copied: %d, error code %d", count,copied,GetLastError()); //--- quit with zero result - it means that the indicator is considered as not calculated return; } //--- for(int i=0; i<count; i++) Print(DoubleToString(array_test[i],0)); //--- } //+------------------------------------------------------------------+
Result:
Vladimir Karputov:
Indicator:
EA:
Result:
Ah, I can now see that my fault was that I'm assigning the first value in the indicator buffer instead of the second from last;
I've changed
staticInfo[0] = 2;
to
staticInfo[rates_total - 1] = 2;
in my code(for testing purposes) and it works!
Thank you very much!

Hi everyone.
I've really tried to solve this myself but after 3 full days I don't think I will.
I just want to pass a single variable to an EA and I can't even do it with these simple scripts
Indicator "DELETEind" :
EA "DELETEea" :
Am I missing something obvious because I've spent too much time staring at the code??
When I print GetLastError() without any code(no variables, no operations, no nothing) I get the error 5039(Amount of parameters more than the format specifiers) but only from the second execution of OnTick() and later.
Since there was no code I'm guessing it's a false positive?
Any suggestion would be helpful, thank you.