Useful features from KimIV - page 66

 
borisych писал(а) >>

...

3. Here, regression refers to a linear regression equation and its graph.

You asked about the slope of the regression equation. I showed you that it can be calculated differently. If you want what you say in point 3. You see 'Useful functions from KimIV' there are 2 types of functions, if you need a polynomial of a higher power then use this algorithm 'Random Flow Theory and FOREX'.

 

The StrTran() function.

This function replaces a substring. All occurrences of it are replaced. For example, you can replace all commas with dots or vice versa in one fell swoop. The StrSplit() function returns the resulting string and accepts the following mandatory parameters:

  • str - The string in which the substring strFrom is being replaced.
  • strFrom - substituted substring. If the substring strFrom is found in string str, it will be replaced by substring strTo.
  • strTo - Substituted substring.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 01.09.2005                                                     |
//|  описание : Замена подстроки                                               |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    str     - текстовая строка, в которой производится замена               |
//|    strFrom - заменяемая подстрока                                          |
//|    strTo   - заменяющая подстрока                                          |
//+----------------------------------------------------------------------------+
string StrTran(string str, string strFrom, string strTo) {
  int    n;
  string strOut="", strTemp;

  for ( n=0; n<StringLen( str); n++) {
    strTemp=StringSubstr( str, n, StringLen( strFrom));
    if ( strTemp== strFrom) {
      strOut=StringConcatenate( strOut, strTo);
      n= n+StringLen( strFrom)-1;
    } else strOut=StringConcatenate( strOut, StringSubstr( str, n, 1));
  }
  return( strOut);
}
 

Examples of how to use the StrTran() function.

  1. Replacing a decimal point with a comma:
    string s=DoubleToStr(Close[1], Digits);
    Print( s);
    s= StrTran( s, ".", ",");
    Print( s);
  2. Removing spaces
    string s="1 2 3 4 5 6 7 8";
    Print( s, " ", StrToInteger( s));
    s= StrTran( s, " ", "");
    Print( s, " ", StrToInteger( s));
  3. Word replacement
    string s="листья жёлтые весной";
    Print( s);
    s= StrTran( s, "весной", "осенью");
    Print( s);

Results of the examples execution:

ZY. Attached is a script to test the StrTran() function.

Files:
 

Updated list of functions:

Files:
f_kimiv.rar  12 kb
 
zhuki писал(а) >>
..
If you allow me to suggest Function which shows anything in the shortcut of taskbar .
I use it to monitor EAs at work without opening the terminal (lots of prying eyes).

For this purpose I have made a separate program for my time - http://www.miraxem.com/rqids.htm


The Forex trader's calculator automatically calculates current profit/loss on open positions and profit/loss on partial closing or overturn of a position.

Real time quotes and charts for 12 currency pairs

It is displayed as a bar on top of all the windows and shows the current quote for the selected currency pairs, profit/loss points and a news calendar with a timer that gives a signal before important events.

 
KimIV писал(а) >>
ah... Well, if in principle, you could use an array passed by reference. Then the number of parameters returned would be limited by the size of the array.

Ahh... How's that?

"Arguments(formal parameters) are passed by value, i.e. each expression xl, . . ., xn is calculated and the value is passed to function...."
Example from the help

int start()
  {
   double some_array[4]={0.3, 1.4, 2.5, 3.6};
   double a= linfunc( some_array, 10.5, 8);
   //...
  }
double linfunc(double x[], double a, double b)
  {
   return ( a* x[0] + b);
  }
And if you try to assign x[0]=999 to a function, it will crash on compilation as I recall.
'x' - array item cannot be assigned

 
KimIV писал(а) >>
[...]
These are trade operations OP_BUY and OP_SELL, while the orders are trade operations OP_BUYLIMIT, OP_BUYSTOP, OP_SELLLIMIT and OP_SELLSTOP as I understand them. I open positions and I set orders. And what do you open? The NumberOfOrders() function is designed to work with orders.

Actually it shouldn't make a difference. It should work with positions as well.
The function compares ot=OrderType
();

and OrderType()
"Returns the operation type of the currently selected order. It can be one of the following values:
OP_BUY - buy position,
OP_SELL - sell position,
...

 
diakin писал(а) >>
Ahh... How's that?

I meant literally the following:

void start()
{
  double some_array[];
  string st="";
  linfunc( some_array);
  for (int i=0; i<ArraySize( some_array); i++)
  {
    st=StringConcatenate( st, "some_array[", i, "]=", some_array[ i], "\n");
  }
  Comment( st);
}
void linfunc(double& x[])
{
  ArrayResize( x, 7);
  for (int i=0; i<ArraySize( x); i++)
  {
    x[ i]=0.7*( i+0.1);
  }
}

diakin wrote >>
x' - array item cannot be assigned

instead of:

double linfunc(double x[], double a, double b)

you have to

double linfunc(double& x[], double a, double b)
 
diakin писал(а) >>
Actually it shouldn't make a difference. Should work with positions as well.

The division into positions and orders is artificial. It was invented by me for my own personal convenience. It is based on the following differences:

1. The open/set price of an order can be changed (OrderOpenPrice()), while the position cannot be changed.

An order must be deleted (OrderDelete()), whereas a position must be closed (OrderClose()).

3. You can change the order lot size (comment, magic number) without affecting the deposit. Delete the old order and set a new one with the new lot size (comment, magic number). If you do the same with the position, there will be a loss equal to the spread multiplied by the lot size and the point value.

4. An order has a lifetime, but a position does not.

 
KimIV писал(а) >>

I meant literally the following:

instead of:

.

Thank you! Now I'll know that you can do it by reference too...

Why should the MQLQLQL helper write in one section that parameters are passed by value and in another that "it's possible to pass them by reference" ....?

omg!

As for the orders, I've read further what the problem is (>1 && <6), i.e. OP_BUY, OP_SELL do not belong here.

By the way, the magic number cannot be changed via OrderModify(). Or did I miss something again? ;-()

Reason: