myeatrade

Blog

MQL4 Execution errors

Any trading operation (functions of OrderSend, OrderClose, OrderCloseBy, OrderDelete or OrderModify) can fail, for a number of reasons, and return either negative ticket number or FALSE. One can find out about the reason for fail by calling of the GetLastError() function. Every error must be processed in a special way. The most common recommendations are given below.

Error codes returned from trade server.

Constant Value Description
ERR_NO_ERROR 0 Trade operation succeeded.
ERR_NO_RESULT 1 OrderModify attempts to replace the values already set with the same values. One or more values must be changed, then modification attempt can be repeated.
ERR_COMMON_ERROR 2 Common error. All attempts to trade must be stopped until reasons are clarified. Restart of operation system and client terminal will possibly be needed.
ERR_INVALID_TRADE_PARAMETERS 3 Invalid parameters were passed to the trading function, for example, wrong symbol, unknown trade operation, negative slippage, non-existing ticket number, etc. The program logic must be changed.
ERR_SERVER_BUSY 4 Trade server is busy. The attempt can be repeated after a rather long period of time (over several minutes).
ERR_OLD_VERSION 5 Old version of the client terminal. The latest version of the client terminal must be installed.
ERR_NO_CONNECTION 6 No connection to the trade server. It is necessary to make sure that connection has not been broken (for example, using the IsConnected function) and repeat the attempt after a certain period of time (over 5 seconds).
ERR_TOO_FREQUENT_REQUESTS 8 Requests are too frequent. The frequency of requesting must be reduced, the program logic must be changed.
ERR_ACCOUNT_DISABLED 64 The account was disabled. All attempts to trade must be stopped.
ERR_INVALID_ACCOUNT 65 The account number is invalid. All attempts to trade must be stopped.
ERR_TRADE_TIMEOUT 128 Timeout for the trade has been reached. Before retry (at least, in 1-minute time), it is necessary to make sure that trading operation has not really succeeded (a new position has not been opened, or the existing order has not been modified or deleted, or the existing position has not been closed)
ERR_INVALID_PRICE 129 Invalid bid or ask price, perhaps, unnormalized price. After 5-second (or more) delay, it is necessary to refresh data using the RefreshRates function and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed.
ERR_INVALID_STOPS 130 Stops are too close, or prices are ill-calculated or unnormalized (or in the open price of a pending order). The attempt can be repeated only if the error occurred due to the price obsolescense. After 5-second (or more) delay, it is necessary to refresh data using the RefreshRates function and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed.
ERR_INVALID_TRADE_VOLUME 131 Invalid trade volume, error in the volume granularity. All attempts to trade must be stopped, and the program logic must be changed.
ERR_MARKET_CLOSED 132 Market is closed. The attempt can be repeated after a rather long period of time (over several minutes).
ERR_TRADE_DISABLED 133 Trade is disabled. All attempts to trade must be stopped.
ERR_NOT_ENOUGH_MONEY 134 Not enough money to make an operation. The trade with the same parameters must not be repeated. After 5-second (or more) delay, the attempt can be repeated with a smaller volume, but it is necessary to make sure that there is enough money to complete the operation.
ERR_PRICE_CHANGED 135 The price has changed. The data can be refreshed without any delay using the RefreshRates function and make a retry.
ERR_OFF_QUOTES 136 No quotes. The broker has not supplied with prices or refused, for any reason (for example, no prices at the session start, unconfirmed prices, fast market). After 5-second (or more) delay, it is necessary to refresh data using the RefreshRates function and make a retry.
ERR_REQUOTE 138 The requested price has become out of date or bid and ask prices have been mixed up. The data can be refreshed without any delay using the RefreshRates function and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed.
ERR_ORDER_LOCKED 139 The order has been locked and under processing. All attempts to make trading operations must be stopped, and the program logic must be changed.
ERR_LONG_POSITIONS_ONLY_ALLOWED 140 Only buying operation is allowed. The SELL operation must not be repeated.
ERR_TOO_MANY_REQUESTS 141 Too many requests. The frequency of requesting must be reduced, the program logic must be changed.
  142 The order has been enqueued. It is not an error but an interaction code between the client terminal and the trade server. This code can be got rarely, when the disconnection and the reconnection happen during the execution of a trade operation. This code should be processed in the same way as error 128.
  143 The order was accepted by the dealer for execution. It is an interaction code between the client terminal and the trade server. It can appear for the same reason as code 142. This code should be processed in the same way as error 128.
  144 The order was discarded by the client during manual confirmation. It is an interaction code between the client terminal and the trade server.
ERR_TRADE_MODIFY_DENIED 145 Modifying has been denied since the order is too close to market and locked for possible soon execution. The data can be refreshed after more than 15 seconds using the RefreshRates function, and a retry can be made.
ERR_TRADE_CONTEXT_BUSY 146 The trade thread is busy. Retry only after the IsTradeContextBusy function has returned FALSE.
ERR_TRADE_EXPIRATION_DENIED 147 The use of pending order expiration date has been denied by the broker. The operation can only be repeated if the expiration parameter has been zeroized.
ERR_TRADE_TOO_MANY_ORDERS 148 The amount of open and pending orders has reached the limit set by the broker. New open positions and pending orders can be placed only after the existing positions or orders have been closed or deleted.
ERR_TRADE_HEDGE_PROHIBITED 149 An attempt to open a position opposite to the existing one when hedging is disabled. First the existing opposite position should be closed, all attempts of such trade operations must be stopped, or the program logic must be changed.
ERR_TRADE_PROHIBITED_BY_FIFO 150 An attempt to close a symbol position contravening the FIFO rule. First earlier existing position(s) should be closed, all attempts of such trade operations must be stopped, or the program logic must be changed.

MQL4 Trading functions (2)

A group of functions intended for trading management.

Trading functions of OrderSend, OrderClose, OrderCloseBy, OrderDelete, and OrderModify cannot be called from custom indicators.
Trading functions can be used in experts and scripts. Trading functions can be called only if the "Allow live trading" property of this particular expert is checked.

To trade from experts and scripts, only one thread was provided that was launched in the program trade context (context of automated trading from experts and scripts). This is why, if this context is occupied with an expert trading operation, another expert or script cannot call trading functions at that moment due to error 146 (ERR_TRADE_CONTEXT_BUSY). To check whether it is possible to trade or not, one has to use the IsTradeAllowed() function. To make a clear sharing of access to the trading context, one can use a semaphore on the basis of a global variable the value of which must be changed using the GlobalVariableSetOnCondition() function.

 

OrderOpenPrice()

double OrderOpenPrice()

Returns open price for the currently selected order.

Order must be first selected by the OrderSelect() function.

