naresh_2011:
I like very much using Triangular Moving Average code developed by Mladen.
-
Play videoPlease edit your post.
For large amounts of code, attach it - 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)
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;
- A MA, any moving average is what it is. It isn't over or under price.
whroeder1:
-
Please edit your post.
For large amounts of code, attach it - 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)
- 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:
- 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

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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.