均线多头或空头排列指标-请教高手

 

我有4条均线,分别是10,20,30,60.颜色是绿,青,蓝,紫。都是细线1,目标就是想达到均线空头或多头排列的时候,10日绿线能变粗为2,只要醒目就好,我现在把均线都编好了,就差判断语句不会写,请教高手,非常感谢,以下是代码,

//+------------------------------------------------------------------+
//| Custom Moving Average.mq4 |
//| Copyright ?2004, MetaQuotes Software Corp. |
//| https://www.metaquotes.net// |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2004, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net//"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 MediumOrchid
#property indicator_color2 Blue
#property indicator_color3 Aqua
#property indicator_color4 Lime


//---- input parameters
extern int MA1Period=60;
extern int MA1Shift=0;
extern int MA2Period=30;
extern int MA2Shift=0;
extern int MA3Period=20;
extern int MA3Shift=0;
extern int MA4Period=10;
extern int MA4Shift=0;
//---- indicator buffers
double ExtMA1Buffer[];
double ExtMA2Buffer[];
double ExtMA3Buffer[];
double ExtMA4Buffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- line shifts when drawing
SetIndexShift(0,MA1Shift);
SetIndexShift(1,MA2Shift);
SetIndexShift(2,MA3Shift);
SetIndexShift(3,MA4Shift);
//---- first positions skipped when drawing
SetIndexDrawBegin(0,MA1Shift+MA1Period);
SetIndexDrawBegin(1,MA2Shift+MA2Period);
SetIndexDrawBegin(2,MA3Shift+MA3Period);
SetIndexDrawBegin(3,MA4Shift+MA4Period);
//---- 4 indicator buffers mapping
SetIndexBuffer(0,ExtMA1Buffer);
SetIndexBuffer(1,ExtMA2Buffer);
SetIndexBuffer(2,ExtMA3Buffer);
SetIndexBuffer(3,ExtMA4Buffer);
//---- drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
SetIndexStyle(3,DRAW_LINE);
//---- index labels
SetIndexLabel(0,"MA1");
SetIndexLabel(1,"MA2");
SetIndexLabel(2,"MA3");
SetIndexLabel(3,"MA4");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| 4MA |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- main loop
for(int i=0; i<limit; i++)
{
//---- ma_shift set to 0 because SetIndexShift called abowe
ExtMA1Buffer[i]=iMA(NULL,0,MA1Period,0,MODE_SMA,PRICE_CLOSE,i);
ExtMA2Buffer[i]=iMA(NULL,0,MA2Period,0,MODE_SMA,PRICE_CLOSE,i);
ExtMA3Buffer[i]=iMA(NULL,0,MA3Period,0,MODE_SMA,PRICE_CLOSE,i);
ExtMA4Buffer[i]=iMA(NULL,0,MA4Period,0,MODE_SMA,PRICE_CLOSE,i);
}
//---- done
int mark=0;

if( "MA1now"<"MA2now" && "MA2now"<"MA3now" && "MA3now"<"MA4now" && mark!=1)
{
????????
mark=1;
}
if( "MA1now">"MA2now" && "MA2now">"MA3now" && "MA3now">"MA4now" && mark!=2)
{
?????????

mark=2;
}

return(0);
}
//+------------------------------------------------------------------+

 

你可以在设定线粗的语句的地方,用变量来代替整数

int xiancu=1;

#property indicator_width4 xiancu

当某一条件下,给xiancu赋值2

基本上就可以了。

 

把这句加上,应该可以,不过画线的代码可能应该重新绘制一下,否则可能看不到效果

SetIndexStyle(3, DRAW_LINE, EMPTY, 2);

 
真谢谢两位热情好心的高手指点,非常感谢,俺试试