Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1331

 
Aleksei Stepanenko:
Sorry, got caught up in the conversation here, didn't notice...

A common theme, and your codes are always interesting...

took a lot for myself)

 
Iurii Tokman:
MakarFX:

.

 
Iurii Tokman:

The technical task is understood better in Ukrainian

I'm not at that level yet, my mother tongue is Russian :)

...but I understand it on a casual level
 
Aleksei Stepanenko:

I don't have that level yet, my first language is Russian :)

I am from the USSR... I have two mother tongues)
 
MakarFX:
I am from the USSR...I have two mother tongues)
.
 
MakarFX:
I am from the USSR... I have two mother tongues)

and we've got three, still surzhik.

 
DanilaMactep:

I'm not very good at maths - how do I calculate distance from order open to stop in the code, so I can replace sl with this one?

Anormalised the lot value like this

So, it remains to understand how to calculate the distance from the open price to the stop in the code?

The absolute value of the difference between the open and stop price should be divided by the price step.

  int sl = fabs(OrderOpenPrice()-OrderStopLoss())/_Point;

And this value sl goes into the formula.

Considering that you put a stop calculated by the ATR indicator, it is enough to

double lot =MathFloor((Free*MaxRisk/100)/(sl/_Point*LotVal)/Step)*Step; //СТРАШНАЯ ФОРМУЛА РАСЧЁТА ОБЪЁМА ЛОТА
And this will already be the normalised lot size.
 
MakarFX:

buyopening price

buy stop loss

spread

Now I understand, I just have to understand, which value I should assign to buy and sell prices.

OrderSend(Symbol(),OP_BUY,lot,Ask,slippages,Bid-sl,Bid+tp ,"ДИВЕРГЕНЦИЯ НА БАЙ АО"); // ОТКРЫВАЕМ БАЙ ОРДЕР

OrderSend(Symbol(),OP_SELL,lot,Bid,slippages,Ask+sl,Ask-tp ,"ДИВЕРГЕНЦИЯ НА СЕЛ АО"); // ОТКРКЫВВАЕМ СЕЛ ОРДЕР

In other words, I assign Ask to the buy open price, f to the sell open price I assign Bid?

 
DanilaMactep:

In the code, I open an order in the following way.

You mean I assign Ask to the buy open price and Bid to the sell open price variable?

OrderSend(Symbol(),OP_BUY,lot,Ask,slippages,Bid-sl,Bid+tp ,"ДИВЕРГЕНЦИЯ НА БАЙ АО"); // ОТКРЫВАЕМ БАЙ ОРДЕР

Judging by this function, you already know the stop loss... I don't understand what the issue is

 
Alexey Viktorov:

Divide the absolute value of the difference between the open and stop price by the price step.

and this sl value will go into the formula.

Considering that you put a stop calculated by the ATR indicator, it is enough to

And that would be the normalised lot size.

I did it by code as you advised. In the beginning of the code I have the condition to choose the type of stop - atp or fixed.

if(tip_sl==en_po_atr)
     { //ЕСЛИ ТИП СТОП ЛОССА СТОИТ ПО АТР ТО ВЫСЧИТЫВАЕМ ЕГО ИЗ АТР
     //Print("СТОП ПО АТР, ЕГО РАЗМЕР ");
     sl= iATR( NULL,PeriodForWork_sl,atr_sl_period,1);// ПОЛУЧЕНИЕ ЗНАЧЕНИЙ АТР ДЛЯ ВЫСТАВЛЕНИЯ СТОПЛОССА
      Print("СТОП ПО АТР, ЕГО РАЗМЕР "+sl);
     }
     else //ИНАЧЕ- ТО ЕСТЬ ЕСЛИ СТОП ЛОСС ФИКСИРОВАННЫЙ В ПУНКТАХ
     {
     Print("СТОП ЛОС ФИКСИРОВАННЫЙ В ПУНКТАХ");
     sl= razmer_fikc_sl*Point; // ПЕЕРМЕННОЙ СТОП ЛОССА ПРИСВАЕВАЕМ ФИКСИРОВАНОНЕ ЗНАЧЕНИЕ ПУНКТОВ И ДОМНОЖАЕМ НА ПОИНТ
     }

Then I commented my normalization and assigned it this way

     sl = fabs(OrderOpenPrice()-OrderStopLoss())/_Point;// ПРИСВОИЛ ЗНАЧЕНИЕ КАК СОВЕТОВАЛИ
     //sl= NormalizeDouble(sl,Digits());// НОРМАЛИЗАЦИЯ ЗНАЧЕНИЯ СТОП ЛОССА ДЛЯ ОТКРЫТИЯ СДЕЛКИ ТО  ЧТО БЫЛО ЗАКОМЕНТИРОВАЛ

Profit calculation is next in the code. No problems there and after calculating the profit I added the scary formula I've been advised to use.

double lot =MathFloor((Free*MaxRisk/100)/(sl/Point*LotVal)/Step)*Step; //СТРАШНАЯ ФОРМУЛА РАСЧЁТА ОБЪЁМА ЛОТА КОТОРУЮ МНЕ СОВЕТОВАЛИ

All was compiled without errors. But when I ran the test the error appears in the log, it's division by zero as far as I understand and the test is stopped. Where did I mess up here or what didn't I do right?

ERROR AT TEST START

Reason: