Useful features from KimIV - page 98

 
Hello Igor! 09.05.2008 17:10 on page 17. 17 You have described the correlation function. Could you describe the correlation function using Pearson's formula
 

Hello Igor!

Could you change the e-OpenByTime EA or write a new one, or suggest a ready one :)))

I need an EA that puts the pauses in different directions at X time by N pips from the price!

 

Hello, Igor!

Do you have a script that draws horizontal line segments at X and Y pips from the signal?

Let me explain: there are Buy/Sell signals (crossing muwings, fractal, etc.).

The script sets 4 parameters, for example:

- 300 pips to Stop,

- 500 pips to Take,

- 10 bars = length of bars,

- where and how to take the signals - reference to the signal indicator, insertion of conditions for signals... This point is something to think about!

The script draws 2 lines on each Buy signal:

1) the first ("stop") lower by 300 pips from the opening price of the signal bar;

2) second ("Take") higher by 500 points from the opening price of the signal bar

3) lines start on the signal bar and end on the 10th bar.

It is the same in the case of Sell signals, only the indents of the lines are reversed.

I think such visualization will be useful for preliminary estimation of "signal-stop".

Regards, Vadim.

 

Hello Igor!

Question 1.

There is error 138 in your OpenPosition() function - ERR_REQUOTE gets paused:

if (err!=135) Sleep(1000*7.7);

Although it is recommended in the documentation to refresh data and try again at once (the price leaves, I want to open a position as soon as possible))).

May it be correct, then:

if (err!=135 && err!=138) Sleep(1000*7.7);?

Or maybe I'm missing something?

Question 2.

Please advise how to correctly specify the Slippage parameter equal to 5 points in the OrderSend() function if my brokerage company (Alpari) gives 5 decimal places.

- "50"?

- or "5"?

 
slavamir писал(а) >>

Question 1.

In your OpenPosition() function error 138 - ERR_REQUOTE gets paused:

if (err!=135) Sleep(1000*7.7);

Although it is recommended in the documentation to refresh data and try again at once (the price leaves, I want to open a position as soon as possible))).

May it be correct, then:

if (err!=135 && err!=138) Sleep(1000*7.7);?

Yes, that's ok! You can do it that way too... Thank you!

slavamir wrote >>

Question 2.

Please tell me how to correctly set Slippage parameter equal to 5 points in OrderSend() function if my brokerage company (Alpari) gives 5 decimal places.

- "50"?

- Or is it "5"?

5
 

Hello Igor,

could you please help with refining your function GetProfitFromDateInCurrency(). I need it to calculate the profit of even closed orders only. I use partial closing (splitting) of orders and the CloseBy function to close the balance of an existing order. To determine whether an even or odd number of orders has been closed, I use the formula:

double x, y; --------------------------------- Suppose
x=MathFloor(OrderLots()/0.02); --------- a. If lots 0.04/0.02=2 --- b. If lots 0.03/0.02=1
y=x*0.02; ---------- a. 2*0,02=0,04 --- б. 1*0.02=0.02
if (y==OrderLots()) ---------- а. 0.04==0.04 --- b. 0.02!=0.04
XLots=y; If equal, then XLots gets the value of y

This works (I couldn't think of a better way of dividing into even/odd and didn't get a hint when I asked).

Next, the actual function call (the one I made from yours)
ClOrdProf=GetProfitFromDateInCurrency("", -1, -1, XTime, XLots);

And my vain attempt to add to your function the condition that profit must be calculated if the lots are even:

double GetProfitFromDateInCurrency(string sy="", int op=-1, int mn=-1, datetime dt=0, double lt=-1)
{
double p=0;
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==") && (op<0 || OrderType()==op)) {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
if (mn<0 || OrderMagicNumber()==mn) {
if (dt<OrderCloseTime()) {
if (OrderLots()==lt) {
p+=OrderProfit()+OrderCommission()+OrderSwap();
}
}
}
}
}
}
}
return(p);
}

It doesn't want to count.
1. Am I wrong somewhere in the function?
2. Could the fact that orders are closed by OrdCloseBy have an effect?

 
Let's assume that the int lt parameter takes three flag values in the GetProfitFromDateInCurrency() function
-1 all orders, 0 - even lots, 1 - odd lots, then
replace
if (OrderLots()==lt) {
p+=OrderProfit()+OrderCommission()+OrderSwap()

}

to

if (lt == -1){
p+=OrderProfit
()+OrderCommission()+OrderSwap();
} else {
int test = OrderLors() * 100;
if (lt == test % 2) {
p+=OrderProfit()+OrderCommission()+OrderSwap();
} else {
p+=OrderProfit()+OrderCommission()+OrderSwap();
}
}
 
keekkenen писал(а) >>
let's say in GetProfitFromDateInCurrency() function int lt parameter takes three flag values


Thanks, your method of lot calculation by modulo is correct, I'll use it later... But here's interesting, it turns out that the function I refined works...in a way. I added Alert to see changes of "p+=" and it calculates everything correctly. But the value ClOrdProf from which we're going to take information won't show up: Alert ("ClOrdProf= ",ClOrdProf);. In the code it looks like this:
int start()
{
........................
bool
ClOrdProf=false; //logical value
........................
ClOrdProf=GetProfitFromDateInCurrency(",-1,-1,XTime,XLots); //function call
if (ClOrdProf==true)
Alert ("ClOrdProf=",ClOrdProf); - it is not updated in the log
.........................
return; //exit from start()
}
// Function for calculating the profit of closed orders
double GetProfitFromDateInCurrency(string sy="", int op=-1, int mn=-1, datetime dt=0, double lt=-1)
{
double p=0;
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==") && (op<0 || OrderType()==op)) {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
if (mn<0 || OrderMagicNumber()==mn) {
if (dt<OrderCloseTime()) {
if (OrderLots()==lt) {
p+=OrderProfit()+OrderCommission()+OrderSwap();
Alert ("p= ", p); - updated in log
}
}
}
}
}
}
}
return(p);
}
I can't figure out what's wrong...

 

Funny, isn't it, funny... funny to you and even to me...(Vladimir Semyonovich)
Originally ClOrdProf is not a bool but a double. And there should be "if (ClOrdProf>0 || ClOrdProf<0)" - the second part, starting with "or", for counting in case of negative profit...what I call "washed eye" - didn't see what lies on the surface right away myself.
Thanks to keekkenen for help in calculation of odd/even lots.
Thanks to Igor, for the possibility of upgrading his function.

 
KimIV >>:

Функция TicketNearPos().

Эта функция возвращает тикет ближайшей к рынку позиции. В качестве критерия "близости" позиции выступает минимум расстояния в пунктах между ценой открытия позиции и текущей рыночной ценой. Отбор учитываемых позиций задаётся внешними параметрами:

  • sy - Наименование рыночного инструмента. Если задать этот параметр, то функция учтёт позиции только заданного инструмента. Значение по умолчанию - "" означает любой рыночный инструмент. Значение NULL означает текущий инструмент.
  • op - Торговая операция, тип позиции. Допустимые значения: OP_BUY, OP_SELL или -1. Значение по умолчанию -1 означает любую позицию.
  • mn - Идентификатор позиции, MagicNumber. Значение по умолчанию -1 означает любой идентификатор.
ЗЫ. Во вложении скрипт для тестирования функции TicketNearPos().
if (pp == 0) 
{return (ti);}
I have noticed a bug in the TypeNearPos function when the condition is met:
Market price = open order price, then this order is no longer taken into account by this function.
I had to add this simple condition to the code.
This condition will also help in the similar functions TypeNearPos() and PriceOpenNearPos().
Reason: