Download MetaTrader 5

help in Modifying Triangular Moving Average Code

To add comments, please log in or register
naresh_2011
13
naresh_2011  

Dear Friends, I like very much using Triangular Moving Average code developed by Mladen. given as under

//+------------------------------------------------------------------+

//|                                                  TriangularMAmq4 |

//+------------------------------------------------------------------+

#property copyright "mladen"

#property link      "www.forex-tsd.com"

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_color1  PaleVioletRed

#property indicator_width1  2


extern int Length = 12;

extern int Price  = PRICE_CLOSE;

extern int Shift  = 0;


double buffer1[];


int init()

{

   SetIndexBuffer(0,buffer1); SetIndexShift(0,Shift);

   return(0);

}

int deinit() { return(0); }



//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+


int start()

{

   int counted_bars=IndicatorCounted();

   if(counted_bars < 0) return(-1);

   if(counted_bars > 0) counted_bars--;

         int limit = MathMin(Bars-counted_bars,Bars-1);


  

   //

   

   for (int i=limit; i>=0; i--) buffer1[i] = iTma(iMA(NULL,0,1,0,MODE_SMA,Price,i),Length,i);

   return(0);

}




double workTma[][1];

double iTma(double price, double period, int r, int instanceNo=0)

{

   if (ArrayRange(workTma,0)!= Bars) ArrayResize(workTma,Bars); r=Bars-r-1;

   

   //

      

   workTma[r][instanceNo] = price;


      double half = (period+1.0)/2.0;

      double sum  = price;

      double sumw = 1;


      for(int k=1; k<period && (r-k)>=0; k++)

      {

         double weight = k+1; if (weight > half) weight = period-k;

                sumw  += weight;

                sum   += weight*workTma[r-k][instanceNo];  

      }             

      return(sum/sumw);

}


//-------------------------------------------------------------

I wanted that the TMA line pass over the prices in ascending price slopes and below during descending price slopes. In the present case, it is just opposite to what i want.

I tried to change  the following lines i the code and could get some desirable results but not up to the last candle. 

    {

         double weight = k+1; if (weight > half) weight = period-k;

                sumw  -= weight;

                sum  -= weight*workTma[r+k][instanceNo];  

      }        


can any one help me to resolve the problem in getting the modified TMA line up to last candle.

whroeder1
15913
whroeder1  
naresh_2011:

I like very much using Triangular Moving Average code developed by Mladen.

I wanted that the TMA line pass over the prices in ascending price slopes and below during descending price slopes. In the present case, it is just opposite to what i want.
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it

  2. What you have is not a standard Triangular Moving Average (TMA, or TRIMA) which is a SMA of an SMA. What you have is Triangular Weighted Moving Average (TriW-MA)
  3. double half = (period+1.0)/2.0;
    For a TriWMA this is bogus. The half marks the value with the highest weight. For a 3 period that is index 1, (0, 1, 2.) For a 5 period that is index 2, (0,1, 2, 3,4.) Change to:
    double half = (period-1.0)/2.0;
  4. A MA, any moving average is what it is. It isn't over or under price.
Mladen Rakic
61854
Mladen Rakic  
whroeder1:

  1. Please edit your post.
    For large amounts of code, attach it

  2. What you have is not a standard Triangular Moving Average (TMA, or TRIMA) which is a SMA of an SMA. What you have is Triangular Weighted Moving Average (TriW-MA)
  3. For a TriWMA this is bogus. The half marks the value with the highest weight. For a 3 period that is index 1, (0, 1, 2.) For a 5 period that is index 2, (0,1, 2, 3,4.) Change to:
  4. A MA, any moving average is what it is. It isn't over or under price.

Check the rest of the code and how and where that "half" variable is used. Nothing bogus in it

All the best

Jose Francisco Casado Fernandez
3272
Jose Francisco Casado Fernandez  

You can consider this section: https://www.mql5.com/en/jobFreelance .

Regards.-

Freelance service at MQL5.com
Freelance service at MQL5.com
  • www.mql5.com
Orders for the development of automated trading programs
To add comments, please log in or register