# 指标外部参数的图形控制

11 四月 2016, 17:20
0
726

### 参数的图形控制

ExtDepth=12

ExtDeviation=5

ExtBackstep=3

```// Initial indicator values
int               ExtDepth=12;
int               ExtDeviation=5;
int               ExtBackstep=3;
//---- indicator buffers
double            ZigzagBuffer[];
double            HighMapBuffer[];
double            LowMapBuffer[];
// Array of indicator parameter variables
string            ArrExt[3,3]    ={"12","21","34", "5","8","21", "3","13","34"};
// Arrays of indices
string            Array_Index[]={"Dep -> ","Dev -> ","Back ->"};
int               Coordinats_IndexUp[]={65,160,260};
int               Coordinats_Index[]  ={35,130,230};
int               Coordinats_IndexDn[]={5, 100,200};
// Color for parameter blocks and indices
color             Color_[]={Blue,Green,Red};```

`"Dep -> ","Dev -> ","Back ->"`

```string            ArrExtDepth[]    ={"12","15","20"};
string            ArrExtDeviation[]={"5",  "8","21"};
string            ArrExtBackstep[] ={"3", "13","34"};
```

`string            ArrExt[3,3]    ={"12","21","34", "5","8","21", "3","13","34"};`

3、5、12 是标准锯齿形调整浪指标的参数中默认设置的标准值。

```void Obj_CreateMove_Text (int CreateMove, string Name, int Type, string Number,  color text_color,
int DistX, int DistY)
{
if (CreateMove==0)
ObjectCreate(Name,Type,0,0,0);
ObjectSetText(Name,Number,10,"Arial",text_color);
ObjectSet(Name,101,3);
ObjectSet(Name, 102, DistX);
ObjectSet(Name, 103, DistY);
}
```

```// Create objects
for( ii=0;ii<3;ii++)
for( i=0;i<3;i++)
Obj_CreateMove_Text (0, Array_Index[ii]+i, 23, (ArrExt[ii,i]), Color_[ii], 5, Coordinats_IndexDn[ii]+30*i);
for( i=0;i<3;i++)
Obj_CreateMove_Text (0, "Index"+Array_Index[i], 23, (Array_Index[i]),   Color_[i], 25, Coordinats_Index[i]);
```

```// Read index coordinates from the chart
for( i=0;i<3;i++)
{
Coordinats[i]=ObjectGet("Index"+Array_Index[i],OBJPROP_YDISTANCE);
if (Coordinats[i]==0)//If outside of the chart, set again
Obj_CreateMove_Text (1, "Index"+Array_Index[i], 23, Array_Index[i], Color_[i], 25, Coordinats_IndexDn[i]);
}
```

`the OBJPROP_YDISTANCE parameter`

`ObjectGet()`

```// Analyze positions of indices
for( i=0;i<3;i++)
{
if (Coordinats[i]>Coordinats_IndexUp[i])
{Move[i] = Coordinats_IndexUp[i]; index[i]=2;}// Index has been moved up
if (Coordinats[i]>Coordinats_IndexDn[i]  &&
Coordinats[i]<Coordinats_IndexUp[i])
{Move[i] = Coordinats_Index[i];   index[i]=1;}// Index is in the middle
if (Coordinats[i]<Coordinats_IndexDn[i])
{Move[i] = Coordinats_IndexDn[i]; index[i]=0;}// Index has been moved down
if (Move[i]!=0)```

```// Move and align the objects depending on their positions
Obj_CreateMove_Text (1, "Index"+Array_Index[i], 23, Array_Index[i], Color_[i], 25, Move[i]);
// Save ZigZag parameter values
switch (i)
{
case 0:  ExtDepth =     StrToInteger(ArrExt[0,index[i]]);  break;
case 1:  ExtDeviation = StrToInteger(ArrExt[1,index[i]]);  break;
case 2:  ExtBackstep =  StrToInteger(ArrExt[2,index[i]]);  break;
}/**/
}
// Pass parameter values to the custom indicator and plot ZigZag based on the obtained values
for(i=300;i>0;i--)
{
ZigzagBuffer[i]=iCustom(NULL,0,"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0,i);
HighMapBuffer[i]=iCustom(NULL,0,"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,1,i);
LowMapBuffer[i]=iCustom(NULL,0,"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,2,i);
}```