Sample:

  if(OrderSelect(10, SELECT_BY_POS)==true)
    Print("open price for the order 10 ",OrderOpenPrice());
  else
    Print("OrderSelect returned the error of ",GetLastError());

OrderOpenTime()

datetime OrderOpenTime()

Returns open time for the currently selected order.

Note: The order must be previously selected by the OrderSelect() function.

Sample:

  if(OrderSelect(10, SELECT_BY_POS)==true)
    Print("open time for the order 10 ",OrderOpenTime());
  else
    Print("OrderSelect returned error of ",GetLastError());

OrderPrint()

void OrderPrint()

Prints information about the selected order in the log in the following format:

ticket number; open time; trade operation; amount of lots; open price; Stop Loss; Take Profit; close time; close price; commission; swap; profit; comment; magic number; pending order expiration date.

Order must be selected by the OrderSelect() function.

Sample:

  if(OrderSelect(10, SELECT_BY_TICKET)==true)
    OrderPrint();
  else
    Print("OrderSelect failed error code is",GetLastError());

OrderProfit()

double OrderProfit()

Returns the net profit value (without swaps or commissions) for the selected order. For open positions, it is the current unrealized profit. For closed orders, it is the fixed profit.

Returns profit for the currently selected order.

Note: The order must be previously selected by the OrderSelect() function.

Sample:

  if(OrderSelect(10, SELECT_BY_POS)==true)
    Print("Profit for the order 10 ",OrderProfit());
  else
    Print("OrderSelect returned the error of ",GetLastError());

OrderSend()

int OrderSend(string symbol, int cmd, double volume, double price, 
              int slippage, double stoploss, double takeprofit, 
              string comment=NULL, int magic=0, datetime expiration=0, 
              color arrow_color=CLR_NONE)

The main function used to open a position or place a pending order.

Returns number of the ticket assigned to the order by the trade server or -1 if it fails. To get additional error information, one has to call the GetLastError() function.

Notes:

At opening of a market order (OP_SELL or OP_BUY), only the latest prices of Bid (for selling) or Ask (for buying) can be used as open price. If operation is performed with a security differing from the current one, the MarketInfo() function must be used with MODE_BID or MODE_ASK parameter for the latest quotes for this security to be obtained. Calculated or unnormalized price cannot be applied. If there has not been the requested open price in the price thread or it has not been normalized according to the amount of digits after decimal point, the error 129 (ERR_INVALID_PRICE) will be generated. If the requested open price is fully out of date, the error 138 (ERR_REQUOTE) will be generated independently on the slippage parameter. If the requested price is out of date, but present in the thread, the position will be opened at the current price and only if the current price lies within the range of price+-slippage.

StopLoss and TakeProfit levels cannot be too close to the market. The minimal distance of stop levels in points can be obtained using the MarketInfo() function with MODE_STOPLEVEL parameter. In the case of erroneous or unnormalized stop levels, the error 130 (ERR_INVALID_STOPS) will be generated.

At placing of a pending order, the open price cannot be too close to the market. The minimal distance of the pending price from the current market one in points can be obtained using the MarketInfo() function with the MODE_STOPLEVEL parameter. In case of false open price of a pending order, the error 130 (ERR_INVALID_STOPS) will be generated.

Applying of pending order expiration time can be disabled in some trade servers. In this case, when a non-zero value is specified in the expiration parameter, the error 147 (ERR_TRADE_EXPIRATION_DENIED) will be generated.

On some trade servers, the total amount of open and pending orders can be limited. If this limit has been exceeded, no new position will be opened (or no pending order will be placed) and trade server will return error 148 (ERR_TRADE_TOO_MANY_ORDERS).

Parameters:

symbol      - Symbol for trading. 
cmd         - Operation type. It can be any of the Trade operation enumeration. 
volume      - Number of lots. 
price       - Preferred price of the trade. 
slippage    - Maximum price slippage for buy or sell orders. 
stoploss    - Stop loss level. 
takeprofit  - Take profit level. 
comment     - Order comment text. Last part of the comment may be changed by server. 
magic       - Order magic number. May be used as user defined identifier. 
expiration  - Order expiration time (for pending orders only). 
arrow_color - Color of the opening arrow on the chart. If parameter is missing or has CLR_NONE value opening arrow is not drawn on the chart. 

Sample:

  int ticket;
  if(iRSI(NULL,0,14,PRICE_CLOSE,0)<25)
    {
     ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-25*Point,Ask+25*Point,"My order #2",16384,0,Green);
     if(ticket<0)
       {
        Print("OrderSend failed with error #",GetLastError());
        return(0);
       }
    }

OrdersHistoryTotal()

int OrdersHistoryTotal()

Returns the number of closed orders in the account history loaded into the terminal. The history list size depends on the current settings of the "Account history" tab of the terminal. 

Sample:

  // retrieving info from trade history
  int i,hstTotal=OrdersHistoryTotal();
  for(i=0;i<hstTotal;i++)
    {
     //---- check selection result
     if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
       {
        Print("Access to history failed with error (",GetLastError(),")");
        break;
       }
     // some work with order
    }

OrderStopLoss()

double OrderStopLoss()

Returns stop loss value for the currently selected order.

Note: The order must be previously selected by the OrderSelect() function. 

Sample:

  if(OrderSelect(ticket,SELECT_BY_POS)==true)
    Print("Stop loss value for the order 10 ", OrderStopLoss());
  else
    Print("OrderSelect failed error code is",GetLastError());

OrdersTotal()

int OrdersTotal()

Returns market and pending orders count. 

Sample:

  int handle=FileOpen("OrdersReport.csv",FILE_WRITE|FILE_CSV,"\t");
  if(handle<0) return(0);
  // write header
  FileWrite(handle,"#","open price","open time","symbol","lots");
  int total=OrdersTotal();
  // write open orders
  for(int pos=0;pos<total;pos++)
    {
     if(OrderSelect(pos,SELECT_BY_POS)==false) continue;
     FileWrite(handle,OrderTicket(),OrderOpenPrice(),OrderOpenTime(),OrderSymbol(),OrderLots());
    }
  FileClose(handle);

OrderSwap()

double OrderSwap()

Returns swap value for the currently selected order.

Note: The order must be previously selected by the OrderSelect() function. 

Sample:

  if(OrderSelect(order_id, SELECT_BY_TICKET)==true)
    Print("Swap for the order #", order_id, " ",OrderSwap());
  else
    Print("OrderSelect failed error code is",GetLastError());

OrderSymbol()

double OrderSymbol()

Returns the order symbol value for selected order.

Note: The order must be previously selected by the OrderSelect() function. 

Sample:

  if(OrderSelect(12, SELECT_BY_POS)==true)
    Print("symbol of order #", OrderTicket(), " is ", OrderSymbol());
  else
    Print("OrderSelect failed error code is",GetLastError());

OrderTakeProfit()

double OrderTakeProfit()

Returns take profit value for the currently selected order.

Note: The order must be previously selected by the OrderSelect() function. 

Sample:

  if(OrderSelect(12, SELECT_BY_POS)==true)
    Print("Order #",OrderTicket()," profit: ", OrderTakeProfit());
  else
    Print("OrderSelect() returns error - ",GetLastError());

OrderTicket()

int OrderTicket()

Returns ticket number for the currently selected order.

Note: The order must be previously selected by the OrderSelect() function. 

Sample:

  if(OrderSelect(12, SELECT_BY_POS)==true)
    order=OrderTicket();
  else
    Print("OrderSelect failed error code is",GetLastError());

OrderType()

int OrderType()

Returns order operation type for the currently selected order. It can be any of the following values:

  • OP_BUY – buying position,
  • OP_SELL – selling position,
  • OP_BUYLIMIT – buy limit pending position,
  • OP_BUYSTOP – buy stop pending position,
  • OP_SELLLIMIT – sell limit pending position,
  • OP_SELLSTOP – sell stop pending position.

Note: The order must be previously selected by the OrderSelect() function. 

Sample:

  int order_type;
  if(OrderSelect(12, SELECT_BY_POS)==true)
    {
     order_type=OrderType();
     // ...
    }
  else
    Print("OrderSelect() returned error - ",GetLastError());

MQL4 Trading functions (1)

A group of functions intended for trading management.

Trading functions of OrderSend, OrderClose, OrderCloseBy, OrderDelete, and OrderModify cannot be called from custom indicators.
Trading functions can be used in experts and scripts. Trading functions can be called only if the "Allow live trading" property of this particular expert is checked.

To trade from experts and scripts, only one thread was provided that was launched in the program trade context (context of automated trading from experts and scripts). This is why, if this context is occupied with an expert trading operation, another expert or script cannot call trading functions at that moment due to error 146 (ERR_TRADE_CONTEXT_BUSY). To check whether it is possible to trade or not, one has to use the IsTradeAllowed() function. To make a clear sharing of access to the trading context, one can use a semaphore on the basis of a global variable the value of which must be changed using the GlobalVariableSetOnCondition() function.

 

OrderSelect()

bool OrderSelect(int index, int select, int pool=MODE_TRADES)

The function selects an order for further processing. It returns TRUE if the function succeeds. It returns FALSE if the function fails. To get the error information, one has to call the GetLastError() function.

The pool parameter is ignored if the order is selected by the ticket number. The ticket number is a unique order identifier. To find out from what list the order has been selected, its close time must be analyzed. If the order close time equals to 0, the order is open or pending and taken from the terminal open positions list. One can distinguish an open position from a pending order by the order type. If the order close time does not equal to 0, the order is a closed order or a deleted pending order and was selected from the terminal history. They also differ from each other by their order types.

Parameters:

index  - Order index or order ticket depending on the second parameter. 
select - Selecting flags. It can be any of the following values:
         SELECT_BY_POS - index in the order pool,
         SELECT_BY_TICKET - index is order ticket. 
pool   - Optional order pool index. Used when the selected parameter is SELECT_BY_POS. It can be any of the following values:
         MODE_TRADES (default)- order selected from trading pool(opened and pending orders),
         MODE_HISTORY - order selected from history pool (closed and canceled order). 

Sample:

  if(OrderSelect(12470, SELECT_BY_TICKET)==true)
    {
     Print("order #12470 open price is ", OrderOpenPrice());
     Print("order #12470 close price is ", OrderClosePrice());
    }
  else
    Print("OrderSelect returned the error of ",GetLastError());

OrderClose()

bool OrderClose(int ticket, double lots, double price, int slippage, 
                color Color=CLR_NONE)

Closes opened order. If the function succeeds, the return value is true. If the function fails, the return value is false.

To get the detailed error information, call GetLastError().

Parameters:

ticket   - Unique number of the order ticket. 
lots     - Number of lots. 
price    - Preferred closing price. 
slippage - Value of the maximum price slippage in points. 
Color    - Color of the closing arrow on the chart. If the parameter is missing or has CLR_NONE value closing arrow will not be drawn on the chart. 

Sample:

  if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)
    {
     OrderClose(order_id,1,Ask,3,Red);
     return(0);
    }

OrderCloseBy()

bool OrderCloseBy(int ticket, int opposite, color Color=CLR_NONE)

Closes an opened order by another opposite opened order. If the function succeeds, the return value is true. If the function fails, the return value is false. To get the detailed error information, call GetLastError().

Parameters:

ticket   - Unique number of the order ticket. 
opposite - Unique number of the opposite order ticket.  
Color    - Color of the closing arrow on the chart. If the parameter is missing or has CLR_NONE value closing arrow will not be drawn on the chart. 

Sample:

  if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)
    {
     OrderCloseBy(order_id,opposite_id);
     return(0);
    }

OrderClosePrice()

double OrderClosePrice()

Returns close price for the currently selected order.

Note: The order must be previously selected by the OrderSelect() function. 

Sample:

  if(OrderSelect(ticket,SELECT_BY_POS)==true)
    Print("Close price for the order ",ticket," = ",OrderClosePrice());
  else
    Print("OrderSelect failed error code is",GetLastError());

OrderCloseTime()

datetime OrderCloseTime()

Returns close time for the currently selected order. If order close time is not 0 then the order selected and has been closed and retrieved from the account history. Open and pending orders close time is equal to 0.

Note: The order must be previously selected by the OrderSelect() function.

Sample:

  if(OrderSelect(10,SELECT_BY_POS,MODE_HISTORY)==true)
    {
     datetime ctm=OrderOpenTime();
     if(ctm>0) Print("Open time for the order 10 ", ctm);
     ctm=OrderCloseTime();
     if(ctm>0) Print("Close time for the order 10 ", ctm);
    }
  else
    Print("OrderSelect failed error code is",GetLastError());

OrderComment()

string OrderComment()

Returns comment for the selected order.

Note: The order must be previously selected by the OrderSelect() function.

Sample:

  string comment;
  if(OrderSelect(10,SELECT_BY_TICKET)==false)
    {
     Print("OrderSelect failed error code is",GetLastError());
     return(0);
    }
  comment = OrderComment();
  // ...

OrderCommission()

double OrderCommission()

Returns calculated commission for the currently selected order.

Note: The order must be previously selected by the OrderSelect() function.

Sample:

  if(OrderSelect(10,SELECT_BY_POS)==true)
    Print("Commission for the order 10 ",OrderCommission());
  else
    Print("OrderSelect failed error code is",GetLastError());

OrderDelete()

bool OrderDelete(int ticket, color Color=CLR_NONE)

