Useful features from KimIV - page 58

 

Hello Igor,

Could you please tell me which operator to replace this one in mql4 - OrderValue(cnt,VAL_TYPE)=OP_BUY (mql3).

Thank you in advance.

 
Can you please advise how to close an order at the closing price of the current bar? I.e. the bar closes together with the order.
 

Hello Igor.

I've looked through all the functions and operators - I can't find, and if there is one, I can't see the function that would modify all the open positions,

that would modify all open positions at once, instead of one selected position at every tick.

If you don't mind, please advise me.

 
KimIV >> :

In this thread I will post the codes of my functions in MQL4, give examples of their use, and answer questions related to their use. Each function will be published in two posts. The first post will contain the function code, the second - examples of use and short explanations. Sometimes I will attach the code of a script to the second post to actually test the function and display the results.

I will start with functions to handle orders as per Lukyanov's request in the topic "How to Run Two EAs At the Same Time" in the end.

Let the first function be the order setting function (version for MT4 tester):

Hello Igor, are you familiar with AlterTrader ? If so, could you tell me the answers to 3 or 4 of my questions ?

 
ipm писал(а) >>
Igor. Good day.
Can you draw a simple problem for you:
set at what price value the signal line will cross MACD, or in other words MACD histogram will become equal to zero.

Hello Oleg!

I haven't solved such problems in practice. And theoretically, I have a vague idea how to do it. Probably, the makdac values are taken as x and the price as x and then the function y=f(x) will represent the dependence of makdac values on the price. If it were that simple, we could invert the function y=f(x) by expressing x through ypc x=F(y). But the difficulty is that the function y=f(x) depends on more than one x. I skipped these lectures at university :-)

 
Duke3D писал(а) >>

Hello Igor,

Could you please tell me which operator to replace this one in mql4 - OrderValue(cnt,VAL_TYPE)=OP_BUY (mql3).

Thank you in advance.

Apparently it will be OrderType().

 
mozg писал(а) >>
Can you please advise how to close order at closing price of the current bar? I.e. the bar closes together with the order.
static datetime prevTimeOpen=0
if ( prevTimeOpen>0 && prevTimeOpen<Time[0]) {
  for ( цикл перебора позиций) {
    if ( выбрана позиция, которую надо закрыть) {
      OrderClose(...);
    }
  }
}
prevTimeOpen=Time[0];
 
amur писал(а) >>

Hello Igor.

I've looked through all the functions and operators - I can't find, and if there is one, I can't see the function that would modify all the open positions,

If there is, I can't see a function that would modify all open positions at once, instead of one selected at every tick.

If you do not mind - please advise.

I don't think such actions would be appropriate. After all, each position usually has individual parameters. So you select one, specific one...

And what exactly you want to modify?

 

NameDayOfWeek() function

Returns the name of the day of the week based on the number passed as a parameter:

  • ndw - Number of the day of the week. Required parameter.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 01.09.2005                                                     |
//|  Описание : Возвращает наименование дня недели                             |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    ndw - номер дня недели                                                  |
//+----------------------------------------------------------------------------+
string NameDayOfWeek(int ndw) {
  if ( ndw==0) return("Воскресенье");
  if ( ndw==1) return("Понедельник");
  if ( ndw==2) return("Вторник");
  if ( ndw==3) return("Среда");
  if ( ndw==4) return("Четверг");
  if ( ndw==5) return("Пятница");
  if ( ndw==6) return("Суббота");
}
 

Function NormalizeLot().

This function returns the normalized value of the lot being traded. Besides normalization, the function fits the lot size to the limits specified by the dealing centre (the minimum and maximum lot values and lot change step are checked). Function NormalizeLot() accepts the following parameters:

  • lo - NormalizeLot value. Required parameter.
  • ro - Rounding method. False - to the lesser side, True - to the greater side. Default value - False - to the lower side.
  • sy - Name of trade instrument. NULL or "" - current symbol. Default value - "".
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 16.05.2008                                                     |
//|  Описание : Возвращает нормализованное значение торгуемого лота.           |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    lo - нормализуемое значение лота.                                       |
//|    ro - способ округления          (   False    - в меньшую,               |
//|                                        True     - в большую сторону)       |
//|    sy - наименование инструмента   ("" или NULL - текущий символ)          |
//+----------------------------------------------------------------------------+
double NormalizeLot(double lo, bool ro= False, string sy="") {
  double l, k;
  if ( sy=="" || sy=="0") sy=Symbol();
  double ls=MarketInfo( sy, MODE_LOTSTEP);
  double ml=MarketInfo( sy, MODE_MINLOT);
  double mx=MarketInfo( sy, MODE_MAXLOT);

  if ( ml==0) ml=0.1;
  if ( mx==0) mx=100;

  if ( ls>0) k=1/ ls; else k=1/ ml;
  if ( ro) l=MathCeil( lo* k)/ k; else l=MathFloor( lo* k)/ k;

  if ( l< ml) l= ml;
  if ( l> mx) l= mx;

  return( l);
}

SZZ. Attached is a script to test NormalizeLot() function.

Files: