MQL4 Reference Constants, Enumerations and Structures Objects Constants Gann Objects

Gann Objects

For Gann Fan (OBJ_GANNFAN) and Gann Grid (OBJ_GANNGRID) objects you can specify two values of the ENUM_GANN_DIRECTION enumeration that sets the trend direction.





Line corresponding to the uptrend line


Line corresponding to the downward trend

To set the scale of the main line as 1x1, use function ObjectSetDouble(chart_handle, gann_object_name, OBJPROP_SCALE, scale), where:

  • chart_handle — chart window where the object is located;
  • gann_object_name — object name;
  • OBJPROP_SCALE — identifier of the "Scale" property;
  • scale — required scale in units of Pips/Bar.

Parameters of Gann Fan object

Example of creating Gann Fan:

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
      //--- Now copy data of bars visible in the chart into this array
      int times=CopyTime(NULL,0,0,bars_on_chart,Times);
         Print("Could not copy the array with the open time!");
      //--- 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
                   //--- Second anchor point to the right
      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
      //--- Set the line trend
      //--- Set the line width
      //--- Define the line style
      //--- Set the line color
      //--- Allow the user to select an object
      //--- Select it yourself
      //--- Draw it on the chart