Deletes previously opened pending order. If the function succeeds, the return value is true. If the function fails, the return value is false. To get the detailed error information, call GetLastError().

Parameters:

ticket   - Unique number of the order ticket. 
Color    - Color of the closing arrow on the chart. If the parameter is missing or has CLR_NONE value closing arrow will not be drawn on the chart. 

Sample:

  if(Ask>var1)
    {
     OrderDelete(order_ticket);
     return(0);
    }

OrderExpiration()

datetime OrderExpiration()

Returns expiration date for the selected pending order.

Note: The order must be previously selected by the OrderSelect() function. 

Sample:

  if(OrderSelect(10, SELECT_BY_TICKET)==true)
    Print("Order expiration for the order #10 is ",OrderExpiration());
  else
    Print("OrderSelect returned error of ",GetLastError());

OrderLots()

double OrderLots()

Returns amount of lots for the selected order.

Note: The order must be previously selected by the OrderSelect() function. 

Sample:

  if(OrderSelect(10,SELECT_BY_POS)==true)
    Print("lots for the order 10 ",OrderLots());
  else
    Print("OrderSelect returned error of ",GetLastError());

OrderMagicNumber()

double OrderMagicNumber()

Returns an identifying (magic) number for the currently selected order.

Note: The order must be previously selected by the OrderSelect() function. 

Sample:

  if(OrderSelect(10,SELECT_BY_POS)==true)
    Print("Magic number for the order 10 ", OrderMagicNumber());
  else
    Print("OrderSelect returned error of ",GetLastError());

OrderModify()

bool OrderModify(int ticket, double price, double stoploss, 
                 double takeprofit, datetime expiration, 
                 color arrow_color=CLR_NONE)

Modification of characteristics for the previously opened position or pending orders. If the function succeeds, the returned value will be TRUE. If the function fails, the returned value will be FALSE. To get the detailed error information, call GetLastError() function.

Notes: Open price and expiration time can be changed only for pending orders.

If unchanged values are passed as the function parameters, the error 1 (ERR_NO_RESULT) will be generated.

Pending order expiration time can be disabled in some trade servers. In this case, when a non-zero value is specified in the expiration parameter, the error 147 (ERR_TRADE_EXPIRATION_DENIED) will be generated.

Parameters:

ticket      - Unique number of the order ticket. 
price       - New open price of the pending order. 
stoploss    - New StopLoss level. 
takeprofit  - New TakeProfit level. 
expiration  - Pending order expiration time. 
arrow_color - Arrow color for StopLoss/TakeProfit modifications in the chart. If the parameter is missing or has CLR_NONE value, the arrows will not be shown in the chart. 

Sample:

  if(TrailingStop>0)
    {
     OrderSelect(12345,SELECT_BY_TICKET);
     if(Bid-OrderOpenPrice()>Point*TrailingStop)
       {
        if(OrderStopLoss()<Bid-Point*TrailingStop)
          {
           OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Blue);
           return(0);
          }
       }
    }

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())

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");

MQL4 Timeseries access

A group of functions intended for access to price data of any available symbol/period.

If data (symbol name and/or timeframe differ from the current ones) are requested from another chart, the situation is possible that the corresponding chart was not opened in the client terminal and the necessary data must be requested from the server. In this case, error ERR_HISTORY_WILL_UPDATED (4066 – the requested history data are under updating) will be placed in the last_error variable, and one will has to re-request (see example of ArrayCopySeries()).

At the testing, price data of the same symbol but of another timeframe are modelled exactly, with the exception of volumes. Volumes of another timeframe are not modelled. Price data of other symbols are not modelled, either. In all cases, the amount of bars in time series is modelled exactly.

 

iBars()

int iBars(string symbol, int timeframe)

Returns the number of bars on the specified chart.

For the current chart, the information about the amount of bars is in the predefined variable named Bars.

Parameters:

symbol    - Symbol name of the security on the data of which the indicator will be calculated. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.  

Sample:

  Print("Bar count on the 'EUROUSD' symbol with PERIOD_H1 is",iBars("EUROUSD",PERIOD_H1));

iBarShift()

int iBarShift(string symbol, int timeframe, datetime time, bool exact=false)

Search for bar by open time. The function returns bar shift with the open time specified. If the bar having the specified open time is missing, the function will return -1 or the nearest bar shift depending on the exact.

Parameters:

symbol    - Symbol name of the security on the data of which the indicator will be calculated. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.  
time      - value to find (bar's open time). 
exact     - Return mode when bar not found. false - iBarShift returns nearest. true - iBarShift returns -1. 

Sample:

  datetime some_time=D'2004.03.21 12:00';
  int      shift=iBarShift("EUROUSD",PERIOD_M1,some_time);
  Print("shift of bar with open time ",TimeToStr(some_time)," is ",shift);

iClose()

int iClose(string symbol, int timeframe, int shift)

Returns Close value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0.

For the current chart, the information about close prices is in the predefined array named Close[].

Parameters:

symbol    - Symbol name of the security on the data of which the indicator will be calculated. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.  
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,i),", ",  iOpen("USDCHF",PERIOD_H1,i),", ",
                                      iHigh("USDCHF",PERIOD_H1,i),", ",  iLow("USDCHF",PERIOD_H1,i),", ",
                                      iClose("USDCHF",PERIOD_H1,i),", ", iVolume("USDCHF",PERIOD_H1,i));

iHigh()

int iHigh(string symbol, int timeframe, int shift)

Returns High value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0.

For the current chart, the information about high prices is in the predefined array named High[].

Parameters:

symbol    - Symbol name of the security on the data of which the indicator will be calculated. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.  
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,i),", ",  iOpen("USDCHF",PERIOD_H1,i),", ",
                                      iHigh("USDCHF",PERIOD_H1,i),", ",  iLow("USDCHF",PERIOD_H1,i),", ",
                                      iClose("USDCHF",PERIOD_H1,i),", ", iVolume("USDCHF",PERIOD_H1,i));

iHighest()

int iHighest(timeframe, int type, int count=WHOLE_ARRAY, int start=0)

Returns the shift of the maximum value over a specific number of periods depending on type.

Parameters:

symbol    - Symbol name of the security on the data of which the indicator will be calculated. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.  
type      - Series array identifier. It can be any of the Series array identifier enumeration values. 
count     - Number of periods (in direction from the start bar to the back one) on which the calculation is carried out. 
start     - Shift showing the bar, relative to the current bar, that the data should be taken from. 

Sample:

  double val;
  // calculating the highest value on the 20 consequtive bars in the range
  // from the 4th to the 23rd index inclusive on the current chart
  val=High[iHighest(NULL,0,MODE_HIGH,20,4)];

iLow()

int iLow(string symbol, int timeframe, int shift)

