哪位朋友可以把它做成MT4指标发布上来
https://www.mql5.com/en/forum/169873 I am using the indicator"TMAcentered MACD v1.2.ex4 " and I want toinclude it into my EA. But right now I got a problem, how can I determine thecurrent color of it programmatically ?regards,salexes Files:TMAcentered_MACD_v1.2.ex416 kb· Learn how to design a trading system by Bear's Power· Objects - Charts - MetaTrader 5 for Android· Murrey Math Line - Line Drawing Problem509salexes 2017.02.10 13:59 #1 Here is the source code of v1.0 which sadly redraws in history, theversion 1.2 attached in the above post does not do that, thats why I would haveliked to use it.
Maybe the code of v1.0 is enough to figure out how to detect the differentcolors. //+------------------------------------------------------------------+
//| TriangularMAcentered.mq4 |
//| mladen |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1DeepSkyBlue
#property indicator_color2OrangeRed
#property indicator_color3DimGray
#property indicator_width12
#property indicator_width22
#property indicator_width31
//
//
//
//
//
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 = iMA(NULL,0,1,0,MODE_SMA,Price,i);
for (i=limit;i>=0;i--)
{
buffer3 =calculateTma(pricesArray,FastHalfLength,i);
buffer4 =calculateTma(pricesArray,SlowHalfLength,i);
ExtMapBuffer =buffer3-buffer4;
buffer2 = 0;
trend = trend;
if (ExtMapBuffer>ExtMapBuffer) trend =1;
if (ExtMapBuffer<ExtMapBuffer) trend =-1;
if (trend>0)
{ Uptrend = ExtMapBuffer;
if (trend<0) Uptrend=ExtMapBuffer;
Dntrend = EMPTY_VALUE;
}
else
if (trend<0)
{
Dntrend = ExtMapBuffer;
if (trend>0) Dntrend=ExtMapBuffer;
Uptrend = EMPTY_VALUE;
}
}
//
//
//
//
//
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
double calculateTma(double&prices[], int halfLength, int i)
{
int j,k;
double sum=(halfLength+1)*prices;
double sumw =(halfLength+1);
for(j=1, k=halfLength; j<=halfLength; j++, k--)
{
sum+= k*prices;
sumw += k;
if (j<=i)
{
sum+=k*prices;
sumw += k;
}
}
return(sum/sumw);
} 在网站中他们贴了两幅源码,我不知道区别在哪里。 //+------------------------------------------------------------------+
//| TriangularMAcentered.mq4 |
//| mladen |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1DeepSkyBlue
#property indicator_color2OrangeRed
#property indicator_color3DimGray
#property indicator_width12
#property indicator_width22
#property indicator_width31
//
//
//
//
//
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= iMA(NULL,0,1,0,MODE_SMA,Price,i);
for (i=limit;i>=0;i--)
{
buffer3 = calculateTma(pricesArray,FastHalfLength,i);
buffer4 = calculateTma(pricesArray,SlowHalfLength,i);
ExtMapBuffer = buffer3-buffer4;
buffer2 = 0;
trend= trend1];
if (ExtMapBuffer>ExtMapBuffer1]) trend =1;
if (ExtMapBuffer<ExtMapBuffer1]) trend =-1;
if (trend>0)
{ Uptrend =ExtMapBuffer;
if (trend1]<0) Uptrend1]=ExtMapBuffer1];
Dntrend= EMPTY_VALUE;
}
else
if (trend<0)
{
Dntrend= ExtMapBuffer;
if (trend1]>0) Dntrend1]=ExtMapBuffer1];
Uptrend= EMPTY_VALUE;
}
}
//
//
//
//
//
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
double calculateTma(double& prices[], int halfLength, int i)
{
int j,k;
double sum=(halfLength+1)*prices;
double sumw =(halfLength+1);
for(j=1, k=halfLength;j<=halfLength; j++, k--)
{
sum+=k*prices;
sumw += k;
if (j<=i)
{
sum+= k*prices;
sumw += k;
}
}
return(sum/sumw);
}
页:
[1]