Useful features from KimIV - page 54

 

The TakeProfitLastPos() function.

This function returns the TakeProfit price level of the last open position or -1. The TakeProfitLastPos() function accepts the following optional parameters:

  • sy - Name of the instrument. "" - any symbol, NULL - current symbol. Default value is "".
  • op - Trade operation. Valid values: -1, OP_BUY, OP_SELL. The default value is -1 - any trade.
  • mn - Trade identifier, MagicNumber. Default value -1 - any magik.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 06.08.2008                                                     |
//|  Описание : Возвращает цену TakeProfit последней открытой позиций или -1.  |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
double TakeProfitLastPos(string sy="", int op=-1, int mn=-1) {
  datetime t;
  double   r=-1;
  int      i, k=OrdersTotal();

  if ( sy=="0") sy=Symbol();
  for ( i=0; i< k; i++) {
    if (OrderSelect( i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()== sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if ( op<0 || OrderType()== op) {
            if ( mn<0 || OrderMagicNumber()== mn) {
              if ( t<OrderOpenTime()) {
                t=OrderOpenTime();
                r=OrderTakeProfit();
              }
            }
          }
        }
      }
    }
  }
  return( r);
}
This function can be used, for example, to determine the price level of TakeProfit of the last open position for the subsequent placing of a pending order at this level.
 
how about opening the "right" lot at the right time?
 
Can you tell me if there is any way to change the lot size of a pending order in MQL4?
 
sdgg >> :
Do you know if there is any way to change the lot size of a pending order in MQL4?

No. You delete the old order and create a new one with the required volume.

 
sdgg писал (а) >>
Can you tell me if there is any way to change a pending order's lot in MQL4?

The developers didn't do it deliberately - to avoid problems!

 

Please advise how to create graphical objects in an EA that trades on two currency pairs, which mark on each chart the opening and closing positions for each currency pair. An EA which is loaded on a single chart will automatically create these marks only on that chart. Maybe there is such a function designed to be used in multi-currency EAs ?

 
RGT >> :

Please advise how to create graphical objects in an EA that trades on two currency pairs, which mark on each chart the opening and closing positions for each currency pair. An EA which is loaded on a single chart will automatically create these marks only on that chart. Maybe there is such a function designed to be used in multi-currency EAs ?

There is no such function. Objects can only be created and managed on the chart to which the EA is attached.

 

TakeProfitLastClosePos() function.

Returns the TakeProfit price level of the last closed position or -1. The TakeProfitLastClosePos() function accepts the following optional parameters:

  • sy - Name of the instrument. "" - any symbol, NULL - current symbol. Default value is "".
  • op - Trade operation. Valid values: -1, OP_BUY, OP_SELL. The default value is -1 - any trade.
  • mn - Trade identifier, MagicNumber. Default value -1 - any magik.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 20.10.2008                                                     |
//|  Описание : Возвращает цену TakeProfit последней закрытой позиций или -1.  |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
double TakeProfitLastClosePos(string sy="", int op=-1, int mn=-1) {
  datetime t;
  double   r=-1;
  int      i, k=OrdersHistoryTotal();

  if ( sy=="0") sy=Symbol();
  for ( i=0; i< k; i++) {
    if (OrderSelect( i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderSymbol()== sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if ( op<0 || OrderType()== op) {
            if ( mn<0 || OrderMagicNumber()== mn) {
              if ( t<OrderCloseTime()) {
                t=OrderCloseTime();
                r=OrderTakeProfit();
              }
            }
          }
        }
      }
    }
  }
  return( r);
}
 
KimIV >> :

TakeProfitLastClosePos() function.

Returns the TakeProfit price level of the last closed position or -1. The TakeProfitLastClosePos() function accepts the following optional parameters:

  • sy - Name of the instrument. "" - any symbol, NULL - current symbol. Default value is "".
  • op - Trade operation. Valid values: -1, OP_BUY, OP_SELL. The default value is -1 - any trade.
  • mn - Trade identifier, MagicNumber. Default value -1 - any magic number.

Is there a function that changes the take profit after some time has passed since the position was opened?

 
drm1 писал(а) >>

is there a function that changes the take profit after some time after the position has been opened?

ModifyOrder()

There, below are some examples of how to use it...