//+----------------------------------------------------------------------------+//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |//+----------------------------------------------------------------------------+//| Версия : 10.05.2008 |//| Описание : Возвращает корреляцию двух рядов. |//+----------------------------------------------------------------------------+//| Параметры: |//| x - массив значений первого ряда |//| y - массив значений второго ряда |//+----------------------------------------------------------------------------+doubleCorrelation(double& x[], double& y[]){double co=0, sa=0, sb=0, sc=0, xs=0, ys=0;
inti, k=MathMin(ArraySize(x), ArraySize(y));
if(k>0){for(i=0; i<k; i++){xs+=x[i]; ys+=y[i];
}xs/=k; ys/=k;
for(i=0; i<k; i++){sa+=(x[i]-xs)*(y[i]-ys);
sb+=(x[i]-xs)*(x[i]-xs);
sc+=(y[i]-ys)*(y[i]-ys);
}sb=MathSqrt(sb*sc);
if(sb!=0)co=sa/sb;
}return(co);
}
ZS. In the trailer is a script for testing the Correlation() function.
This function returns the index of the last open position or -1. A more accurate selection of positions to be checked is defined by external parameters:
sy - Name of market instrument. If we set this parameter, the function will consider only positions of the specified instrument. The default value "" means any market instrument. NULL means the current instrument.
op - Trade operation, position type. Valid values: OP_BUY, OP_SELL or -1. The default value -1 means any position.
mn - Position identifier, MagicNumber. Default value -1 means any identifier.
//+----------------------------------------------------------------------------+//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |//+----------------------------------------------------------------------------+//| Версия : 19.02.2008 |//| Описание : Возвращает индекс последней открытой позиции или -1 |//+----------------------------------------------------------------------------+//| Параметры: |//| sy - наименование инструмента ("" - любой символ, |//| NULL - текущий символ) |//| op - операция (-1 - любая позиция) |//| mn - MagicNumber (-1 - любой магик) |//+----------------------------------------------------------------------------+intGetIndexLastPos(stringsy="", intop=-1, intmn=-1){datetimeo;
inti, k=OrdersTotal(), r=-1;
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(o<OrderOpenTime()){o=OrderOpenTime();
r=i;
}}}}}}}return(r);
}
ZS. Attached is a script to test GetIndexLastPos() function.
This function returns the lot size of the last open position or -1. A more accurate selection of positions to be checked is defined by external parameters:
sy - Name of market instrument. If you set this parameter, the function will consider only positions of the specified instrument. The default value "" means any market instrument. NULL means the current instrument.
op - Trade operation, position type. Valid values: OP_BUY, OP_SELL or -1. Default value -1 means any position.
mn - Position identifier, MagicNumber. Default value -1 means any identifier.
//+----------------------------------------------------------------------------+//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |//+----------------------------------------------------------------------------+//| Версия : 19.02.2008 |//| Описание : Возвращает размер лота последней открытой позиции или -1 |//+----------------------------------------------------------------------------+//| Параметры: |//| sy - наименование инструмента ("" - любой символ, |//| NULL - текущий символ) |//| op - операция (-1 - любая позиция) |//| mn - MagicNumber (-1 - любой магик) |//+----------------------------------------------------------------------------+doubleGetLotLastPos(stringsy="", intop=-1, intmn=-1){datetimeo;
doublel=-1;
inti, 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(o<OrderOpenTime()){o=OrderOpenTime();
l=OrderLots();
}}}}}}}return(l);
}
ZS. Attached is a script to test GetLotLastPos() function.
This function returns the index of the last position opened or -1. A more accurate selection of positions to be checked is specified by external parameters:
ZS. Attached is a script to test GetIndexLastPos() function.
What is the index ? Is it a bar number of the last position opened? Or something else?
rid писал (а): What is the index? Is it the bar number of the last open position? Or something else?
This is the sequence number of the position in the list of open positions and set orders. The numbering starts from zero and is the same for positions and orders.
Dear Igor, please help me. The problem is that I cannot find anywhere the code how to attach MA to CCI or Stoch. The buy or sell signal should be generated when this МА crosses the CCI level, e.g. +100/-100.
Maybe there is an Expert Advisor that uses the code I need?
This function returns the maximum lot size from the number of open positions. A more accurate selection of positions to be checked is specified by external parameters:
sy - Name of market instrument. If this parameter is set, the function will consider only positions of the specified symbol. The default value "" means any market instrument. NULL means the current instrument.
op - Trade operation, position type. Valid values: OP_BUY, OP_SELL or -1. The default value -1 means any position.
mn - Position identifier, MagicNumber. Default value -1 means any identifier.
//+----------------------------------------------------------------------------+//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |//+----------------------------------------------------------------------------+//| Версия : 19.02.2008 |//| Описание : Возвращает максимальный размер лота из открытых позиций |//+----------------------------------------------------------------------------+//| Параметры: |//| sy - наименование инструмента ("" - любой символ, |//| NULL - текущий символ) |//| op - операция (-1 - любая позиция) |//| mn - MagicNumber (-1 - любой магик) |//+----------------------------------------------------------------------------+doubleGetMaxLotFromOpenPos(stringsy="", intop=-1, intmn=-1){doublel=0;
inti, 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(l<OrderLots())l=OrderLots();
}}}}}}return(l);
}
ZS. In the trailer there is a script to test GetMaxLotFromOpenPos() function.
This function returns the minimum lot size from the number of open positions. A more accurate selection of positions to be checked is specified by external parameters:
sy - Name of market instrument. If this parameter is set, the function will consider only positions of the specified symbol. The default value "" means any market instrument. NULL means the current instrument.
op - Trade operation, position type. Valid values: OP_BUY, OP_SELL or -1. The default value -1 means any position.
mn - Position identifier, MagicNumber. Default value -1 means any identifier.
//+----------------------------------------------------------------------------+//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |//+----------------------------------------------------------------------------+//| Версия : 19.02.2008 |//| Описание : Возвращает минимальный размер лота из открытых позиций |//+----------------------------------------------------------------------------+//| Параметры: |//| sy - наименование инструмента ("" - любой символ, |//| NULL - текущий символ) |//| op - операция (-1 - любая позиция) |//| mn - MagicNumber (-1 - любой магик) |//+----------------------------------------------------------------------------+doubleGetMinLotFromOpenPos(stringsy="", intop=-1, intmn=-1){doublel=0;
inti, 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(l==0 || l>OrderLots())l=OrderLots();
}}}}}}return(l);
}
HH. Attached is a script to test GetMinLotFromOpenPos() function.
Dear Igor, please help me. The problem is that I cannot find anywhere the code how to attach MA to CCI or Stoch. The buy or sell signal should be generated when this МА crosses the CCI level, e.g. +100/-100.
Perhaps there is an Expert Advisor that uses the code I need?
This question is obviously not relevant. I will give you an example of such a code fragment using stochastic and MA examples in order not to distract Igor.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
The function itself:
ZS. In the trailer is a script for testing the Correlation() function.
GetIndexLastPos() function.
This function returns the index of the last open position or -1. A more accurate selection of positions to be checked is defined by external parameters:
- sy - Name of market instrument. If we set this parameter, the function will consider only positions of the specified instrument. The default value "" means any market instrument. NULL means the current instrument.
- op - Trade operation, position type. Valid values: OP_BUY, OP_SELL or -1. The default value -1 means any position.
- mn - Position identifier, MagicNumber. Default value -1 means any identifier.
ZS. Attached is a script to test GetIndexLastPos() function.The GetLotLastPos() function.
This function returns the lot size of the last open position or -1. A more accurate selection of positions to be checked is defined by external parameters:
- sy - Name of market instrument. If you set this parameter, the function will consider only positions of the specified instrument. The default value "" means any market instrument. NULL means the current instrument.
- op - Trade operation, position type. Valid values: OP_BUY, OP_SELL or -1. Default value -1 means any position.
- mn - Position identifier, MagicNumber. Default value -1 means any identifier.
ZS. Attached is a script to test GetLotLastPos() function.GetIndexLastPos() function.
This function returns the index of the last position opened or -1. A more accurate selection of positions to be checked is specified by external parameters:
ZS. Attached is a script to test GetIndexLastPos() function.What is the index ? Is it a bar number of the last position opened? Or something else?
What is the index? Is it the bar number of the last open position? Or something else?
This is the sequence number of the position in the list of open positions and set orders. The numbering starts from zero and is the same for positions and orders.
Dear Igor, please help me. The problem is that I cannot find anywhere the code how to attach MA to CCI or Stoch. The buy or sell signal should be generated when this МА crosses the CCI level, e.g. +100/-100.
Maybe there is an Expert Advisor that uses the code I need?
GetMaxLotFromOpenPos() function.
This function returns the maximum lot size from the number of open positions. A more accurate selection of positions to be checked is specified by external parameters:
- sy - Name of market instrument. If this parameter is set, the function will consider only positions of the specified symbol. The default value "" means any market instrument. NULL means the current instrument.
- op - Trade operation, position type. Valid values: OP_BUY, OP_SELL or -1. The default value -1 means any position.
- mn - Position identifier, MagicNumber. Default value -1 means any identifier.
ZS. In the trailer there is a script to test GetMaxLotFromOpenPos() function.GetMinLotFromOpenPos() function.
This function returns the minimum lot size from the number of open positions. A more accurate selection of positions to be checked is specified by external parameters:
- sy - Name of market instrument. If this parameter is set, the function will consider only positions of the specified symbol. The default value "" means any market instrument. NULL means the current instrument.
- op - Trade operation, position type. Valid values: OP_BUY, OP_SELL or -1. The default value -1 means any position.
- mn - Position identifier, MagicNumber. Default value -1 means any identifier.
HH. Attached is a script to test GetMinLotFromOpenPos() function.Dear Igor, please help me. The problem is that I cannot find anywhere the code how to attach MA to CCI or Stoch. The buy or sell signal should be generated when this МА crosses the CCI level, e.g. +100/-100.
Perhaps there is an Expert Advisor that uses the code I need?
This question is obviously not relevant. I will give you an example of such a code fragment using stochastic and MA examples in order not to distract Igor.
MA. I will keep the post for 24 hours - then I will delete it!
MA. I will keep this post for 24 hours - then I will delete it!