Returns Low value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0.

For the current chart, the information about high prices is in the predefined array named Low[].

Parameters:

symbol    - Symbol name of the security on the data of which the indicator will be calculated. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.  
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,i),", ",  iOpen("USDCHF",PERIOD_H1,i),", ",
                                      iHigh("USDCHF",PERIOD_H1,i),", ",  iLow("USDCHF",PERIOD_H1,i),", ",
                                      iClose("USDCHF",PERIOD_H1,i),", ", iVolume("USDCHF",PERIOD_H1,i));

iLowest()

int iLowest(timeframe, int type, int count=WHOLE_ARRAY, int start=0)

Returns the shift of the least value over a specific number of periods depending on type.

Parameters:

symbol    - Symbol name of the security on the data of which the indicator will be calculated. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.  
type      - Series array identifier. It can be any of the Series array identifier enumeration values. 
count     - Number of periods (in direction from the start bar to the back one) on which the calculation is carried out. 
start     - Shift showing the bar, relative to the current bar, that the data should be taken from. 

Sample:

// calculating the lowest value on the 10 consequtive bars in the range
// from the 10th to the 19th index inclusive on the current chart
double val=Low[iLowest(NULL,0,MODE_LOW,10,10)];

iOpen()

int iOpen(string symbol, int timeframe, int shift)

Returns Open value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0.

For the current chart, the information about open prices is in the predefined array named Open[].

Parameters:

symbol    - Symbol name of the security on the data of which the indicator will be calculated. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.  
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,i),", ",  iOpen("USDCHF",PERIOD_H1,i),", ",
                                      iHigh("USDCHF",PERIOD_H1,i),", ",  iLow("USDCHF",PERIOD_H1,i),", ",
                                      iClose("USDCHF",PERIOD_H1,i),", ", iVolume("USDCHF",PERIOD_H1,i));

iTime()

int iTime(string symbol, int timeframe, int shift)

Returns Time value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0.

For the current chart, the information about bars open times is in the predefined array named Time[].

Parameters:

symbol    - Symbol name of the security on the data of which the indicator will be calculated. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.  
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,i),", ",  iOpen("USDCHF",PERIOD_H1,i),", ",
                                      iHigh("USDCHF",PERIOD_H1,i),", ",  iLow("USDCHF",PERIOD_H1,i),", ",
                                      iClose("USDCHF",PERIOD_H1,i),", ", iVolume("USDCHF",PERIOD_H1,i));

iVolume()

int iVolume(string symbol, int timeframe, int shift)

Returns Tick Volume value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0.

For the current chart, the information about bars tick volumes is in the predefined array named Volume[].

Parameters:

symbol    - Symbol name of the security on the data of which the indicator will be calculated. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.  
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,i),", ",  iOpen("USDCHF",PERIOD_H1,i),", ",
                                      iHigh("USDCHF",PERIOD_H1,i),", ",  iLow("USDCHF",PERIOD_H1,i),", ",
                                      iClose("USDCHF",PERIOD_H1,i),", ", iVolume("USDCHF",PERIOD_H1,i));

MQL4 Technical indicators (4)

A group of functions intended for calculation of standard and custom indicators.

For an expert (or any other MQL4 program) to take up the value of any indicator, it is not necessary that this indicator is present in the chart. The requested indicator will be loaded and calculated in the thread of the module that has called it.

Any indicator can be calculated on the data of not only current chart, but also on the data of any available symbol/period. If data (symbol name and/or timeframe differ from the current ones) are requested from another chart, the situation is possible that the corresponding chart was not opened in the client terminal and the necessary data must be requested from the server. In this case, error ERR_HISTORY_WILL_UPDATED (4066 – the requested history data are under updating) will be placed in the last_error variable, and one will has to re-request (see example of ArrayCopySeries()).

 

iMFI()

double iMFI(string symbol, int timeframe, int period, int shift)

Calculates the Money flow index and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period        - Averaging period for calculation. 
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if(iMFI(NULL,0,14,0)>iMFI(NULL,0,14,1)) return(0);

iMA()

double iMA(string symbol, int timeframe, int period, int ma_shift, 
           int ma_method, int applied_price, int shift)

Calculates the Moving average indicator and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period        - Averaging period for calculation.
ma_shift      - MA shift. Indicators line offset relate to the chart by timeframe. 
ma_method     - MA method. It can be any of the Moving Average method enumeration value. 
applied_price - Applied price. It can be any of Applied price enumeration values.  
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  AlligatorJawsBuffer[i]=iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,i);

iMAOnArray()

double iMAOnArray(double array[], int total, int period, 
                  int ma_shift, int ma_method, int shift)

Calculation of the Moving Average on data stored in a numeric array. Unlike iMA(…), the iMAOnArray function does not take data by symbol name, timeframe, the applied price. The price data must be previously prepared. The indicator is calculated from left to right. To access to the array elements as to a series array (i.e., from right to left), one has to use the ArraySetAsSeries function.

Parameters:

array[]   - Array with data. 
total     - The number of items to be counted. 0 means whole array. 
period    - Averaging period for calculation.
ma_shift  - MA shift. Indicators line offset relate to the chart by timeframe. 
ma_method - MA method. It can be any of the Moving Average method enumeration value. 
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

   double macurrent=iMAOnArray(ExtBuffer,0,5,0,MODE_LWMA,0);
   double macurrentslow=iMAOnArray(ExtBuffer,0,10,0,MODE_LWMA,0);
   double maprev=iMAOnArray(ExtBuffer,0,5,0,MODE_LWMA,1);
   double maprevslow=iMAOnArray(ExtBuffer,0,10,0,MODE_LWMA,1);
   //----
   if(maprev<maprevslow && macurrent>=macurrentslow)
     Alert("crossing up");

iOsMA()

double iOsMA(string symbol, int timeframe, 
             int fast_ema_period, int slow_ema_period, int signal_period, 
             int applied_price, int shift)

Calculates the Moving Average of Oscillator and returns its value. Sometimes called MACD Histogram in some systems.

Parameters:

symbol          - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe       - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
fast_ema_period - Number of periods for fast moving average calculation. 
slow_ema_period - Number of periods for slow moving average calculation. 
signal_period   - Number of periods for signal moving average calculation. 
applied_price   - Applied price. It can be any of Applied price enumeration values.  
shift           - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if(iOsMA(NULL,0,12,26,9,PRICE_OPEN,1)>iOsMA(NULL,0,12,26,9,PRICE_OPEN,0)) return(0);

iMACD()

double iMACD(string symbol, int timeframe, 
             int fast_ema_period, int slow_ema_period, int signal_period, 
             int applied_price, int mode, int shift)

