Of course you can integrate an indicator in an EA but not the typical indi. functions (OnCalculate), buffer (#property indicator_buffers 1) etc.
For example you can replace an ema like iMA(...,MODE_EMA,..) by its calculation: ema = (newVal - ema)*c + ema; or the daily high and lows by CopyRates(Symbol(),PERIODE_D1,...);
All this must be part of the body of OnTick() either itself or indirectly by a function call.
What is the difference between EA and Indicator in term of code? I mean without loading a file on MT5, if you receive a MQL5 file, open it and read the code how will you determine if it is an indicator or not?
Most likely, the application type (EA, indicator, or script) is determined depending on the event handling functions used in it:
https://www.mql5.com/en/docs/basis/function/events
Some quotes from the link above:- The OnStart() function is the Start event handler, which is automatically generated only for running scripts.
- OnTick(). The NewTick event is generated for Expert Advisors only when a new tick for a symbol is received, to the chart of which the Expert Advisor is attached. It's useless to define the OnTick() function in a custom indicator or script, because the NewTick event is not generated for them.
- The OnCalculate() function is called only in custom indicators when it's necessary to calculate the indicator values by the Calculate event.
Handle_X
i will go directly for the indicator name
Double X;
and in the OnInit Function
int OnInit() { X=(...............); return(INIT_SUCCEEDED); }
Most likely, the application type (EA, indicator, or script) is determined depending on the event handling functions used in it:
https://www.mql5.com/en/docs/basis/function/events
Some quotes from the link above:- The OnStart() function is the Start event handler, which is automatically generated only for running scripts.
- The NewTick event is generated for Expert Advisors only when a new tick for a symbol is received, to the chart of which the Expert Advisor is attached. It's useless to define the OnTick() function in a custom indicator or script, because the NewTick event is not generated for them.
- The OnCalculate() function is called only in custom indicators when it's necessary to calculate the indicator values by the Calculate event.
then, if an indicator depend on the OnCalculate() function, what is his alternative in ea
then, if an indicator depend on the OnCalculate() function, what is his alternative in ea
The best way is to emulate indicator buffers in an EA. I will not try to explain this to you here, as this is too broad a topic, with its own nuances. Perhaps someone else will do it.
The second way is to include the indicator as a resource. Regarding this, I can’t explain anything to you in more detail too because I have never tried to do this (I have always emulated buffers).
But before selling such an adviser, in any case, you should make sure that you do not violate the copyrights of the indicator
You mean the correct line will be instead of using a
i will go directly for the indicator name
and in the OnInit Function
If you calculate the indicator values with in an EA do it like that (not tested, there is no need to request a handle of iMA() - calculate the value instead):
input int PerEMA = 14; double cPerEma; ... int OnInit() { ... cPerEma = 2.0/(PerEMA+1); ... } void OnTick() { ... MqlRates bars[]; static double ema = 0.0; if (isNewBar(_Period) ) { CopyRates(_Symbol,_Period,TimeCurrent(),2,bars) ema = (bars[1].close - ema)*cPerEma + ema; } ... }This ema needs a couple of bars to get close to is real value - instead you can calculate the history...
i see thanks a lot
Exponential requires 3.45×(Length+1) bars to converge to 1/10 percent. (EMA Period 5 requires 21 initial bars.)
Moving average - Wikipedia
input int PerEMA = 14; ⋮ ema = (bars[1].close - ema)*cPerEma + ema;
The 14 period EMA requires 52 bars. Use the iMA indicator, or calculate it properly.
Exponential requires 3.45×(Length+1) bars to converge to 1/10 percent. (EMA Period 5 requires 21 initial bars.)
Moving average - Wikipedia
The 14 period EMA requires 52 bars. Use the iMA indicator, or calculate it properly.
![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 everyone
I have two question about MQL5 :
1- Is there any alternative to the function iCustom ? : I'm asking if there is a way to directly write an indicator Code/Logic into the ea and deleting his dependancie tp external file. Moving Average comes by default on all plateforms, however if the ea is using a custom indicater, the iCustom require the indicator to be in the right folder and have the right name. for a better understanding, some may know what i'm talking about but seing this line of cod with a random indicator name "X"
ex: If you sell a product on the market place that depend on another indicator, not every customer will understand the need/why and how to download the specific indicator to the right folder (\\Indicator\\market...) that also applied if you are selling outside mql5 market place.
Now what i want to know: is it possible to inclute an indicator directly to an ea by directly including the code into the ea?.
2- All my attemps to write an indicator code into an ea failed, everytime i do so, MT5 recognise my ea as an indicator. In another word, when i try to include an indicator into the ea without the iCustom function, my ea get automatically converted to an indicator. this brings me to my second question
What is the difference between EA and Indicator in term of code? I mean without loading a file on MT5, if you receive a MQL5 file, open it and read the code how will you determine if it is an indicator or not?
Thanks