Is it possible to read changes in pre-built indicator (for example: its value changes) through an expert-advisor, and of course - automate the trades based on those reads?
What is the function that is responsible for doing this?
I have tried to look this up on Google, but it appears I can only do things like track object creation or deletion ... called Chart Events.... maybe I'm missing something?
Yes, it is possible.
MetaTrader4 Terminal is a software platform, that allows you to launch
1x
soloist Expert Advisor - as an event-driven code-execution algorith per each MT4.Graph
Nx
concurrent Custom Indicator-s event-driven restricted code-base per each MT4.Graph
1x
soloist Script asynchronous code-execution unit per each MT4.Graph
This inventory is important, as you have no other means how to automate complex Trading Algorithmisation but this.
Technical Indicators are executed under one common thread, which poses limitations for real-time robustness plus some restrictions apply for the permitted / forbidden operations that might be coded / compiled / executed in Indicator ( all aim at avoiding any and all possible blocking situations ( ref. solo-thread for all ... ) )
This said, you might have noticed, that both Expert Advisor
and Technical Indicator
-s are externally synchronised ( forget for the moment about non-parallel, shared thread execution with principal nanosecond scale of asynchronicity due to resource / code-execution scheduling ) and bound to externally issued anFxMarketEVENT
in a form of an arriving signal ( once a price moves, MT4.Server
sends QUOTE
downstream message to the MT4.Terminal
, a.k.a. a Tick ), which once ( if ) received, triggers MQL4
code-execution facilities on localhost
:
OnTick(){ ...}
# in case of Expert Advisor
OnCalculate(){...}
# in case of Custom Technical Indicator
What is the function that is responsible for this?
Directly? None.
Indirectly? The one you construct and make responsible for registering / monitoring the changes of such value ( be it internally in MQL4
domain or externally via distributed processing model, incl. GPU
-cluster one for more demanding processing, where internal shared-thread execution fails to meet the timing constraints ):
bool hasAnIndicatorChanged( double aTol = 0.00001 ){ // DERIVATION
static double prevVALUE = EMPTY_VALUE; // .DEF
double aNewVALUE = iBWMFI( _Symbol, // .SYM
PERIOD_CURRENT, // .PERIOD
0 // .HOT[0]
); // .STO "current"
if ( MathAbs( aNewVALUE - prevVALUE ) <= aTol ){
prevVALUE = aNewVALUE;
return( False ); // JIT/RET --> --> --> --> --> non-MISRA-C JIT/RET
}
else {
prevVALUE = aNewVALUE;
return( True ); // JIT/RET --> --> --> --> --> non-MISRA-C JIT/RET
}
}
Can do principle
One may create a similarly trivial or a bit more complex PID-monitor and ask from Expert Advisor
each time an OnTick()
is being called ( thus align the code execution with the internal event-handler at no additional cost ).
void OnTick(){
if ( hasAnIndicatorChanged() ){
...
}
...
}
Ok I found it.
In order to use a custom indicator as a tool for a buy / trade decision inside an expert advisor, the function is iCustom()