Calculates the Moving averages convergence/divergence and returns its value. In the systems where OsMA is called MACD Histogram, this indicator is displayed as two lines. In the Client Terminal, the Moving Average Convergence/Divergence is drawn as a histogram.

Parameters:

symbol          - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe       - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
fast_ema_period - Number of periods for fast moving average calculation. 
slow_ema_period - Number of periods for slow moving average calculation. 
signal_period   - Number of periods for signal moving average calculation. 
applied_price   - Applied price. It can be any of Applied price enumeration values. 
mdoe            - Indicator line index. It can be any of the Indicators line identifiers enumeration value 
shift           - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if(iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0)>iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0)) return(0);

iOBV()

double iOBV(string symbol, int timeframe, int applied_price, int shift)

Calculates the On Balance Volume indicator and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
applied_price - Applied price. It can be any of Applied price enumeration values.  
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double val=iOBV(NULL, 0, PRICE_CLOSE, 1);

iSAR()

double iSAR(string symbol, int timeframe, double step, 
            double maximum, int shift)

Calculates the Parabolic Stop and Reverse system and returns its value.

Parameters:

symbol    - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
step      - Increment, usually 0.02.
maximum   - Maximum value, usually 0.2. 
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if(iSAR(NULL,0,0.02,0.2,0)>Close[0]) return(0);

iRSI()

double iRSI(string symbol, int timeframe, int period, 
            int applied_price, int shift)

Calculates the Relative strength index and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period        - Averaging period for calculation.
applied_price - Applied price. It can be any of Applied price enumeration values.  
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if(iRSI(NULL,0,14,PRICE_CLOSE,0)>iRSI(NULL,0,14,PRICE_CLOSE,1)) return(0);

iRSIOnArray()

double iRSIOnArray(double array[], int total, int period, int shift)

Calculation of the Relative Strength Index on data stored in a numeric array. Unlike iRSI(…), the iRSIOnArray function does not take data by symbol name, timeframe, the applied price. The price data must be previously prepared. The indicator is calculated from left to right. To access to the array elements as to a series array (i.e., from right to left), one has to use the ArraySetAsSeries function.

Parameters:

array[] - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
total   - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period  - Averaging period for calculation.
shift   - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if(iRSIOnArray(ExtBuffer,1000,14,0)>iRSI(NULL,0,14,PRICE_CLOSE,1)) return(0);

iRVI()

double iRVI(string symbol, int timeframe, int period, int mode, int shift)

Calculates the Relative Vigor index and returns its value.

Parameters:

symbol    - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period    - Number of periods for calculation. 
mdoe      - Indicator line index. It can be any of the Indicators line identifiers enumeration value 
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double val=iRVI(NULL, 0, 10,MODE_MAIN,0);

iStdDev()

double iStdDev(string symbol, int timeframe, int ma_period, 
               int ma_shift, int ma_method, int applied_price, 
               int shift)

Calculates the Standard Deviation indicator and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
ma_period     - Averaging period for calculation.
ma_shift      - MA shift. Indicators line offset relate to the chart by timeframe. 
ma_method     - MA method. It can be any of the Moving Average method enumeration value. 
applied_price - Applied price. It can be any of Applied price enumeration values.  
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double val=iStdDev(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,0);

iStdDevOnArray()

double iStdDevOnArray(double array[], int total, int ma_period, 
                      int ma_shift, int ma_method, int shift)

Calculation of the Standard Deviation indicator on data stored in a numeric array. Unlike iStdDev(…), the iStdDevOnArray function does not take data by symbol name, timeframe, the applied price. The price data must be previously prepared. The indicator is calculated from left to right. To access to the array elements as to a series array (i.e., from right to left), one has to use the ArraySetAsSeries function.

Parameters:

array[]   - Array with data. 
total     - The number of items to be counted. 0 means whole array. 
ma_period - Averaging period for calculation.
ma_shift  - MA shift. Indicators line offset relate to the chart by timeframe. 
ma_method - MA method. It can be any of the Moving Average method enumeration value. 
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double val=iStdDevOnArray(ExtBuffer,100,10,0,MODE_EMA,0);

iStochastic()

double iStochastic(string symbol, int timeframe, 
                   int %Kperiod, int %Dperiod, int slowing, 
                   int method, int price_field, 
                   int mode, int shift)

Calculates the Stochastic oscillator and returns its value.

Parameters:

symbol      - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe   - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
%Kperiod    - %K line period. 
%Dperiod    - %D line period. 
slowing     - Slowing value. 
method      - MA method. It can be any of the Moving Average method enumeration value. 
price_field - Price field parameter. Can be one of this values: 0 - Low/High or 1 - Close/Close 
mdoe        - Indicator line index. It can be any of the Indicators line identifiers enumeration value 
shift       - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if( iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,0)
     >iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,0)) 
   return(0);

iWPR()

double iWPR(string symbol, int timeframe, int period, int shift)

Calculates the Larry William’s percent range indicator and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period        - Averaging period for calculation. 
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if(iWPR(NULL,0,14,0)>iWPR(NULL,0,14,1)) return(0);

MQL4 Technical indicators (3)

A group of functions intended for calculation of standard and custom indicators.

For an expert (or any other MQL4 program) to take up the value of any indicator, it is not necessary that this indicator is present in the chart. The requested indicator will be loaded and calculated in the thread of the module that has called it.

Any indicator can be calculated on the data of not only current chart, but also on the data of any available symbol/period. If data (symbol name and/or timeframe differ from the current ones) are requested from another chart, the situation is possible that the corresponding chart was not opened in the client terminal and the necessary data must be requested from the server. In this case, error ERR_HISTORY_WILL_UPDATED (4066 – the requested history data are under updating) will be placed in the last_error variable, and one will has to re-request (see example of ArrayCopySeries()).

 

iForce()

double iForce(string symbol, int timeframe, int period, int ma_method, 
              int applied_price, int shift)

Calculates the Force index and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period        - Averaging period for calculation.
ma_method     - MA method. It can be any of Moving Average method enumeration value.  
applied_price - Applied price. It can be any of Applied price enumeration values.  
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double val=iForce(NULL, 0, 13,MODE_SMA,PRICE_CLOSE,0);

iFractals()

double iFractals(string symbol, int timeframe, int mode, int shift)

Calculates the Fractals and returns its value.

Parameters:

symbol    - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.   
mode      - Indicator line index. It can be any of the Indicators line identifiers enumeration value.  
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double val=iFractals(NULL, 0, MODE_UPPER, 3);

iGator()

double iGator(string symbol, int timeframe, 
              int jaw_period, int jaw_shift, 
              int teeth_period, int teeth_shift, 
              int lips_period, int lips_shift, 
              int ma_method, int applied_price, 
              int mode, int shift)

