跳至内容

Gann Objects

Gann 对象

对于 Gann 扇形图(OBJ_GANNFAN)和 Gann 网格图(OBJ_GANNGRID)对象,您可以指定 ENUM_GANN_DIRECTION 枚举中的两个值来设置趋势方向。

ENUM_GANN_DIRECTION

ID描述
GANN_UP_TREND对应于上升趋势线的线
GANN_DOWN_TREND对应于下降趋势线的线

要将主线的比例设置为 1x1,请使用函数 ObjectSetDouble(chart_handle, gann_object_name, OBJPROP_SCALE, scale),其中:

  • chart_handle – 对象所在的图表窗口;
  • gann_object_name – 对象名称;
  • OBJPROP_SCALE – “比例”属性的标识符;
  • scale – 必需的比例,单位为 Pips/Bar。

Gann 扇形图对象的参数

创建 Gann 扇形图的示例:

void OnStart()
  {
//---
   string my_gann="OBJ_GANNFAN object";
   if(ObjectFind(0,my_gann)<0)// Object not found
     {
      //--- Inform about the failure
      Print("Object ",my_gann," not found. Error code = ",GetLastError());
      //--- Get the maximal price of the chart
      double chart_max_price=ChartGetDouble(0,CHART_PRICE_MAX,0);
      //--- Get the minimal price of the chart
      double chart_min_price=ChartGetDouble(0,CHART_PRICE_MIN,0);
      //--- How many bars are shown in the chart?
      int bars_on_chart=int(ChartGetInteger(0,CHART_VISIBLE_BARS));
      //--- Create an array, to write the opening time of each bar to
      datetime Times[];
      //--- Arrange access to the array as that of timeseries
      ArraySetAsSeries(Times,true);
      //--- Now copy data of bars visible in the chart into this array
      int times=CopyTime(NULL,0,0,bars_on_chart,Times);
      if(times<=0)
        {
         Print("Could not copy the array with the open time!");
         return;
        }
      //--- Preliminary preparations completed

      //--- Index of the central bar in the chart
      int center_bar=bars_on_chart/2;
      //--- Chart equator - between the maximum and minimum
      double mean=(chart_max_price+chart_min_price)/2.0;
      //--- Set the coordinates of the first anchor point to the center
      ObjectCreate(0,my_gann,OBJ_GANNFAN,0,Times[center_bar],mean,
                   //--- Second anchor point to the right
                   Times[center_bar/2],(mean+chart_min_price)/2.0);
      Print("Times[center_bar] = "+(string)Times[center_bar]+"  Times[center_bar/2] = "+(string)Times[center_bar/2]);
      //Print("Times[center_bar]/="+Times[center_bar]+"  Times[center_bar/2]="+Times[center_bar/2]);
      //--- Set the scale in units of Pips / Bar
      ObjectSetDouble(0,my_gann,OBJPROP_SCALE,10);
      //--- Set the line trend
      ObjectSetInteger(0,my_gann,OBJPROP_DIRECTION,GANN_UP_TREND);
      //--- Set the line width
      ObjectSetInteger(0,my_gann,OBJPROP_WIDTH,1);
      //--- Define the line style
      ObjectSetInteger(0,my_gann,OBJPROP_STYLE,STYLE_DASHDOT);
      //--- Set the line color
      ObjectSetInteger(0,my_gann,OBJPROP_COLOR,clrYellowGreen);
      //--- Allow the user to select an object
      ObjectSetInteger(0,my_gann,OBJPROP_SELECTABLE,true);
      //--- Select it yourself
      ObjectSetInteger(0,my_gann,OBJPROP_SELECTED,true);
      //--- Draw it on the chart
      ChartRedraw(0);
     }
  }
最后更新于