Here is the source code of v1.0 which sadly redraws in history, the version 1.2 attached in the above post does not do that, thats why I would have liked to use it.
Maybe the code of v1.0 is enough to figure out how to detect the different colors.
//| TriangularMA centered.mq4 |
//| mladen |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DeepSkyBlue
#property indicator_color2 OrangeRed
#property indicator_color3 DimGray
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 1
//
//
//
//
//
extern int FastHalfLength = 50;
extern int SlowHalfLength = 100;
extern int Price = PRICE_CLOSE;
//
//
//
//
//
double ExtMapBuffer[];
double Uptrend[];
double Dntrend[];
double buffer2[];
double buffer3[];
double buffer4[];
double pricesArray[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
int init()
{
FastHalfLength=MathMax(FastHalfLength,1);
SlowHalfLength=MathMax(SlowHalfLength,1);
IndicatorBuffers(7);
SetIndexBuffer(0,Uptrend); SetIndexDrawBegin(0,SlowHalfLength);
SetIndexBuffer(1,Dntrend); SetIndexDrawBegin(1,SlowHalfLength);
SetIndexBuffer(2,buffer2);
SetIndexBuffer(3,ExtMapBuffer);
ArraySetAsSeries(ExtMapBuffer, true);
SetIndexBuffer(4,buffer3);
SetIndexBuffer(5,buffer4);
SetIndexBuffer(6,pricesArray);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID);
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID);
return(0);
}
int deinit() { return(0); }
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int start()
{
double sum,sumw;
int counted_bars=IndicatorCounted();
int i,j,k,limit;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=MathMin(Bars-counted_bars,Bars-1);
limit=MathMax(limit,FastHalfLength);
limit=MathMax(limit,SlowHalfLength);
double trend[];
ArrayResize(trend, limit);
ArraySetAsSeries(trend, true);
//
//
//
//
//
for (i=limit;i>=0;i--) pricesArray[i] = iMA(NULL,0,1,0,MODE_SMA,Price,i);
for (i=limit;i>=0;i--)
{
buffer3[i] = calculateTma(pricesArray,FastHalfLength,i);
buffer4[i] = calculateTma(pricesArray,SlowHalfLength,i);
ExtMapBuffer[i] = buffer3[i]-buffer4[i];
buffer2[i] = 0;
trend[i] = trend[i+1];
if (ExtMapBuffer[i]> ExtMapBuffer[i+1]) trend[i] =1;
if (ExtMapBuffer[i]< ExtMapBuffer[i+1]) trend[i] =-1;
if (trend[i]>0)
{ Uptrend[i] = ExtMapBuffer[i];
if (trend[i+1]<0) Uptrend[i+1]=ExtMapBuffer[i+1];
Dntrend[i] = EMPTY_VALUE;
}
else
if (trend[i]<0)
{
Dntrend[i] = ExtMapBuffer[i];
if (trend[i+1]>0) Dntrend[i+1]=ExtMapBuffer[i+1];
Uptrend[i] = EMPTY_VALUE;
}
}
//
//
//
//
//
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
double calculateTma(double& prices[], int halfLength, int i)
{
int j,k;
double sum = (halfLength+1)*prices[i];
double sumw = (halfLength+1);
for(j=1, k=halfLength; j<=halfLength; j++, k--)
{
sum += k*prices[i+j];
sumw += k;
if (j<=i)
{
sum += k*prices[i-j];
sumw += k;
}
}
return(sum/sumw);
}
But you also need to take into account that for a line to show, the previous buffer also usually != EMPTY_VALUE.
Thank you for your answer!
I know, the line is always shown. My problem is that i need to know the color.
Looking at the value it provides didn't really helped me, any suggestions ? In some cases all got values in it.
If you compare adjacent bars and the buffer has a value for both, then you know that that buffer draws a line between those 2 bars.
The problem comes when some indicators more than 1 buffer draws a line between the same 2 bars, then only 1 colour shows.
A good way to check is to put the indicator on a chart and set the colour for all drawn buffers except 1 to no colour. Then only 1 colour will show in sections. The buffer that always has a value for the bars where the line shows is the buffer that you are interested in for that particular colour.
Here is the source code of v1.0 which sadly redraws in history, the version 1.2 attached in the above post does not do that, thats why I would have liked to use it.
Maybe the code of v1.0 is enough to figure out how to detect the different colors.
//| TriangularMA centered.mq4 |
//| mladen |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DeepSkyBlue
#property indicator_color2 OrangeRed
#property indicator_color3 DimGray
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 1
//
//
//
//
//
extern int FastHalfLength = 50;
extern int SlowHalfLength = 100;
extern int Price = PRICE_CLOSE;
//
//
//
//
//
double ExtMapBuffer[];
double Uptrend[];
double Dntrend[];
double buffer2[];
double buffer3[];
double buffer4[];
double pricesArray[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
int init()
{
FastHalfLength=MathMax(FastHalfLength,1);
SlowHalfLength=MathMax(SlowHalfLength,1);
IndicatorBuffers(7);
SetIndexBuffer(0,Uptrend); SetIndexDrawBegin(0,SlowHalfLength);
SetIndexBuffer(1,Dntrend); SetIndexDrawBegin(1,SlowHalfLength);
SetIndexBuffer(2,buffer2);
SetIndexBuffer(3,ExtMapBuffer);
ArraySetAsSeries(ExtMapBuffer, true);
SetIndexBuffer(4,buffer3);
SetIndexBuffer(5,buffer4);
SetIndexBuffer(6,pricesArray);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID);
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID);
return(0);
}
int deinit() { return(0); }
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int start()
{
double sum,sumw;
int counted_bars=IndicatorCounted();
int i,j,k,limit;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=MathMin(Bars-counted_bars,Bars-1);
limit=MathMax(limit,FastHalfLength);
limit=MathMax(limit,SlowHalfLength);
double trend[];
ArrayResize(trend, limit);
ArraySetAsSeries(trend, true);
//
//
//
//
//
for (i=limit;i>=0;i--) pricesArray[i] = iMA(NULL,0,1,0,MODE_SMA,Price,i);
for (i=limit;i>=0;i--)
{
buffer3[i] = calculateTma(pricesArray,FastHalfLength,i);
buffer4[i] = calculateTma(pricesArray,SlowHalfLength,i);
ExtMapBuffer[i] = buffer3[i]-buffer4[i];
buffer2[i] = 0;
trend[i] = trend[i+1];
if (ExtMapBuffer[i]> ExtMapBuffer[i+1]) trend[i] =1;
if (ExtMapBuffer[i]< ExtMapBuffer[i+1]) trend[i] =-1;
if (trend[i]>0)
{ Uptrend[i] = ExtMapBuffer[i];
if (trend[i+1]<0) Uptrend[i+1]=ExtMapBuffer[i+1];
Dntrend[i] = EMPTY_VALUE;
}
else
if (trend[i]<0)
{
Dntrend[i] = ExtMapBuffer[i];
if (trend[i+1]>0) Dntrend[i+1]=ExtMapBuffer[i+1];
Uptrend[i] = EMPTY_VALUE;
}
}
//
//
//
//
//
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
double calculateTma(double& prices[], int halfLength, int i)
{
int j,k;
double sum = (halfLength+1)*prices[i];
double sumw = (halfLength+1);
for(j=1, k=halfLength; j<=halfLength; j++, k--)
{
sum += k*prices[i+j];
sumw += k;
if (j<=i)
{
sum += k*prices[i-j];
sumw += k;
}
}
return(sum/sumw);
}
If it does not, then it is using simple LWMA and has nothing in common with centered TMA (or TMA)
salexes: I know, the line is always shown. My problem is that i need to know the color.
#property indicator_color1 DeepSkyBlue #property indicator_color2 OrangeRed #property indicator_color3 DimGray | Detailed explanation of iCustom - MQL4 forum |

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I am using the indicator "TMAcentered MACD v1.2.ex4 " and I want to include it into my EA. But right now I got a problem, how can I determine the current color of it programmatically ?
regards,
salexes