MQL5 return and fetch a struct result from function

MQL5 return and fetch a struct result from function

Manage alerts

Loading saved threads...

relo80 · External communityPost link
External question — Stack Overflow Stack Exchange Author: relo80 Original post: https://stackoverflow.com/questions/69598867 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I do my first steps in MQL5. I tried to use a function, which should return a struct object (like an array with multiple datatypes of variables). At the end I want to work with this result. So let me show what I mean. my_function(){ struct resultdata { string name; double price; int qty; }; MyData arr[] = { {"product 1", 110.000, 200}, {"product 2", 110.100, 300}, {"product 3", 110.200, 400}, }; } my_function_feedback=my_function(); Print("First is",my_function_feedback[0].name); This way won't work. What did I do wrong or how can I do this?
Quote
Report
Andrew Allaire · External communityPost link
External answer — Stack Overflow Stack Exchange Author: Andrew Allaire Original post: https://stackoverflow.com/a/72580974 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Sadly, I don't think it is possible to get an mql5 function to return a struct. The closest thing I have figured out how to do is to pass an argument address in the arguments of the function. For example: struct Candle { double open; double high; double low; double close; }; void loadCandle(Candle &candle) { candle.open = 12.0; candle.high = 12.0; candle.low = 12.0; candle.close = 12.0; } To use this function you supply a structure argument and the structure is changed by the function: Candle c; loadCandle(c); I know its not quite the same, but its the closest way that I know about and this question has sat for 7 months with no other answer.
Quote
Report

Post Reply

Checking account access…