myeatrade

MQL4 Reference

MQL4 Window functions (1)

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

 

HideTestIndicators()

void HideTestIndicators(bool hide)

The function sets a flag hiding indicators called by the Expert Advisor. After the expert has been tested and the appropriate chart opened, the flagged indicators will not be drawn in the testing chart. Every indicator called will first be flagged with the current hiding flag.

It must be noted that only those indicators can be drawn in the testing chart that are directly called from the expert under test.

Parameters:

hide - TRUE, if there is a need to hide indicators, or else FALSE.

Sample:

   HideTestIndicators(true);
   MaCurrent=iMA(NULL,0,56,0,MODE_EMA,PRICE_CLOSE,0);
   MaPrevious=iMA(NULL,0,56,0,MODE_EMA,PRICE_CLOSE,1);
   HideTestIndicators(false);

Period()

int Period()

Returns the amount of minutes determining the used period (chart timeframe).

Sample:

   Print("Period is ", Period());

RefreshRates()

void RefreshRates()

Refreshing of data in pre-defined variables and series arrays. This function is used when expert advisor has been calculating for a long time and needs data refreshing. Returns TRUE if data are refreshed, otherwise returns FALSE. The only reason for data cannot be refreshed is that they are the current data of the client terminal.

Experts and scripts operate with their own copy of history data. Data of the current symbol are copied at the first launch of the expert or script. At each subsequent launch of the expert (remember that script is executed only once and does not depend on incoming ticks), the initial copy will be updated. One or more new ticks can income while the expert or script is operating, and data can become out of date.

Sample:

   int ticket;
   while(true)
     {
      ticket=OrderSend(Symbol(),OP_BUY,1.0,Ask,3,0,0,"expert comment",255,0,CLR_NONE);
      if(ticket<=0)
        {
         int error=GetLastError();
         //---- not enough money
         if(error==134) break;
         //---- 10 seconds wait
         Sleep(10000);
         //---- refresh price data
         RefreshRates();
         break;
        }
      else
        {
         OrderSelect(ticket,SELECT_BY_TICKET);
         OrderPrint();
         break;
        }
     }

Symbol()

string Symbol()

Returns a text string with the name of the current financial instrument.

Sample:

   int total=OrdersTotal();
   for(int pos=0;pos<total;pos++)
     {
      // check selection result because the order may be closed or deleted at this time!
      if(OrderSelect(pos, SELECT_BY_POS)==false) continue;
      if(OrderType()>OP_SELL || OrderSymbol()!=Symbol()) continue;
      // performs some processing...
     }

WindowBarsPerChart()

int WindowBarsPerChart()

Function returns the amount of bars visible on the chart.

Sample:

// work with visible bars.
int bars_count=WindowBarsPerChart();
int bar=WindowFirstVisibleBar();
for(int i=0; i<bars_count; i++,bar--)
  {
   // ...
  }

WindowExpertName()

string WindowExpertName()

Returns name of the executed expert, script, custom indicator, or library, depending on the MQL4 program, from which this function has been called.

Sample:

string name=WindowExpertName();
GlobalVariablesDeleteAll(name);

WindowFind()

int WindowFind(string name)

If indicator with name was found, the function returns the window index containing this specified indicator, otherwise it returns -1.

Note: WindowFind() returns -1 if custom indicator searches itself when init() function works.

Parameters:

name - Indicator short name.

Sample:

   int win_idx=WindowFind("MACD(12,26,9)");

WindowFirstVisibleBar()

int WindowFirstVisibleBar()

The function returns the first visible bar number in the current chart window. It must be taken into consideration that price bars are numbered in the reverse order, from the last to the first one. The current bar, the latest in the price array, is indexed as 0. The oldest bar is indexed as Bars-1. If the first visible bar number is 2 or more bars less than the amount of visible bars in the chart, it means that the chart window has not been fully filled out and there is a space to the left.

Sample:

// work with visible bars.
int bars_count=WindowBarsPerChart();
int bar=WindowFirstVisibleBar();
for(int i=0; i<bars_count; i++,bar--)
  {
   // ...
  }

WindowHandle()

int WindowHandle(string symbol, int timeframe)

Returns the system window handler containing the given chart. If the chart of symbol and timeframe has not been opened by the moment of function calling, 0 will be returned.

Parameters:

symbol - symbol name.
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

Sample:

  int win_handle=WindowHandle("USDX",PERIOD_H1);
  if(win_handle!=0)
    Print("Window with USDX,H1 detected. Rates array will be copied immediately.");

WindowIsVisible()

bool WindowIsVisible(int index)

Returns TRUE if the chart subwindow is visible, otherwise returns FALSE. The chart subwindow can be hidden due to the visibility properties of the indicator placed in it.

Parameters:

index - Chart subwindow index.

Sample:

  int maywin=WindowFind("MyMACD");
  if(maywin>-1 && WindowIsVisible(maywin)==true)
    Print("window of MyMACD is visible");
  else
    Print("window of MyMACD not found or is not visible");
This article url: http://www.myeatrade.com/457/

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