```//+------------------------------------------------------------------+
//|                                         management_indicator.mq4 |
//|                                             http://www.fibook.ru |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
// Initial indicator values
int               ExtDepth=12;
int               ExtDeviation=5;
int               ExtBackstep=3;
//---- indicator buffers
double            ZigzagBuffer[];
double            HighMapBuffer[];
double            LowMapBuffer[];
// Array of indicator parameter variables
string            ArrExt[3,3]    ={"12","21","34", "5","8","21", "3","13","34"};
// Arrays of indices
string            Array_Index[]={"Dep -> ","Dev -> ","Back ->"};
int               Coordinats_IndexUp[]={65,160,260};
int               Coordinats_Index[]  ={35,130,230};
int               Coordinats_IndexDn[]={5, 100,200};
// Color for parameter blocks and indices
color             Color_[]={Blue,Green,Red};
// Variables for calculations
int               i,ii;
int               index[3];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(3);
//---- drawing settings
SetIndexStyle(0,DRAW_SECTION);
//---- indicator buffers mapping
SetIndexBuffer(0,ZigzagBuffer);
SetIndexBuffer(1,HighMapBuffer);
SetIndexBuffer(2,LowMapBuffer);
SetIndexEmptyValue(0,0.0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
int  Coordinats[3];
int  Move[3];
// Check if index objects are on the chart
if (ObjectGet("IndexDep -> ",OBJPROP_YDISTANCE)<1||
ObjectGet("IndexDev -> ",OBJPROP_YDISTANCE)<1||
ObjectGet("IndexBack ->",OBJPROP_YDISTANCE)<1)
// If they are not on the chart, create them
{
for( ii=0;ii<3;ii++)
for( i=0;i<3;i++)
Obj_CreateMove_Text (0, Array_Index[ii]+i, 23, ArrExt[ii,i], Color_[ii], 5, Coordinats_IndexDn[ii]+30*i);
for( i=0;i<3;i++)
Obj_CreateMove_Text (0, "Index"+Array_Index[i], 23, Array_Index[i], Color_[i], 25, Coordinats_IndexDn[i]);
}
// Read index coordinates from the chart
for( i=0;i<3;i++)
{
Coordinats[i]=ObjectGet("Index"+Array_Index[i],OBJPROP_YDISTANCE);
if (Coordinats[i]==0)//If outside of the chart, set again
Obj_CreateMove_Text (1, "Index"+Array_Index[i], 23, Array_Index[i], Color_[i], 25, Coordinats_IndexDn[i]);
}
// Analyze positions of indices
for( i=0;i<3;i++)
{
if (Coordinats[i]>Coordinats_IndexUp[i])
{Move[i] = Coordinats_IndexUp[i]; index[i]=2;}//Index has been moved up
if (Coordinats[i]>Coordinats_IndexDn[i]  &&
Coordinats[i]<Coordinats_IndexUp[i])
{Move[i] = Coordinats_Index[i];   index[i]=1;}// Index is in the middle
if (Coordinats[i]<Coordinats_IndexDn[i])
{Move[i] = Coordinats_IndexDn[i]; index[i]=0;}// Index has been moved down
if (Move[i]!=0)
// Move and align the objects depending on their positions
Obj_CreateMove_Text (1, "Index"+Array_Index[i], 23, Array_Index[i], Color_[i], 25, Move[i]);
// Save ZigZag parameter values
switch (i)
{
case 0:  ExtDepth =     StrToInteger(ArrExt[0,index[i]]);  break;
case 1:  ExtDeviation = StrToInteger(ArrExt[1,index[i]]);  break;
case 2:  ExtBackstep =  StrToInteger(ArrExt[2,index[i]]);  break;
}/**/
}
// Pass parameter values to the custom indicator and plot ZigZag based on the obtained values
for(i=300;i>0;i--)
{
ZigzagBuffer[i]=iCustom(NULL,0,"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0,i);
HighMapBuffer[i]=iCustom(NULL,0,"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,1,i);
LowMapBuffer[i]=iCustom(NULL,0,"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,2,i);
}
Comment ("ExtDepth =",ExtDepth,", ExtDeviation =",ExtDeviation,", ExtBackstep =",ExtBackstep);
//----
return(0);
}
// Function for creating and moving graphical objects
void Obj_CreateMove_Text (int CreateMove, string Name, int Type, string Number,  color text_color, int DistX, int DistY)
{
if (CreateMove==0)
ObjectCreate(Name,Type,0,0,0);
ObjectSetText(Name,Number,10,"Arial",text_color);
ObjectSet(Name,101,3);
ObjectSet(Name, 102, DistX);
ObjectSet(Name, 103, DistY);
}

//+------------------------------------------------------------------+```