Gator oscillator calculation. The oscillator displays the difference between the Alligator red and blue lines (the upper histogram) and that between red and green lines (the lower histogram).

Parameters:

symbol          - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe       - Timeframe. It can be one of Timeframe enumeration values. 0 means the current chart timeframe. 
jaw_period      - Blue line averaging period (Alligator's Jaw). 
jaw_shift       - Blue line shift relative to the chart. 
teeth_period    - Red line averaging period (Alligator's Teeth). 
teeth_shift     - Red line shift relative to the chart. 
lips_period     - Green line averaging period (Alligator's Lips). 
lips_shift      - Green line shift relative to the chart. 
ma_method       - MA method. It can be any of Moving Average methods. 
applied_price   - Applied price. It can be any of Applied price enumeration values. 
mode            - Data source, identifier of a line of the indicator. It can be any of the following values:
MODE_GATORJAW   - Gator Jaw (blue) balance line,
MODE_GATORTEETH - Gator Teeth (red) balance line,
MODE_GATORLIPS  - Gator Lips (green) balance line. 
shift           - Shift relative to the current bar (number of periods back) where the data should be taken from. 

Sample:

  double jaw_val=iGator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_UPPER, 1);

iIchimoku()

double iIchimoku(string symbol, int timeframe, int tenkan_sen, 
                 int kijun_sen, int senkou_span_b, int mode, 
                 int shift)

Calculates the Ichimoku Kinko Hyo and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
tenkan_sen    - Tenkan Sen averaging period. 
kijun_sen     - Kijun Sen averaging period. 
senkou_span_b - Senkou SpanB averaging period. 
mode          - Source of data. It can be one of the Ichimoku Kinko Hyo mode enumeration.  
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double tenkan_sen=iIchimoku(NULL, 0, 9, 26, 52, MODE_TENKANSEN, 1);

iBWMFI()

double iBWMFI(string symbol, int timeframe, int shift)

Calculates the Bill Williams Market Facilitation index and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.  
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double val=iBWMFI(NULL, 0, 0);

iMomentum()

double iMomentum(string symbol, int timeframe, int period, 
                 int applied_price, int shift)

Calculates the Momentum indicator and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period        - Averaging period for calculation. 
applied_price - Applied price. It can be any of Applied price enumeration values.  
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if(iMomentum(NULL,0,12,PRICE_CLOSE,0)>iMomentum(NULL,0,20,PRICE_CLOSE,0)) return(0);

iMomentumOnArray()

double iMomentumOnArray(double array[], int total, int period, int shift)

Calculation of the Momentum indicator on data stored in a numeric array. Unlike iMomentum(…), the iMomentumOnArray function does not take data by symbol name, timeframe, the applied price. The price data must be previously prepared. The indicator is calculated from left to right. To access to the array elements as to a series array (i.e., from right to left), one has to use the ArraySetAsSeries function.

Parameters:

array[] - Array with data. 
total   - The number of items to be counted. 
period  - Averaging period for calculation.  
shift   - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if(iMomentumOnArray(mybuffer,100,12,0)>iMomentumOnArray(mubuffer,100,20,0)) return(0);

MQL4 Technical indicators (2)

A group of functions intended for calculation of standard and custom indicators.

For an expert (or any other MQL4 program) to take up the value of any indicator, it is not necessary that this indicator is present in the chart. The requested indicator will be loaded and calculated in the thread of the module that has called it.

Any indicator can be calculated on the data of not only current chart, but also on the data of any available symbol/period. If data (symbol name and/or timeframe differ from the current ones) are requested from another chart, the situation is possible that the corresponding chart was not opened in the client terminal and the necessary data must be requested from the server. In this case, error ERR_HISTORY_WILL_UPDATED (4066 – the requested history data are under updating) will be placed in the last_error variable, and one will has to re-request (see example of ArrayCopySeries()).

 

iBullsPower()

double iBullsPower(string symbol, int timeframe, int period, 
                   int applied_price, int shift)

Calculates the Bulls Power indicator and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period        - Averaging period for calculation. 
applied_price - Applied price. It can be any of Applied price enumeration values.  
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double val=iBullsPower(NULL, 0, 13,PRICE_CLOSE,0);

iCCI()

double iCCI(string symbol, int timeframe, int period, 
            int applied_price, int shift)

Calculates the Commodity channel index and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period        - Averaging period for calculation. 
applied_price - Applied price. It can be any of Applied price enumeration values.  
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if(iCCI(NULL,0,12,PRICE_TYPICAL,0)>iCCI(NULL,0,20,PRICE_TYPICAL,0)) return(0);

iCCIOnArray()

double iCCIOnArray(double array[], int total, int period, int shift)

Calculation of the Commodity Channel Index on data stored in a numeric array. Unlike iCCI(…), the iCCIOnArray function does not take data by symbol name, timeframe, the applied price. The price data must be previously prepared. The indicator is calculated from left to right. To access to the array elements as to a series array (i.e., from right to left), one has to use the ArraySetAsSeries function.

Parameters:

array[] - Array with data. 
total   - The number of items to be counted. 
period  - Averaging period for calculation.   
shift   - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if(iCCIOnArray(ExtBuffer,total,12,0)>iCCI(NULL,0,20,PRICE_TYPICAL, 0)) return(0);

iCustom()

double iCustom(string symbol, int timeframe, string name, 
               ..., 
               int mode, int shift)

Calculates the specified custom indicator and returns its value. The custom indicator must be compiled (*.EX4 file) and be in the terminal_directory\experts\indicators directory.

Parameters:

symbol    - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
name      - Custom indicator compiled program name. 
...       - Parameters set (if necessary). The passed parameters and their order must correspond with the desclaration order and the type of extern variables of the custom indicator. 
mode      - Line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions.  
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double val=iCustom(NULL, 0, "SampleInd",13,1,0);

iDeMarker()

double iDeMarker(string symbol, int timeframe, int period, int shift)

Calculates the DeMarker indicator and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period        - Averaging period for calculation.   
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double val=iDeMarker(NULL, 0, 13, 1);

iEnvelopes()

double iEnvelopes(string symbol, int timeframe, int ma_period, 
                  int ma_method, int ma_shift, int applied_price, 
                  double deviation, int mode, int shift)

Calculates the Envelopes indicator and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
ma_period     - Averaging period for calculation of the main line. 
ma_method     - MA method. It can be any of Moving Average method enumeration value. 
ma_shift      - MA shift. Indicator line offset relate to the chart by timeframe. 
applied_price - Applied price. It can be any of Applied price enumeration values. 
deviation     - Percent deviation from the main line. 
mode          - Indicator line index. It can be any of Indicators line identifiers enumeration value. 
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double val=iEnvelopes(NULL, 0, 13,MODE_SMA,10,PRICE_CLOSE,0.2,MODE_UPPER,0);

iEnvelopesOnArray()

double iEnvelopesOnArray(double array[], int total, int ma_period, 
                         int ma_method, int ma_shift, double deviation, 
                         int mode, int shift)

Calculates the Envelopes indicator and returns its value.

Parameters:

array[]   - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
total     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
ma_period - Averaging period for calculation of the main line. 
ma_method - MA method. It can be any of Moving Average method enumeration value. 
ma_shift  - MA shift. Indicator line offset relate to the chart by timeframe. 
deviation - Percent deviation from the main line. 
mode      - Indicator line index. It can be any of Indicators line identifiers enumeration value. 
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double val=iEnvelopes(NULL, 0, 13,MODE_SMA,10,PRICE_CLOSE,0.2,MODE_UPPER,0);

MQL4 Technical indicators (1)

A group of functions intended for calculation of standard and custom indicators.

For an expert (or any other MQL4 program) to take up the value of any indicator, it is not necessary that this indicator is present in the chart. The requested indicator will be loaded and calculated in the thread of the module that has called it.

Any indicator can be calculated on the data of not only current chart, but also on the data of any available symbol/period. If data (symbol name and/or timeframe differ from the current ones) are requested from another chart, the situation is possible that the corresponding chart was not opened in the client terminal and the necessary data must be requested from the server. In this case, error ERR_HISTORY_WILL_UPDATED (4066 – the requested history data are under updating) will be placed in the last_error variable, and one will has to re-request (see example of ArrayCopySeries()).

 

iAC()

double iAC(string symbol, int timeframe, int shift)

Calculates the Bill Williams’ Accelerator/Decelerator oscillator.

Parameters:

symbol    - Symbol name of the security on the data of which the indicator will be calculated. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double result=iAC(NULL, 0, 1);

iAD()

double iAD(string symbol, int timeframe, int shift)

Calculates the Accumulation/Distribution indicator and returns its value.

Parameters:

symbol    - Symbol name of the security on the data of which the indicator will be calculated. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double result=iAD(NULL, 0, 1);

iAlligator()

double iAlligator(string symbol, int timeframe, 
                  int jaw_period, int jaw_shift, 
                  int teeth_period, int teeth_shift, 
                  int lips_period, int lips_shift, 
                  int ma_method, int applied_price, 
                  int mode, int shift)

Calculates the Bill Williams’ Alligator and returns its value.

Parameters:

symbol          - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe       - Timeframe. It can be one of Timeframe enumeration values. 0 means the current chart timeframe. 
jaw_period      - Blue line averaging period (Alligator's Jaw). 
jaw_shift       - Blue line shift relative to the chart. 
teeth_period    - Red line averaging period (Alligator's Teeth). 
teeth_shift     - Red line shift relative to the chart. 
lips_period     - Green line averaging period (Alligator's Lips). 
lips_shift      - Green line shift relative to the chart. 
ma_method       - MA method. It can be any of Moving Average methods. 
applied_price   - Applied price. It can be any of Applied price enumeration values. 
mode            - Data source, identifier of a line of the indicator. It can be any of the following values:
MODE_GATORJAW   - Gator Jaw (blue) balance line,
MODE_GATORTEETH - Gator Teeth (red) balance line,
MODE_GATORLIPS  - Gator Lips (green) balance line. 
shift           - Shift relative to the current bar (number of periods back) where the data should be taken from. 

Sample:

  double jaw_val=iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORJAW, 1);

iADX()

double iADX(string symbol, int timeframe, int period, 
            int applied_price, int mode, int shift)

Calculates the Movement directional index and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period        - Averaging period for calculation. 
applied_price - Applied price. It can be any of Applied price enumeration values. 
mode          - Indicator line index. It can be any of the Indicators line identifiers enumeration value. 
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if(iADX(NULL,0,14,PRICE_HIGH,MODE_MAIN,0)>iADX(NULL,0,14,PRICE_HIGH,MODE_PLUSDI,0)) return(0);

iATR()

double iATR(string symbol, int timeframe, int period, int shift)

Calculates the Indicator of the average true range and returns its value.

Parameters:

symbol    - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period    - Averaging period for calculation.   
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if(iATR(NULL,0,12,0)>iATR(NULL,0,20,0)) return(0);

iAO()

double iAO(string symbol, int timeframe, int shift)

Calculates the Bill Williams’ Awesome oscillator and returns its value.

Parameters:

symbol    - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
shift     - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double val=iAO(NULL, 0, 2);

iBearsPower()

double iBearsPower(string symbol, int timeframe, int period, 
                   int applied_price, int shift)

Calculates the Bears Power indicator and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period        - Averaging period for calculation. 
applied_price - Applied price. It can be any of Applied price enumeration values.  
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  double val=iBearsPower(NULL, 0, 13,PRICE_CLOSE,0);

iBands()

double iBands(string symbol, int timeframe, int period, 
              int deviation, int bands_shift, int applied_price, 
              int mode, int shift)

Calculates the Bollinger Bands indicator and returns its value.

Parameters:

symbol        - Symbol the data of which should be used to calculate the indicator. NULL means the current symbol. 
timeframe     - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe. 
period        - Averaging period to calculate the main line. 
deviation     - Deviation from the main line. 
bands_shift   - The indicator shift relative to the chart. 
applied_price - Applied price. It can be any of Applied price enumeration values. 
mode          - Indicator line index. It can be any of the Indicators line identifiers enumeration value. 
shift         - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if(iBands(NULL,0,20,2,0,PRICE_LOW,MODE_LOWER,0)>Low[0]) return(0);

iBandsOnArray()

double iBandsOnArray(double array[], int total, int period, 
                     int deviation, int bands_shift, int mode, 
                     int shift)

Calculation of the Bollinger Bands indicator on data stored in a numeric array. Unlike iBands(…), the iBandsOnArray function does not take data by symbol name, timeframe, the applied price. The price data must be previously prepared. The indicator is calculated from left to right. To access to the array elements as to a series array (i.e., from right to left), one has to use the ArraySetAsSeries function.

Parameters:

array[]     - Array with data. 
total       - The number of items to be counted. 0 means the whole array. 
period      - Averaging period to calculate the main line. 
deviation   - Deviation from the main line. 
bands_shift - The indicator shift relative to the chart.  
mode        - Indicator line index. It can be any of the Indicators line identifiers enumeration value. 
shift       - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago). 

Sample:

  if(iBandsOnArray(ExtBuffer,total,2,0,MODE_LOWER,0)>Low[0]) return(0);
第 1 页,共 7 页12345...最旧 »
menu image pre-loadermenu image pre-loadermenu image pre-loadermenu image pre-loadermenu image pre-loadermenu image pre-loadermenu image pre-loader