Useful features from KimIV - page 63

 
KimIV >> :

wasn't... wrote...

The ClosePosBySortLots() function.

This function closes positions in order of sorting by lot size. That is, using this function, you can close positions in ascending or descending order of lots sizes. Function ClosePosBySortLots() accepts the following optional parameters:

  • sy - Name of the trading instrument. "" - any instrument, NULL - current instrument. Default value is "".
  • op - Type of trade operation. Valid values -1 - any position, OP_BUY - buy, OP_SELL - sell. The default value is -1.
  • mn - MagicNumber, unique identifier of trade operation. Default value -1 - any magic number.
  • sd - Lot size sorting direction. Valid values MODE_ASCEND - ascending, MODE_DESCEND - descending. Default value is MODE_DESCEND.

SZY. Attached is a script to test ClosePosBySortLots() function.

Thank you very much Igor. I will pray for you:-)

 

Privat

rsi

Thanks for the examples!

Decipher this if you don't mind:

var=Close[0]
What does it do?
 

er... stop it here... I'm sorry... delete... Creativity is always welcome!

and take the link to the functions from the attachment file...

Files:
f_kimiv.rar  12 kb
 
WroC писал(а) >>

Please decode this if it's not difficult :

var=Close[0]

What do you want to eat it with?

Variable named var is assigned the value of price level of the current bar close (zero number). But since the current bar isn't finished yet, Close[0] is the same as Bid, i.e. the current price.

 

KimIV


And I kept trying to somehow use marketinfo it turns out to be even simpler ....

 
if ( ExistPositions(NULL, OP_BUY, Magic)) {
 po= PriceOpenLastPos(NULL, OP_BUY, Magic);
 if (! ExistOrders (NULL, OP_SELLSTOP, Magic+1)
 && ! ExistPositions(NULL, OP_SELL , Magic+1)) {
 pp= po- offSet*Point;
 if ( StopLoss>0) sl= pp+ StopLoss*Point; else sl=0;
 if ( TakeProfit>0) tp= pp- TakeProfit*Point; else tp=0;
 SetOrder(NULL, OP_SELLSTOP, ll, pp, sl, tp, Magic+3);

Good afternoon.
Igor, do you have a function to implement locking tactics?
On page 45 you gave an example that could be used for this.

But such an approach limits the number of open orders to 1.
If we look at the example, it would look like this
LockStep=20 from open position
LockStopLoss=10
1500 - open Buy\1480 - open sellstop

1470 - open buy\1450 - open sellstop

1460 - close sellstop 1450\open sellstop 1450
1490 - close sellstop 1480\opensellstop 1450
the given function will open two orders sellstop 1450

P.S. Many thanks for your work. There is actually a lot of information and it is very helpful, I have taken most of it on board.



 
demsan писал(а) >>
Igor, do you have a function to implement locking tactics?

No, there is no separate function. So you have to combine the existing ones and maybe add some of your own. I advise you to organize the following connection: one pair Buy/SellStop - one magician. Next pair - next magician and so on.

 

The StringLower() function.

This function converts a string to lower case. All SIGNIFICANT (large) characters become lowercase (small). The StringLower() function accepts only one obligatory parameter - the input string.

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 01.09.2005                                                     |
//|  Описание : Возвращает строку в нижнем регистре                            |
//+----------------------------------------------------------------------------+
string StringLower(string s) {
  int c, i, k=StringLen( s), n;
  for ( i=0; i< k; i++) {
    n=0;
    c=StringGetChar( s, i);
    if ( c>64 && c<91) n= c+32;     // A-Z -> a-z
    if ( c>191 && c<224) n= c+32;   // А-Я -> а-я
    if ( c==168) n=184;            //  Ё  ->  ё
    if ( n>0) s=StringSetChar( s, i, n);
  }
  return( s);
}

SZY. Attached is a script to test StringLower() function.

Files:
 

The StringUpper() function.

This function converts the string to Uppercase. All lowercase (small) characters become Uppercase (large). The StringUpper() function accepts only one mandatory parameter - the input string.

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 01.09.2005                                                     |
//|  Описание : Возвращает строку в ВЕРХНЕМ регистре                           |
//+----------------------------------------------------------------------------+
string StringUpper(string s) {
  int c, i, k=StringLen( s), n;
  for ( i=0; i< k; i++) {
    n=0;
    c=StringGetChar( s, i);
    if ( c>96 && c<123) n= c-32;    // a-z -> A-Z
    if ( c>223 && c<256) n= c-32;   // а-я -> А-Я
    if ( c==184) n=168;            //  ё  ->  Ё
    if ( n>0) s=StringSetChar( s, i, n);
  }
  return( s);
}

ZS. Attached is a script to test StringUpper().

Files:
 

The StringToArrayDouble() function.

This function splits the string into real numbers, and each number is added to the array as a separate element. As many real numbers appear in the string, the same number of elements will be added to the array. A semicolon is recognized as a separator. The StringToArrayDouble() function returns the number of array elements, and takes the following mandatory parameters:

  • st - A string of real numbers separated by a semicolon.
  • ad - Array of real numbers.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 10.10.2008                                                     |
//|  Описание : Перенос вещественных чисел из строки в массив                  |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    st - строка вещественных чисел через точку с запятой                    |
//|    ad - массив вещественных чисел                                          |
//+----------------------------------------------------------------------------+
//|  Возврат:                                                                  |
//|    Количество элементов в массиве                                          |
//+----------------------------------------------------------------------------+
int StringToArrayDouble(string st, double& ad[]) {
  int    i=0, np;
  string stp;

  ArrayResize( ad, 0);
  while (StringLen( st)>0) {
    np=StringFind( st, ";");
    if ( np<0) {
      stp= st;
      st="";
    } else {
      stp=StringSubstr( st, 0, np);
      st=StringSubstr( st, np+1);
    }
    i++;
    ArrayResize( ad, i);
    ad[ i-1]=StrToDouble( stp);
  }
  return(ArraySize( ad));
}

ZS. Attached is a script to test the StringToArrayDouble() function.