Nesting of MA and TEMA

 

Nesting of MQL5 handles as iMA and iTEMA is not possible. I would need the Triple Exponential Moving Average of a Moving Average e.g.:

      int PRICE_GD_OPEN = iMA(_Symbol,PERIOD_CURRENT,10,0,MODE_SMA,PRICE_OPEN);
      double GD = iTEMA(_Symbol, PERIOD_CURRENT,4,0, PRICE_GD_OPEN);

How can I realize this?

Moving Average - Trend Indicators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
Moving Average - Trend Indicators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
  • www.metatrader5.com
The Moving Average Technical Indicator shows the mean instrument price value for a certain period of time. When one calculates the moving average...
 
int PRICE_GD_OPEN = iMA(_Symbol, PERIOD_CURRENT, 10, 0, MODE_SMA, PRICE_OPEN);
int GD = iTEMA(_Symbol, PERIOD_CURRENT, 4, 0, PRICE_GD_OPEN);
:
:
CopyBuffer(GD, 0, 0, rates_total, TEMA_Buffer);
 

Thank you. Still I do not know how to make it run.

int PRICE_GD_OPEN = iMA(_Symbol, PERIOD_CURRENT, 10, 0, MODE_SMA, PRICE_OPEN);
int GD = iTEMA(_Symbol, PERIOD_CURRENT, 4, 0, PRICE_GD_OPEN);


Both are handles. But

PRICE_GD_OPEN

in the iTEMA handle function as the last value should be entered as double value. But this double value is available only after CopyBuffer in OnTick and not yet in OnInit operation.

Entering

CopyBuffer(GD, 0, 0, rates_total, TEMA_Buffer);
adapted as
CopyBuffer(GD_handle, 0, 0, 100, GD);


only shows errors:


http://michaelneubert.net/error.jpg

I feel unable to bring the routines in a right order:


double  GD[];  
int     GD_handle;          // handle of the indicator iTEMA

double  PRICE_GD_OPEN[];  
int     PRICE_GD_OPEN_handle;          // handle of the indicator iMA

int OnInit
{
  PRICE_GD_OPEN = iMA(_Symbol, PERIOD_CURRENT, 10, 0, MODE_SMA, PRICE_OPEN);
  GD_handle = iTEMA(_Symbol, PERIOD_CURRENT, 4, 0, PRICE_GD_OPEN[]);
}
  
void OnTick()
  { 


   CopyBuffer(GD_handle, 0, 0, 100,GD);
   
   CopyBuffer(PRICE_GD_OPEN_handle,0,0,100,PRICE_GD_OPEN);
   ArraySetAsSeries(PRICE_GD_OPEN,true); 


Can you help please?

 
riofenix #:

Both are handles. But

in the iTEMA handle function as the last value should be entered as double value. But this double value is available only after CopyBuffer in OnTick and not yet in OnInit operation.

iTEMA

The function returns the handle of the Triple Exponential Moving Average indicator. It has only one buffer.

int  iTEMA(
   string                          symbol,               // symbol name
   ENUM_TIMEFRAMES      period,               // period
   int                              ma_period,         // averaging period
   int                              ma_shift,            // horizontal shift of indicator
   ENUM_APPLIED_PRICE  applied_price     // type of price or handle
   );

applied_price

[in]  The price used. Can be any of the price constants ENUM_APPLIED_PRICE or a handle of another indicator.


What double value are you talking about?

The applied price or another indicator handle value will be entered here.

double  GD[];  
int     GD_handle;          // handle of the indicator iTEMA

//double  PRICE_GD_OPEN[];  
int     PRICE_GD_OPEN_handle;          // handle of the indicator iMA

int OnInit
{
  PRICE_GD_OPEN_handle = iMA(_Symbol, PERIOD_CURRENT, 10, 0, MODE_SMA, PRICE_OPEN);
  GD_handle = iTEMA(_Symbol, PERIOD_CURRENT, 4, 0, PRICE_GD_OPEN_handle);
}
  
void OnTick()
  { 


   CopyBuffer(GD_handle, 0, 0, 100, GD);
   
   //CopyBuffer(PRICE_GD_OPEN_handle,0,0,100,PRICE_GD_OPEN);
   //ArraySetAsSeries(PRICE_GD_OPEN,true); 
Documentation on MQL5: Language Basics / Data Types / Void Type and NULL Constant
Documentation on MQL5: Language Basics / Data Types / Void Type and NULL Constant
  • www.mql5.com
Void Type and NULL Constant - Data Types - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Thank you so much, I have been not aware about your outpointed details. It runs smoothly changing

int OnInit

to
void OnInit()
What does this change (substantially) ? I am not aware of the difference.
 
riofenix #:

Thank you so much, I have been not aware about your outpointed details. It runs smoothly changing

to What does this change (substantially) ? I am not aware of the difference.

I also had copied the whole thing without realizing this.

Without the parentheses, it would not be recognized as a function and should result in an error.