Always reference the documentation: https://www.mql5.com/en/docs/indicators/ima
int iMA( string symbol, // symbol name ENUM_TIMEFRAMES period, // period int ma_period, // averaging period int ma_shift, // horizontal shift ENUM_MA_METHOD ma_method, // smoothing type ENUM_APPLIED_PRICE applied_price // type of price or handle );
Example:
HandleEMA = iMA( _Symbol, _Period, PeriodEMA, ShiftEMA, MODE_EMA, PRICE_CLOSE );
- www.mql5.com
int shif=-15; int handle1; int OnInit() { return(0); } void OnTick() { //--- handle1=iMA(Symbol(),PERIOD_CURRENT,10,shif,MODE_SMA,PRICE_CLOSE); double myMArray[]; ArraySetAsSeries(myMArray,true); CopyBuffer(handle1,0,0,10,myMArray); Comment(myMArray[0]); } //+------------------------------------------------------------------+
Thanks for the reply. In the verification of the posted code, I have the following different values, both in demo and on the strategy tester. With shift = -15
Thanks for the reply. In the verification of the posted code, I have the following different values, both in demo and on the strategy tester . With shift = -15
You have made a mistake: in the MQL5 language, the indicator handle is CREATED ONCE !!! And this is done in OnInit.
The code is correct, but what I can't find is the crossing of two MAs with shift = 0 and shift = -15, same period.
How can I implement it?
@Vladimir Karputov told you that you are supposed to obtain the handle in the OnInit() event as you originally did, so why did you change it to the OnTick() and claim it is now correct? It is not!
Show your code for the crossing test! How are we supposed to know what you are doing wrong without seeing your implementation?
int shif=3; int handle1; int handle2; int OnInit() { handle1=iMA(Symbol(),PERIOD_CURRENT,10,0,MODE_SMA,PRICE_CLOSE); handle2=iMA(Symbol(),PERIOD_CURRENT,10,shif,MODE_SMA,PRICE_CLOSE); return(0); } void OnTick() { //--- double myMArray1[]; double myMArray2[]; ArraySetAsSeries(myMArray1,true); ArraySetAsSeries(myMArray2,true); CopyBuffer(handle1,0,0,3,myMArray1); CopyBuffer(handle2,0,0,3,myMArray2); string Activatrade=""; if(myMArray1[0]>myMArray2[0]) Activatrade="BUY"; else Activatrade="SELL"; Comment(" MA1 ",myMArray1[0],"\n"," MA2 ",myMArray2[0],"\n"," Activatrade ",Activatrade); } //+------------------------------------------------------------------+
I understood where the error was, it can't work with negative shifts. Thank you
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have created an moving average in an EA.
how can i add:
input int shift=-15; positive or negative ?
I am creating this code (MQL5) to make optimizations faster
Thanks