If I have an indicator ( myIndi
) which generates a variable ( Var1
), how can I access the Var1
from an EA, please?
I've tried iCustom()
but not getting the results.
If I have an indicator ( myIndi
) which generates a variable ( Var1
), how can I access the Var1
from an EA, please?
I've tried iCustom()
but not getting the results.
iCustom()
is a primary interface between EA and Custom IndicatorsThere is no reason, why would a call to iCustom()
not return a value, given the myIndi
compilation was successful and the constructed Custom Indicator is principally correct in its internal workings ( do not hesistate to post the MCVE-code example to prove or dis-prove this ).
Next step:
publish an update of your post, to include an MCVE-code so as to review the root-cause of the actual state of such call:
retVal = iCustom( _Symbol, PERIOD_CURRENT, "myIndi",
<p1>,
<p2>,
...,
<id#>,
<shift>
);
The following method is robust for both EA-side and Indicator-side teams to smoothly and safely share evolving ideas and for maintaining all the versions of iCustom()
EA-side call-interface clean and safe plus creating the calling-interface a way more readable ( with #define
-ed human-readable names for meaningful and coherent line#-identifications ).
These sections are maintained by the Custom Indicator developers, during the whole life-cycle of a Custom Indicator and EA-teams just #include
these as a self-explanatory template once any version is being used inside EA.
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! <<_MAINTAINED_SECTION_>>.START
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!! -------------------------------------------||||||||||||||||||||||||||||||||||||||||||| POSITIONAL ORDINAL-NUMBERED CALLING INTERFACE ||||||||||||||||||||| all iCustom() call MUST BE REVISED ____________________________ !!!
//--- indicator parameters -------------------------------------------||||||||||||||||||||||||||||||||||||||||||| POSITIONAL ORDINAL-NUMBERED CALLING INTERFACE ||||||||||||||||||||| all iCustom() call MUST BE REVISED ____________________________ !!!
//!!! -------------------------------------------||||||||||||||||||||||||||||||||||||||||||| POSITIONAL ORDINAL-NUMBERED CALLING INTERFACE ||||||||||||||||||||| all iCustom() call MUST BE REVISED ____________________________ !!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#define XYZ_CUSTOM_INDICATOR_NAME "an_XYZ_<fileName_w/o_.MQ4>" // the Custom Indicator fileName
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//--- input parameters -------------------------------------------------------- iCustom( ) CALL INTERFACE
input int nBARs_period = 18;
extern double MUL_SIGMA = 0;
sinput ENUM_APPLIED_PRICE aPriceTYPE = PRICE_CLOSE;
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/* = iCustom( _Symbol, PERIOD_CURRENT, XYZ_CUSTOM_INDICATOR_NAME, // |-> iCustom INDICATOR NAME
XYZ_nBARs_period, // |-> input1 nBARs_period
XYZ_MUL_SIGMA, // |-> input2 MUL_SIGMA
XYZ_PRICE_TYPE, // |-> input3 aPriceTYPE from: ENUM_APPLIED_PRICE
XYZ_<_VALUE_>_BUFFER_ID, // |-> line# --------------------------------------------from: { 0: Val1 == Buffer0[] | 1: Buffer1[] | ... }
aShift // |-> [aShift]-aTimeDOMAIN-offset of a Val1[] to return
); //
*/
#define XYZ_Val1_BUFFER_ID 0 // <---- <Val1>[]
#define XYZ_Val2_BUFFER_ID 1
#define XYZ_Val3_BUFFER_ID 2
#define XYZ_Val4_BUFFER_ID 3
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!! -------------------------------------------||||||||||||||||||||||||||||||||||||||||||| POSITIONAL ORDINAL-NUMBERED CALLING INTERFACE ||||||||||||||||||||| all iCustom() call MUST BE REVISED ____________________________ !!!
//--- indicator parameters -------------------------------------------||||||||||||||||||||||||||||||||||||||||||| POSITIONAL ORDINAL-NUMBERED CALLING INTERFACE ||||||||||||||||||||| all iCustom() call MUST BE REVISED ____________________________ !!!
//!!! -------------------------------------------||||||||||||||||||||||||||||||||||||||||||| POSITIONAL ORDINAL-NUMBERED CALLING INTERFACE ||||||||||||||||||||| all iCustom() call MUST BE REVISED ____________________________ !!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! <<_MAINTAINED_SECTION_>>.END
Any other approaches were historically proven to be more painfull or more risky.
Using GlobalVariable*
call(s) is not a robust use-case for this problem-domain, as many side-effects are to be expected and such code-value-integration is prone to stop working without EA-being able to detect such ( semantic ) failure.
Using a Custom Indicator logic "inside" EA is possible, but at a cost of a complete re-design of the logic, as EA code-execution unit behaves way different from the Custom Indicator code-execution unit in the MetaTrader4 Terminal code-execution environment. It is fair to note, that due to MQL4-language-( and Terminal )-revisions, it makes sense just for an HFT-grade Project, or for extremely latency-sensitive implementations to carefully decide cons and pros before going into this direction.
There are two ways:
- let this variable be a buffer and access that buffer and position through iCustom();
- write such variable as GlobalVariablesOfClientTerminal and read it as GV.
Also possible to move the indicator's logic inside the EA, in such case you will be able to access that parameter directly, but that is usually not so easy.
use global variables to transfer the var values between EAs and indicators.