OBJ_ARROW_STOP

停止符号。

注意

相对于符号的定位点位置可以从ENUM_ARROW_ANCHOR 枚举选择。

在MetaEditor编写代码时,大型符号(大于5)只能通过设置适当的OBJPROP_WIDTH属性值来创建。

示例

下面的脚本创建和移动图表上的停止符号。已开发的特别函数用于创建和改变图形对象的属性。您可以在您的个人应用中使用这些函数"as is" 。

//--- 描述

#property description "Script draws \"Stop\" sign."

#property description "Anchor point coordinate is set in"

#property description "percentage of the chart window size."

//--- 启动脚本期间显示输入参数的窗口

#property script_show_inputs

//--- 脚本的输入参数

input string            InpName="ArrowStop";     // 符号名称

input int               InpDate=10;              // 定位点日期在 %

input int               InpPrice=50;             // 定位点价格在 %

input ENUM_ARROW_ANCHOR InpAnchor=ANCHOR_BOTTOM; // 定位类型

input color             InpColor=clrRed;         // 符号颜色

input ENUM_LINE_STYLE   InpStyle=STYLE_DOT;      // 边界线条风格

input int               InpWidth=5;              // 符号大小

input bool              InpBack=false;           // 背景符号

input bool              InpSelection=false;      // 突出移动

input bool              InpHidden=true;          // 隐藏对象列表中

input long              InpZOrder=0;             // 鼠标单击优先

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

//| Create Stop sign                                                 |

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

bool ArrowStopCreate(const long              chart_ID=0,           // 图表 ID

                     const string            name="ArrowStop",     // 符号名称

                     const int               sub_window=0,         // 子窗口指数

                     datetime                time=0,               // 定位点时间

                     double                  price=0,              // 定位点价格

                     const ENUM_ARROW_ANCHOR anchor=ANCHOR_BOTTOM, // 定位类型

                     const color             clr=clrRed,           // 符号颜色

                     const ENUM_LINE_STYLE   style=STYLE_SOLID,    // 边界线条风格

                     const int               width=3,              // 符号大小

                     const bool              back=false,           // 在背景中

                     const bool              selection=true,       // 突出移动

                     const bool              hidden=true,          // 隐藏在对象列表

                     const long              z_order=0)            // 鼠标单击优先

  {

//--- 若未设置则设置定位点的坐标

   ChangeArrowEmptyPoint(time,price);

//--- 重置错误的值

   ResetLastError();

//--- 创建符号

   if(!ObjectCreate(chart_ID,name,OBJ_ARROW_STOP,sub_window,time,price))

     {

      Print(__FUNCTION__,

            ": failed to create \"Stop\" sign! Error code = ",GetLastError());

      return(false);

     }

//--- 设置定位类型

   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);

//--- 设置符号颜色

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

//--- 设置边界线条风格

   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);

//--- 设置符号大小

   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);

//--- 显示前景 (false) 或背景 (true)

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);

//--- 启用 (true) 或禁用 (false) 通过鼠标移动符号的模式

//--- 当使用ObjectCreate函数创建图形对象时,对象不能

//--- 默认下突出并移动。在这个方法中,默认选择参数

//--- true 可以突出移动对象

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

//--- 在对象列表隐藏(true) 或显示 (false) 图形对象名称

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

//--- 设置在图表中优先接收鼠标点击事件

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

//--- 成功执行

   return(true);

  }

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

//| 移动定位点                                                        |

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

bool ArrowStopMove(const long   chart_ID=0,       // 图表 ID

                   const string name="ArrowStop", // 对象名称

                   datetime     time=0,           // 定位点时间坐标

                   double       price=0)          // 定位点价格坐标

  {

//--- 如果没有设置点的位置,则将其移动到当前的卖价柱

   if(!time)

      time=TimeCurrent();

   if(!price)

      price=SymbolInfoDouble(Symbol(),SYMBOL_BID);

//--- 重置错误的值

   ResetLastError();

//--- 移动定位点

   if(!ObjectMove(chart_ID,name,0,time,price))

     {

      Print(__FUNCTION__,

            ": failed to move the anchor point! Error code = ",GetLastError());

      return(false);

     }

//--- 成功执行

   return(true);

  }

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

//| 改变停止符号定位类型                                                |

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

bool ArrowStopAnchorChange(const long              chart_ID=0,        // 图表 ID

                           const string            name="ArrowStop",  // 对象名称

                           const ENUM_ARROW_ANCHOR anchor=ANCHOR_TOP) // 定位点位置

  {

//--- 重置错误的值

   ResetLastError();

//--- 改变定位类型

   if(!ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor))

     {

      Print(__FUNCTION__,

            ": failed to change anchor type! Error code = ",GetLastError());

      return(false);

     }

