Convert TEMA to Tema(close,period)

 

Hi

I would like to convert my Tema function to function like TEMA(CLOSE,PERIOD)

I have problem with variable Tema[i], How can i return this variable from funtion ?


My code :

int n=4, Av=6;
double var1;

int i,limit;
//---- buffers
double Ema[];
double EmaOfEma[];
double EmaOfEmaOfEma[];
double Tema[];
int init()
  {
  
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexStyle(5,DRAW_LINE);
   SetIndexDrawBegin(0,EMA_Period);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);

//---- 3 indicator buffers mapping
   if(!SetIndexBuffer(0,Ema) &&
      !SetIndexBuffer(1,EmaOfEma) &&
      !SetIndexBuffer(2,EmaOfEmaOfEma) &&
      !SetIndexBuffer(3,Tema) &&
      !SetIndexBuffer(4,var1) &&
      !SetIndexBuffer(5,var5))
      Print("cannot set indicator buffers!");
//   if(!SetIndexBuffer(0,Tema) )
//      Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("TEMA("+EMA_Period+")");
//---- initialization done
   return(0);
  }

int start()
{
   int i, limit;
   int    counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
  

var= Tema(0,6);                                                        // here i want to run function 
 Print(var);                                                           //    but in var variable is some big value
 
      return(0);
  }


double Tema(int cena,int okres) 
{
 for(i = limit; i >=0; i--)
       {
       Ema[i] = iMA(NULL,0,okres,0,MODE_EMA,cena,i);
     //  Print(Ema[i]);
      }
 for(i = limit; i >=0; i--)
       {
       EmaOfEma[i] = iMAOnArray(Ema,Bars,okres,0,MODE_EMA,i);
     // Print( EmaOfEma[i]);
    }
 for(i = limit; i >=0; i--)
       EmaOfEmaOfEma[i] = iMAOnArray(EmaOfEma,Bars,okres,0,MODE_EMA,i);
         
  
 for(i = limit; i >=0; i--)
    {  
    Tema[i] = 3 * Ema[i] - 3 * EmaOfEma[i] + EmaOfEmaOfEma[i];
      // Print(Tema[i]);
     }  
return(Tema);                                                                 // is it correct ??

 
lukibest:

Hi

I would like to convert my Tema function to function like TEMA(CLOSE,PERIOD)

I have problem with variable Tema[i], How can i return this variable from funtion ?


My code :

Pass the array to the function by reference . . . or just use a globally declared array
 
RaptorUK:
Pass the array to the function by reference

Can you show me some examples
 
lukibest:

Can you show me some examples

Do you know of Google ? it's a search engine, very good . . . .

Try this

If you only need the Function to ever work on one array just make the array global . . .

Just looked at your code, Tema[] is a buffer so is already a Global . . you don't need to return anything . . .

 
Your Tema function is very inefficient, why not make those 4 loops into one and do everything in one loop ?
Reason: