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

 
DanilaMactep:

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

Then I commented out my normalization and set it this way

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.

All was compiled without errors. But when I run the test the log shows an error, that I get division by zero and the test is stopped. Where I messed up or what I did wrong?


Just delete it.

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

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

Then I commented out my normalization and set it this way

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.

All was compiled without errors. But when I run the test the log shows an error, that I get division by zero and the test is stopped. Where I messed up here or what didn't I do right?


Just when you are given two different options, you should not apply both at once.

Are you counting sl as two different choices

sl= iATR( NULL,PeriodForWork_sl,atr_sl_period,1);// ПОЛУЧЕНИЕ ЗНАЧЕНИЙ АТР ДЛЯ ВЫСТАВЛЕНИЯ СТОПЛОССА

or

sl= razmer_fikc_sl*Point; // ПЕЕРМЕННОЙ СТОП ЛОССА ПРИСВАЕВАЕМ ФИКСИРОВАНОНЕ ЗНАЧЕНИЕ ПУНКТОВ И ДОМНОЖАЕМ НА ПОИНТ

you get the value in price values. And the formula should contain points from ... to ....

So, the stop at a distance from the price is either iATR(.........)/_Point or razmer_fikc_sl but using two different values in the function is not very convenient, therefore it's better to leave only one variant

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

And don't forget that sl should be calculated BEFORE trying to calculate the lot size.

 
sl= iATR( NULL,PeriodForWork_sl,atr_sl_period,1)/Point;// ПОЛУЧЕНИЕ ЗНАЧЕНИЙ АТР ДЛЯ ВЫСТАВЛЕНИЯ СТОПЛОССА
Be sure to
 

Make it so...

void OnTick()
  {
//---
if(tip_sl==en_po_atr)
     { //ЕСЛИ ТИП СТОП ЛОССА СТОИТ ПО АТР ТО ВЫСЧИТЫВАЕМ ЕГО ИЗ АТР
     sl= iATR( NULL,PeriodForWork_sl,atr_sl_period,1)/Point;// ПОЛУЧЕНИЕ ЗНАЧЕНИЙ АТР ДЛЯ ВЫСТАВЛЕНИЯ СТОПЛОССА
      Print("СТОП ПО АТР, ЕГО РАЗМЕР "+sl);
     }
     else //ИНАЧЕ- ТО ЕСТЬ ЕСЛИ СТОП ЛОСС ФИКСИРОВАННЫЙ В ПУНКТАХ
     {
     sl= razmer_fikc_sl; // ПЕЕРМЕННОЙ СТОП ЛОССА ПРИСВАЕВАЕМ ФИКСИРОВАНОНЕ ЗНАЧЕНИЕ ПУНКТОВ И ДОМНОЖАЕМ НА ПОИНТ
      Print("СТОП ПО АТР, ЕГО РАЗМЕР "+sl);
     }
double lot =MathFloor((Free*MaxRisk/100)/(sl*LotVal)/Step)*Step; //СТРАШНАЯ ФОРМУЛА РАСЧЁТА ОБЪЁМА ЛОТА
 
MakarFX:

Just delete it.

I fixed the line and the test started - THANK YOU very much! Just didn't understand why when getting the stoploss from iATR into a variable, why divide by the point at the end? P/S I'm having real difficulties with maths, I'm not messing around :-( But I guess the test went well and with a 100 lot put the minimum, and with a 10000 lot different all the time, so it works fine... Thanks again for the help...

 
DanilaMactep:

I have fixed the string and the test started - THANK YOU very much! Just didn't understand why when getting the stoploss from iATR into a variable, why divide by the point at the end? P/S I'm having a hard time with maths, I'm not messing around :-( But I guess the test went well and at 100 deposit the lot is minimal, and at 10000 depo it's different all the time, so it works ok... Thanks again for the help...

ATR gives out a decimal number, like 0.00120

razmer_fikc_sl is an integer.

to calculate the lot, you need points, i.e. integers

ATR/Point gives an integer number

 
It's an old topic, but I can't find a solution. How to specify the time interval (for example from 12:00 to 14:00) and open an order only once within this interval and that meets some condition (RSI<30 for example).

Or

Something analogous to Sleep: open an order on a given condition and do nothing for 2 hours. But Sleep doesn't work in the tester.
 
Порт-моне тв:
This is an old topic, but I cannot find a solution. How to specify the time slot (for example, from 12:00 to 14:00) and only once in this slot open an order satisfying some condition (RSI<30 for example).

Or

Something analogous to Sleep: open an order on a given condition and do nothing for 2 hours. But Sleep doesn't work in the tester.

first condition - time has come
second condition - rsi
third condition - there is no such order in the history at the price of opening in intervals

 

Good afternoon.

There is an indicator Elliott Wave Oscillator, it gives numerical values of variable EWO. There are positive EWOs that are above zero and negative EWOs that are below zero.

From last 100 readings of EWO, it is necessary to calculate the average value of positive EWO and separately the average value of negative EWO

I get the values from the indicator double EWO=iCustom(Symbol(),0, "Elliott Wave Oscillator",0,0);

Please advise which mql4 code can implement this in an EA ?


I managed to find the modulo average.

double avarage_EWO = 0;
for(int g=0;g<100;g++)
avarage_EWO = avarage_EWO + MathAbs( iCustom(Symbol(),0, "Elliott Wave Oscillator",0,g) ); // modulo average
avarage_EWO = avarage_EWO/100;


But how to calculate separately average positive and average negative EWO ?

Thanks !



 

Take Profit triggering

I cannot figure out how and what ORDER_REASON_TP is for,

I know howDEAL_REASON_TP works, but I don't know what is going on with orders here

Reason: