Hi,
...
Structs: https://www.mql5.com/en/docs/basis/types/classes
But first you have to find a unified presentation of all of your indicator parameters.
![Documentation on MQL5: Language Basics / Data Types / Structures, Classes and Interfaces Documentation on MQL5: Language Basics / Data Types / Structures, Classes and Interfaces](https://c.mql5.com/36/53/documentation-on-mql5-language__1.png)
- www.mql5.com
Thanks, perhaps I do not get your point. Is what your wrote not just a repetition of my question as a task which I'm not able to find out.
But at least I have found out that I can use double as datatype for int parameters. And as far as I can see, my indicators are only using uint, int and double. So probably I just need double as baseclass for parameters ...
One indicator is using a string input, but I have the source code and can modify that indicator and remove that string input.
This is not really a nice solution but for testing good enough. I'll give it a try.
Regards
Daniel
I solved it this way:
struct IndicatorParam { double vals[]; }; struct IndicatorDescriptor { string path; int bufferIndexValue; int bufferIndexSignal; int paramsSetCount; IndicatorParam parameters[4]; }; void initIndicatorMetadata() { ... imd_setMD(IMD_FISHER_TRANSFORM, "crossing/Ehlers Fisher transform (original)", 0, 1); imd_setMD(IMD_ATR_RATIO, "Volume/atrratio", 0, -1); imd_addPs(IMD_ATR_RATIO, 0, 7, 4, 10); // set metadata as initialized metadata_initialized = true; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void imd_addPs(int indicatorIdx, int paramNo, double val1, double val2=IMD_INVALID_PARAM, double val3=IMD_INVALID_PARAM) { imd_addP(indicatorIdx, paramNo, val1); if(val2 > IMD_INVALID_PARAM) { imd_addP(indicatorIdx, paramNo, val2); } if(val3 > IMD_INVALID_PARAM) { imd_addP(indicatorIdx, paramNo, val3); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void imd_addP(int indicatorIdx, int paramNo, double val) { int siz = ArraySize(metadata_indicators[indicatorIdx].parameters[paramNo].vals); ArrayResize(metadata_indicators[indicatorIdx].parameters[paramNo].vals, siz+1); metadata_indicators[indicatorIdx].parameters[paramNo].vals[siz] = val; if(metadata_indicators[indicatorIdx].paramsSetCount <= paramNo) { metadata_indicators[indicatorIdx].paramsSetCount = paramNo + 1; } }
You can use MqlParam for this.
int IndicatorInit(int indicatorIdx, MqlParam &pars[]) { switch(indicatorIdx) { case IMD_FISHER_TRANSFORM: return iCustom(NULL, PERIOD_CURRENT, imd_getPath(indicatorIdx), pars[0].integer_value, pars[1].double_value); ...
For documentation about MqlParam see the MQL5 reference. See also the IndicatorCreate() function with generic parameters.
![Documentation on MQL5: Timeseries and Indicators Access / IndicatorCreate Documentation on MQL5: Timeseries and Indicators Access / IndicatorCreate](https://c.mql5.com/36/53/documentation-on-mql5-timeseries__4.png)
- www.mql5.com
Yes, thats how I do it currently. With 30 indicators you have a lot of redundant code because you need to add each new indicator into the switch case.
Now I have a generic mechanism with any need to extend that code, except I need more than 5 parameters
//+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int initIndicator(int indicatorIdx, int param1=0, int param2=0, int param3=0, int param4=0, int param5=0) { int handle = INVALID_HANDLE; int valueIdxArr[] = {param1,param2, param3, param4, param5}; initIndicatorMetadata(); if(indicatorIdx == IMD_NONE) { return INVALID_HANDLE; } switch(metadata_indicators[indicatorIdx].paramsSetCount) { case 0: handle = iCustom(NULL, PERIOD_CURRENT, metadata_indicators[indicatorIdx].path); case 1: handle = iCustom(NULL, PERIOD_CURRENT, metadata_indicators[indicatorIdx].path, imd_getP(indicatorIdx, 0, valueIdxArr)); case 2: handle = iCustom(NULL, PERIOD_CURRENT, metadata_indicators[indicatorIdx].path, imd_getP(indicatorIdx, 0, valueIdxArr), imd_getP(indicatorIdx, 1, valueIdxArr)); case 3: handle = iCustom(NULL, PERIOD_CURRENT, metadata_indicators[indicatorIdx].path, imd_getP(indicatorIdx, 0, valueIdxArr), imd_getP(indicatorIdx, 1, valueIdxArr), imd_getP(indicatorIdx, 2, valueIdxArr)); case 4: handle = iCustom(NULL, PERIOD_CURRENT, metadata_indicators[indicatorIdx].path, imd_getP(indicatorIdx, 0, valueIdxArr), imd_getP(indicatorIdx, 1, valueIdxArr), imd_getP(indicatorIdx, 2, valueIdxArr), imd_getP(indicatorIdx, 3, valueIdxArr)); case 5: handle = iCustom(NULL, PERIOD_CURRENT, metadata_indicators[indicatorIdx].path, imd_getP(indicatorIdx, 0, valueIdxArr), imd_getP(indicatorIdx, 1, valueIdxArr), imd_getP(indicatorIdx, 2, valueIdxArr), imd_getP(indicatorIdx, 3, valueIdxArr), imd_getP(indicatorIdx, 4, valueIdxArr)); } return handle; }
Yes, thats how I do it currently. With 30 indicators you have a lot of redundant code because you need to add each new indicator into the switch case.
Now I have a generic mechanism with any need to extend that code, except I need more than 5 parameters
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I'm writing an EA for testing combinations of different indicators.
For that I want want to have different parameter sets for each indicator.
My problem is that the code is getting a bit redundant I would like to initialize the indicators based on the metadata.
Parameters shal be stored in an structure (see code: ?? parameterSet1[];) including the possible parameters and on initialization (see code initIndicator()) I want to take the data from there.
For only the path that way is working, but I need some help with the ... in iCustom.
here is the code:
Which datatype can I use to store int, double, bool, enums and string which are the parameters fo different indicator?
Thanks for any hint
Regards
Daniel