# 懒惰是进步的动力，或者如何交互性的使用图形

17 三月 2016, 09:27
0
712

### 图形对象坐标的处理

• 让交易者在图表上指定对象绘图的一个参考点。
• 保存了充分的代码输入，所以计算机的处理器加载同样如此。
• 没有必要在图表上对绘制对象编写初始逻辑。另外，要在程序上实现所需的逻辑没那么容易。例如，看一下有多少“锯齿形调整浪”指标。

（1_01_Tr_Alert 指标随这些线进行调整，在 Demark 趋势线绘制指标 TL_by_Demark_v6 中使用相同的名称）

`int    obj_total=ObjectsTotal();`

```// Determine the Trend line object
int    obj_total=ObjectsTotal();
string index;
for(int i=0;i<obj_total;i++)
{
index=ObjectName(i);
string substrTL_down = StringSubstr (index, 0, 7);
if (substrTL_down == "TrDdown") string TrDLine_down=index;
string substrTL_up = StringSubstr (index, 0, 5);
if (substrTL_up == "TrDup") string TrDLine_up=index;

}```

`if ((Close[1]>ObjectGetValueByShift(TrDLine, 1)) && (Close[2]<ObjectGetValueByShift(TrDLine, 2)))`

```//+------------------------------------------------------------------+
//|                                               1.012_InfoFibo.mq4 |
//|                                                                  |
//|                                                     b2w@narod.ru |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
//---- input parameters
extern bool Auto_Correct_Line = false;// Autocorrection of the last Fibo point
extern bool ClearRectangle = true;//Deleting of the squares while redrawing of the Fibo levels
extern bool TargetZone = true;//Drawing of the target zones
double fibs[] = {-0.618, -0.382, -0.237, 0.0, 0.145, 0.382, 0.618, 0.855, 1.0, 1.237, 1.382, 1.618};
color fibsColor[] = {Maroon, Green, ForestGreen, Teal, SteelBlue, ,
SteelBlue, Teal, ForestGreen, Green, Maroon};
double Old_Price;
color FontColor=Black;
int y=0,count_a=0;
double ftime;
double win_idx;
string NameFibs;
double ExtMapBufferUP[];
double ExtMapBufferDN[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{

//---- indicators
SetIndexStyle(0,DRAW_ARROW,0,1);
SetIndexArrow(0,233);
SetIndexBuffer(0,ExtMapBufferUP);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,DRAW_ARROW,0,1);
SetIndexArrow(1,234);
SetIndexBuffer(1,ExtMapBufferDN);
SetIndexEmptyValue(1,0.0);

return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
if(ftime!=Time[0]) count_a=0;
//  int    counted_bars=IndicatorCounted();
//----
// Determine if there are the Fibo levels or not
int    obj_total=ObjectsTotal();
string index;
for(int i=0;i<obj_total;i++)
{
index=ObjectName(i);
string substr = StringSubstr(index, 0, 4);
if (substr == "Fibo")  NameFibs=index;
string substrTL = StringSubstr (index, 0, 9);
if (substrTL == "Trendline")
string TrDLine=index;
string substrPR = StringSubstr (index, 0, 5);
if (substrPR == "Arrow")
string PR=index;
}

// Parameters of the trend line
if (StringLen(TrDLine)>1)
{
if (ObjectGet(TrDLine, OBJPROP_PRICE1)>ObjectGet(TrDLine, OBJPROP_PRICE2))
{
if ((Close[1]>ObjectGetValueByShift(TrDLine, 1)) &&
(Close[2]<ObjectGetValueByShift(TrDLine, 2)))
{
ExtMapBufferUP[1]=(Low[1]-5*Point); /*Alert (Symbol(),"  Trend UP enter");*/
}
}
else
if (ObjectGet(TrDLine, OBJPROP_PRICE1)<ObjectGet(TrDLine, OBJPROP_PRICE2))
{
if ((Close[1]<ObjectGetValueByShift(TrDLine, 1)) &&
(Close[2]>ObjectGetValueByShift(TrDLine, 2)))
{
}
}
}
// The end of calculation of the trend line
if (StringLen(NameFibs) <1) return(-1);// If there are no Fibo levels, then we exit
// Determine where the Fibo levels are drawn
double pr1=ObjectGet(NameFibs, OBJPROP_PRICE1);// first price High
double pr1vrem=ObjectGet(NameFibs, OBJPROP_TIME1);// first time of the price
double pr2=ObjectGet(NameFibs,OBJPROP_PRICE2);// second price Low
double pr2vrem=ObjectGet(NameFibs, OBJPROP_TIME2);// second time of the price
double fibprop=(pr1-pr2);// The difference between HIGH and LOW
double Timeend=(Time[0]+(Period()*360)); // The right side by the time
// to display the objects on the chart
double TimeNachalo=(Time[0]+Period()*60);// The right side by the time
// to display the objects on the chart
//+++
ObjectMove(PR, 0,Time[0], Bid);// The icon of the current price
//+++
// Parameters of the rectangle of the reverse zone..
double verx=(pr1-fibprop*0.382);
double niz=(pr2+fibprop*0.382);
if (Auto_Correct_Line==true)
{
if (High[0]>pr1) ObjectMove(NameFibs, 0,Time[0], High[0]);
if (Low[0]<pr2) ObjectMove(NameFibs, 1,Time[0], Low[0]);
}
if (ClearRectangle == true) ObjectsDeleteAll(0,OBJ_RECTANGLE);// Delete the RECTANGLES objects
// Draw the rectangles in the cycle
for( y=0;y<11;y++)
{
Timeend,(pr2+fibprop*fibs[y+1]) );
}
// The end of drawing

/* Drawing of the rectangle of the ZONE */
ObjectCreate("Kvadrat", OBJ_RECTANGLE, 0, TimeNachalo, verx , Timeend , niz);

// The array of text data
TextAlert[0] =   "Attention two targets ";
TextAlert[1] =   ("Order up * "+UP);
TextAlert[2] =   ("Order down   * "+DN);
TextAlert[3] =   ("TARGET up 2  * "+(DoubleToStr(pr1+fibprop*0.618,Digits)));
TextAlert[4] =   ("TARGET up 1  * "+(DoubleToStr(pr1+fibprop*0.382,Digits)));
TextAlert[5] =   ("TARGET down 1  * "+(DoubleToStr(pr2-fibprop*0.382,Digits)));
TextAlert[6] =   ("TARGET down 2  * "+(DoubleToStr(pr2-fibprop*0.618,Digits)));
double YDist[] = {20, 55, 80, 120, 150, 180, 210};
color TextAlertClr[] = {Yellow, Green, Red, Green, Green, Red, Red};

// Output to the screen the message about orders entering
for(y=0;y<7;y++)
if (TargetZone == true)
{
if (Bid > niz && Bid < verx)
for(y=0;y<7;y++)
{
}
}

// The informer of the price and the currency name
ObjectDelete("Market_Price_Label101");
ObjectCreate("Market_Text_Label101", OBJ_LABEL, 0, 0, 0);
ObjectSetText("Market_Text_Label101", (Symbol()+"  "+Period()), 16, "Times New Roman", Yellow);
ObjectSet("Market_Text_Label101", OBJPROP_CORNER, 2);
ObjectSet("Market_Text_Label101", OBJPROP_XDISTANCE, 5);
ObjectSet("Market_Text_Label101", OBJPROP_YDISTANCE, 5);

return(0);
}

//+------------------------------------------------------------------+

{
ftime=Time[0];
{count_a+=1;
PlaySound("ku_ku.wav");
}
}
return;```

### 总结

1_012_InfoFibo.mq4 (7.42 KB)