myeatrade

MQL4 Reference

MQL4 Window functions (2)

A group of functions intended for working with the current chart window.

 

WindowOnDropped()

int WindowOnDropped()

Returns window index where expert, custom indicator or script was dropped. This value is valid if the expert, custom indicator or script was dropped by mouse.

Note: For custom indicators being initialized (call from the init() function), this index is not defined.

The returned index is the number of window (0-chart main menu, subwindows of indicators are numbered starting from 1) where the custom indicator is working. A custom indicator can create its own new subwindow during its work, and the number of this subwindow will differ from that of the window where the indicator was really dropped in.

See also WindowXOnDropped(), WindowYOnDropped().

Sample:

if(WindowOnDropped()!=0)
  {
   Print("Indicator 'MyIndicator' must be applied to main chart window!");
   return(false);
  }

WindowPriceMax()

double WindowPriceMax(int index=0)

Returns maximal value of the vertical scale of the specified subwindow of the current chart (0-main chart window, the indicators’ subwindows are numbered starting from 1). If the subwindow index has not been specified, the maximal value of the price scale of the main chart window is returned.

See also WindowPriceMin(), WindowFirstVisibleBar(), WindowBarsPerChart().

Parameters:

index - Chart subwindow index (0 - main chart window). 

Sample:

double   top=WindowPriceMax();
double   bottom=WindowPriceMin();
datetime left=Time[WindowFirstVisibleBar()];
int      right_bound=WindowFirstVisibleBar()-WindowBarsPerChart();
if(right_bound<0) right_bound=0;
datetime right=Time[right_bound]+Period()*60;
//----
ObjectCreate("Padding_rect",OBJ_RECTANGLE,0,left,top,right,bottom);
ObjectSet("Padding_rect",OBJPROP_BACK,true);
ObjectSet("Padding_rect",OBJPROP_COLOR,Blue);
WindowRedraw();

WindowPriceMin()

double WindowPriceMin(int index=0)

Returns minimal value of the vertical scale of the specified subwindow of the current chart (0-main chart window, the indicators’ subwindows are numbered starting from 1). If the subwindow index has not been specified, the minimal value of the price scale of the main chart window is returned.

See also WindowPriceMax(), WindowFirstVisibleBar(), WindowBarsPerChart().

Parameters:

index - Chart subwindow index (0 - main chart window). 

Sample:

double   top=WindowPriceMax();
double   bottom=WindowPriceMin();
datetime left=Time[WindowFirstVisibleBar()];
int      right_bound=WindowFirstVisibleBar()-WindowBarsPerChart();
if(right_bound<0) right_bound=0;
datetime right=Time[right_bound]+Period()*60;
//----
ObjectCreate("Padding_rect",OBJ_RECTANGLE,0,left,top,right,bottom);
ObjectSet("Padding_rect",OBJPROP_BACK,true);
ObjectSet("Padding_rect",OBJPROP_COLOR,Blue);
WindowRedraw();

WindowPriceOnDropped()

double WindowPriceOnDropped()

Returns the price part of the chart point where expert or script was dropped. This value is only valid if the expert or script was dropped by mouse.

Note: For custom indicators, this value is undefined.

Sample:

  double   drop_price=WindowPriceOnDropped();
  datetime drop_time=WindowTimeOnDropped();
  //---- may be undefined (zero)
  if(drop_time>0)
    {
     ObjectCreate("Dropped price line", OBJ_HLINE, 0, drop_price);
     ObjectCreate("Dropped time line", OBJ_VLINE, 0, drop_time);
    }

WindowRedraw()

void WindowRedraw()

Redraws the current chart forcedly. It is normally used after the objects properties have been changed.

Sample:

  //---- set new properties for some objects
  ObjectMove(object_name1, 0, Time[index], price);
  ObjectSet(object_name1, OBJPROP_ANGLE, angle*2);
  ObjectSet(object_name1, OBJPROP_FONTSIZE, fontsize);
  ObjectSet(line_name, OBJPROP_TIME2, time2);
  ObjectSet(line_name, OBJPROP_ANGLE, line_angle);
  //---- now redraw all
  WindowRedraw();

WindowScreenShot()

bool WindowScreenShot(string filename, int size_x, int size_y, 
                      int start_bar=-1, int chart_scale=-1, 
                      int chart_mode=-1)

Saves current chart screen shot as a GIF file. Returns FALSE if it fails. To get the error code, one has to use the GetLastError() function.

The screen shot is saved in the terminal_dir\experts\files (terminal_dir\tester\files in case of testing) directory or its subdirectories.

Parameters:

filename    - Screen shot file name. 
size_x      - Screen shot width in pixels. 
size_y      - Screen shot height in pixels. 
start_bar   - Index of the first visible bar in the screen shot. If 0 value is set, the current first visible bar will be shot. If no value or negative value has been set, the end-of-chart screen shot will be produced, indent being taken into consideration. 
chart_scale - Horizontal chart scale for screen shot. Can be in the range from 0 to 5. If no value or negative value has been set, the current chart scale will be used. 
chart_mode  - Chart displaying mode. It can take the following values: CHART_BAR (0 is a sequence of bars), CHART_CANDLE (1 is a sequence of candlesticks), CHART_LINE (2 is a close prices line). If no value or negative value has been set, the chart will be shown in its current mode. 

Sample:

  int lasterror=0;
  //---- tester has closed one or more trades
  if(IsTesting() && ExtTradesCounter<TradesTotal())
    {
     //---- make WindowScreenShot for further checking
     if(!WindowScreenShot("shots\\tester"+ExtShotsCounter+".gif",640,480))
        lasterror=GetLastError();
     else ExtShotsCounter++;
     ExtTradesCounter=TradesTotal();
    }

WindowTimeOnDropped()

datetime WindowTimeOnDropped()

Returns the time part of the chart point where expert or script was dropped. This value is only valid if the expert or script was dropped by mouse.

Note: For custom indicators, this value is undefined.

Sample:

  double   drop_price=WindowPriceOnDropped();
  datetime drop_time=WindowTimeOnDropped();
  //---- may be undefined (zero)
  if(drop_time>0)
    {
     ObjectCreate("Dropped price line", OBJ_HLINE, 0, drop_price);
     ObjectCreate("Dropped time line", OBJ_VLINE, 0, drop_time);
    }

WindowsTotal()

int WindowsTotal()

Returns count of indicator windows on the chart (including main chart).

Sample:

Print("Windows count = ", WindowsTotal());

WindowXOnDropped()

int WindowXOnDropped()

Returns the value at X axis in pixels for the chart window client area point at which the expert or script was dropped. The value will be true only if the expert or script were moved with the mouse ("Drag’n’Drop") technique.

See also WindowYOnDropped(), WindowOnDropped().

Sample:

Print("Expert dropped point x=",WindowXOnDropped()," y=",WindowYOnDropped());

WindowYOnDropped()

int WindowYOnDropped()

Returns the value at Y axis in pixels for the chart window client area point at which the expert or script was dropped. The value will be true only if the expert or script were moved with the mouse ("Drag’n’Drop") technique.

See also WindowXOnDropped(), WindowPriceOnDropped(), WindowOnDropped().

Sample:

Print"Expert was attached to the window in the point x=",WindowXOnDropped()," y=",WindowYOnDropped())
This article url: http://www.myeatrade.com/458/

Please login to post comment, if you haven't account you can register free