# 四个时间范围的多个指标信号的同步显示

26 二月 2016, 09:52
0
1 707

### 简介

Real_Time_MultiIndicator_v1 是专门为解决这些任务而创建。该指标同时计算四个时间范围上的选定指标信号，并将其转换为主图表子窗口中的表格。在指标信号后面的括号内，可以看到表明信号的属于选中时间范围的最新柱数。

### 在表格添加新指标

```//----The parameters of the indicators
extern string p1 = "SAR parameters";
extern double SAR_Step = 0.01;
extern double SAR_Max = 0.1;
extern string p2 = "MACD parameters";
extern int Fast_EMA = 12;
extern int Slow_EMA = 26;
extern int MACD_SMA = 9;
extern string p3 = "Moving Average parameters";
extern int Fast_MA = 5;
extern int Slow_MA = 10;
extern string p4 = "ADX parameters";
//extern string p5 = "The parameters of the indicator 1";
//extern string p6 = "The parameters of the indicator 2";
//extern string p7 = "The parameters of the indicator 3";```

`extern string p5 = "CCI parameters";`

```extern string p5 = "CCI parameters";
extern int Period_CCI = 14;```

`string name[] = {"Parabolic SAR","MACD","Сrossing MA","ADX","","",""};`

`string name[] = {"Parabolic SAR","MACD","Сrossing MA","ADX","CCI","",""};`

``` int init()
{
string sn = "Real_Time_MultiIndicator_v1";
IndicatorShortName(sn);
SetIndexLabel(0, sn);
name[0] = name[0] + "(" + DoubleToStr(SAR_Step, 2) + ", " +
DoubleToStr(SAR_Max, 2) + ")";
name[1] = name[1] + "(" + DoubleToStr(Fast_EMA, 0) + ", " +
DoubleToStr(Slow_EMA, 0) + ", " +
DoubleToStr(MACD_SMA, 0) + ")";
name[2] = name[2] + "(" + DoubleToStr(Fast_MA, 0) + ", " +
DoubleToStr(Slow_MA, 0) + ")";
name[3] = name[3] + "(" + DoubleToStr(ADX_Period, 0) + ")";
//name[4] = name[4] + "(" +
//          DoubleToStr(1st parameter of the indicator 1, 0) +
//          ", " + DoubleToStr(2nd parameter of the indicator 1, 0) + ")";
//name[5] = name[5] + "(" +
//          DoubleToStr(1st parameter of the indicator 2, 0) +
//          ", " + DoubleToStr(2nd parameter of the indicator 2, 0) + ")";
//name[6] = name[6] + "(" +
//          DoubleToStr(1st parameter of the indicator 3, 0) +
//          ", " + DoubleToStr(2nd parameter of the indicator 3, 0) + ")";
return(0);
}```

```//name[4] = name[4] + "(" +

//          DoubleToStr(1st paramater of the indicator 1, 0) +

//          ", " + DoubleToStr(2nd parameter of the indicator 1, 0) + ")";```

`name[4] = name[4] + "(" + DoubleToStr(Period_CCI, 0) + ")";`

```/*
//+------------------------------------------------------------------+
//| Function 1                                                       |
//+------------------------------------------------------------------+

string Function(int p)

{
int ii  = 1;
if (C=Condition for the indicator - true - sell, false - buy)
{
while (Conditionc for sell)
ii++;
if (Error(p,ii+1) == 1) return("Waiting data");
return("Sell(" + DoubleToStr(ii, 0) + ")");
}
else
{
ii++;
if (Error(p,ii+1) == 1) return("Waiting data");
return("Buy(" + DoubleToStr(ii, 0) + ")");
}
}*/```

`string CCI(int p)`

`iCCI(NULL, p, Period_CCI, PRICE_MEDIAN, 0) < 0`

`while(iCCI(NULL, p, Period_CCI, PRICE_MEDIAN, ii) < 0)`

ii—是相对当前柱的移位。以相同的方式将“while”行（买入条件）更改为

`while(iCCI(NULL, p, Period_CCI, PRICE_MEDIAN, ii) > 0)`

```string CCI(int p)
{
int ii = 1;
if(iCCI(NULL, p, Period_CCI, PRICE_MEDIAN, 0) < 0)
{
while(iCCI(NULL, p, Period_CCI, PRICE_MEDIAN, ii) < 0)
ii++;
if(Error(p, ii + 1) == 1)
return("Waiting data");
return("Sell(" + DoubleToStr(ii, 0) + ")");
}
else
{
while(iCCI(NULL, p, Period_CCI, PRICE_MEDIAN, ii) > 0)
ii++;
if(Error(p, ii + 1) == 1)
return("Waiting data");
return("Buy(" + DoubleToStr(ii, 0) + ")");
}
}```

```if(iCCI(NULL, p, Period_CCI, PRICE_MEDIAN, 0) > -100) &&
iCCI(NULL, p, Period_CCI, PRICE_MEDIAN, 0) < 100))
return("N/A");```

```string CCI(int p)
{
int ii = 1;
if((iCCI(NULL, p, Period_CCI, PRICE_MEDIAN, 0) > -100) &&
(iCCI(NULL, p, Period_CCI, PRICE_MEDIAN, 0) < 100) )
return("N/A");
if(iCCI(NULL, p, Period_CCI, PRICE_MEDIAN, 0) < -100)
{
while(iCCI(NULL, p, Period_CCI, PRICE_MEDIAN, ii) < -100)
ii++;
if(Error(p, ii + 1) == 1)
return("Waiting data");
return("Sell(" + DoubleToStr(ii, 0) + ")");
}
else
{
while(iCCI(NULL, p, Period_CCI, PRICE_MEDIAN, ii) > 100)
ii++;
if(Error(p, ii + 1) == 1)
return("Waiting data");
return("Buy(" + DoubleToStr(ii, 0) + ")");
}
}```

```/*//----------Fifth line
for (i = 1; i <= 4; i++)
{
ObjectDelete("6" + DoubleToStr(i, 0));
ObjectCreate("6" + DoubleToStr(i, 0), OBJ_TEXT,
WindowFind("Real_Time_MultiIndicator_v1"), textT[i+1], textC[6]);
ObjectSetText("6" + DoubleToStr(i, 0), Функция(per[i-1]), 13, "Tahoma", TxtColor);
}*/```

``` //----------Fifth line
for (i=1;i<=4;i++)
{
ObjectDelete("6" + DoubleToStr(i, 0));
ObjectCreate("6" + DoubleToStr(i, 0), OBJ_TEXT,
WindowFind("Real_Time_MultiIndicator_v1"),
textT[i+1], textC[5]);
ObjectSetText("6" + DoubleToStr(i, 0), CCI(per[i-1]), 13,
"Tahoma", TxtColor);
}```

`int per[] = {15,30,60,240};`

`int per[] = {5,30,60,240};`

`string nameS[] = {"INDICATOR","M15","M30","H1","H4"}`

`string nameS[] = {"INDICATOR","M5","M30","H1","H4"};`