//--- 成功执行

   return(true);

  }

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

//| 删除停止符号                                                       |

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

bool ArrowStopDelete(const long   chart_ID=0,       // 图表 ID

                     const string name="ArrowStop") // 标签名称

  {

//--- 重置错误的值

   ResetLastError();

//--- 删除符号

   if(!ObjectDelete(chart_ID,name))

     {

      Print(__FUNCTION__,

            ": failed to delete \"Stop\" sign! Error code = ",GetLastError());

      return(false);

     }

//--- 成功执行

   return(true);

  }

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

//| 检查定位点的值和为空点设置                                           |

//| 默认的值                                                          |

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

void ChangeArrowEmptyPoint(datetime &time,double &price)

  {

//--- 如果点的时间没有设置,它将位于当前柱

   if(!time)

      time=TimeCurrent();

//--- 如果点的价格没有设置,则它将用卖价值

   if(!price)

      price=SymbolInfoDouble(Symbol(),SYMBOL_BID);

  }

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

//| 脚本程序起始函数                                                   |

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

void OnStart()

  {

//--- 检查输入参数的正确性

   if(InpDate<0 || InpDate>100 || InpPrice<0 || InpPrice>100)

     {

      Print("Error! Incorrect values of input parameters!");

      return;

     }

//--- 图表窗口的可见柱的数量

   int bars=(int)ChartGetInteger(0,CHART_VISIBLE_BARS);

//--- 价格数组大小

   int accuracy=1000;

//--- 存储要使用的日期和价格值的数组

//--- 设置和改变符号定位点的坐标

   datetime date[];

   double   price[];

//--- 内存分配

   ArrayResize(date,bars);

   ArrayResize(price,accuracy);

//--- 填写日期数组

   ResetLastError();

   if(CopyTime(Symbol(),Period(),0,bars,date)==-1)

     {

      Print("Failed to copy time values! Error code = ",GetLastError());

      return;

     }

//--- 填写价格数组

//--- 找出图表的最高值和最低值

   double max_price=ChartGetDouble(0,CHART_PRICE_MAX);

   double min_price=ChartGetDouble(0,CHART_PRICE_MIN);

//--- 定义变化的价格并填写该数组

   double step=(max_price-min_price)/accuracy;

   for(int i=0;i<accuracy;i++)

      price[i]=min_price+i*step;

//--- 定义绘制符号的点

   int d=InpDate*(bars-1)/100;

   int p=InpPrice*(accuracy-1)/100;

//--- 在图表上创建停止符号

   if(!ArrowStopCreate(0,InpName,0,date[d],price[p],InpAnchor,InpColor,

      InpStyle,InpWidth,InpBack,InpSelection,InpHidden,InpZOrder))

     {

      return;

     }

//--- 重画图表并等待1秒

   ChartRedraw();

   Sleep(1000);

//--- 现在,移动定位点和改变其相对于符号的位置

//--- 循环计数器

   int h_steps=bars*2/5;

//--- 移动定位点

   for(int i=0;i<h_steps;i++)

     {

      //--- 使用下面的值

      if(d<bars-1)

         d+=1;

      //--- 移动点

      if(!ArrowStopMove(0,InpName,date[d],price[p]))

         return;

      //--- 检查脚本操作是否已经强制禁用

      if(IsStopped())

         return;

      //--- 重画图表

      ChartRedraw();

      // 0.025 秒延迟

      Sleep(25);

     }

//--- 改变定位点相对于符号的位置

   ArrowStopAnchorChange(0,InpName,ANCHOR_TOP);

//--- 重画图表

   ChartRedraw();

//--- 循环计数器

   h_steps=bars*2/5;

//--- 移动定位点

   for(int i=0;i<h_steps;i++)

     {

      //--- 使用下面的值

      if(d<bars-1)

         d+=1;

      //--- 移动点

      if(!ArrowStopMove(0,InpName,date[d],price[p]))

         return;

      //--- 检查脚本操作是否已经强制禁用

      if(IsStopped())

         return;

      //--- 重画图表

      ChartRedraw();

      // 0.025 秒延迟

      Sleep(25);

     }

//--- 1 秒延迟

   Sleep(1000);

//--- 删除图表符号

   ArrowStopDelete(0,InpName);

   ChartRedraw();

//--- 1 秒延迟

   Sleep(1000);

//---

  }