Hello, I just realized that it seems to be possible to access a struct element using its string value:
Is this a bug or on purpose?
This is interesting. MQL5 having JS like feature. Maybe it is a new update?
@Carl Schreiber: I came across this behaviour because of another issue I tried to solve. I have a struct which conatins several information such as open price, different stop losses, open times, closing times etc. I wanted to find the lowest and second lowest stop loss within the struct. Since ArraySort is not applicable to structs I tried the following:
SL[0,0] = tradeInfo[0].SL_1; SL[1,0] = tradeInfo[0].SL_2; SL[2,0] = tradeInfo[0].SL_3; SL[3,0] = tradeInfo[0].SL_4; SL[4,0] = tradeInfo[0].SL_5; SL[0,1] = 1; SL[1,1] = 2; SL[2,1] = 3; SL[3,1] = 4; SL[4,1] = 5; ArraySort(SL);
which returns:
Next, I would like to move the lowest stop loss, which is 2, to the value of 5 thus to the value of 90.98.
Now, my issue appears because I do not know how to bring this information back into my struct. There are so many combinations that I need to nest so many if statements and that sounds really wrong to me ;-)
So my intention was to concatenate the second column of the array (number of the SL) with "SL_"+(string)SL[0,1] to get "SL 2" and use this again to alter the value from the struct using
string sl="SL_"+(string)SL[0,1]; LongPos[0]."sl" = 90.98;
I have not yet tested it if it works but this brought to my question raised above ;-)
I have not yet tested it if it works but this brought to my question raised above ;-)
I think the issue is that you have a fundamental code logic/design problem. You should rethink how you want to structure your data and/or methods of handling it in a more organised and efficient manner.
Hello, I just realized that it seems to be possible to access a struct element using its string value:
Is this a bug or on purpose?
Thank you for message.
This is a bug.
Fixed.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, I just realized that it seems to be possible to access a struct element using its string value:
Is this a bug or on purpose?