Questions from Beginners MQL5 MT5 MetaTrader 5 - page 852

 

Doesn't open a trade, where's the fault?

iRSI_handle=iRSI(NULL,0,15,PRICE_OPEN);

double iRSI_buf[];

ArraySetAsSeries(iRSI_buf,true);

CopyBuffer(iRSI_handle,0,0,20,iRSI_buf);

if (iRSI_buf[0]>60)

trader.Buy(Lot);
 
Askr:

Doesn't open the trade, where's the bug?

Bug number 1: On each tick you create a NEW indicator HANDL

Shoal number 2: (probably) the Lot variable has an incorrect volume.

Flaw number 3: (probably) order filling type for CTrade class is not filled.


In general, what's in the terminal's (or tester's) log?

 
Kirill Belousov:

the amount multiplied by the loss in currency from 1 SL

And if the loss is 1, in BO for example.

I put the values into the formula, not even close to the same result.

What is wrong?

double lot=1.0;
double koef_lot=2.0;
int seriya =15;
double depo=0.0;
depo=(lot*(koef_lot*seriya-1))/(koef_lot-1);
   Comment(" depo ",depo);
 
Vladimir Karputov:

Gap number 1: On each tick you create a NEW indicator HANDL

Shoal number 2: (probably) the Lot variable has an incorrect volume.

Flaw number 3: (probably) order filling type for CTrade class is not filled.


Anyway, what's in the terminal's (or tester's) log?

This code yes was in onitics

ArraySetAsSeries(iRSI_buf,true);

CopyBuffer(iRSI_handle,0,0,20,iRSI_buf);

Moved it to onytics. I've just read the articles here - and I've understood that there is no difference for work, but it's better in onitiket. But in terms of clarity for myself, I was more convenient to do everything in 1 block, I am purely for myself while solving problems that I set myself (learning.)

The problem was with the lot - I had to put not a variable lot - and the function returnlot (because it was a function for calculating the lot).

Now I found a mistake in lot function - lot is calculated with a lot of decimal places and as a result the order cannot be opened. We need to reduce unnecessary characters and leave only 2.

//параметры
input double      StartLot=0.1;
input double      StartEquityLot=10000;

//переменные
double KoefLotEQUITY;//разница эквити
double Lot;

//функция расчета текущего торгового лота
double LotF(double Lot)
{
KoefLotEQUITY=AccountInfoDouble(ACCOUNT_EQUITY)/ StartEquityLot;
Lot=StartLot*KoefLotEQUITY;
//функция минимального возможного лота
if (Lot<0.01)
{
Lot=0.01;
}

return(Lot);
} 

NormalizeDouble and DoubleToStr so far can not work - writes that the function can not be placed in the function, and below when I put their work with the function writes error - which I can not fix.


 
Askr:

This code was in onitics.

Moved it to ontic. I just read the articles here - and from them I understood that there is no difference for work, but it's better in ontiket. But in terms of clarity for myself, I was more convenient to do everything in 1 block, I am purely for myself while solving problems that I set myself (learning.)

The problem was with the lot - it was not necessary to set a variable lot - and the function returnlot (because there was a function for calculating the lot).

Now I found a mistake in lot function - lot is calculated with a lot of decimal places and as a result the order cannot be opened. We need to reduce unnecessary characters and leave only 2.

When I paste the function NormalizeDouble and DoubleToStr I cannot do it yet - it says that the function cannot be put into a function, and when I paste them below the function writes errors that I cannot correct.


In MQL5 you need to create an indicator handle ONLY once and ONLY in OnInit. It is an axiom. You can not create an indicator handle on each tick in OnTick - it is incorrect.

The correct normalization of the lot is in the trade class CSymbolInfo::NormalizePrice

 
Vladimir Karputov:

In MQL5 you must create an indicator handle ONLY once and ONLY in OnInit. It is an axiom. You can not create an indicator handle on each tick in OnTick - this is RIGHT.

The correct normalization of the lot is in the trade class CSymbolInfo::NormalizePrice

Wrong, I don't argue with that. BUT!!! What will change if we create it on every tick??? Not even the value will change.

 
Alexey Viktorov:

Wrong, there's no arguing with that. BUT!!! What's going to change if you create on every tick??? Not even the value will change.

What's the point? Just a lot of extra work for the script, that's all.

 
Alexey Viktorov:

Wrong, no argument with that. BUT!!! What's going to change if you create on every tick??? Not even the value will change.

In a recent article I've shown that MQL5 effectively combats the vestiges of coding in MQL4 style - creation of handles on every tick: the memory is not wasted, but the operation speed is decreased at least. But I repeat: creating indicators in MQL5 in MQL4 style is not the right method. If you switch to MQL5, it means that the programming style must be rebuilt.

 
Konstantin Nikitin:

What's the point? It's just extra work for the script, that's all.

Of course there is no point. It was such a hidden question drubashke: Why resemble the neurotic, which are enough here as it is, and include Caps Lock?

 

That is, the result is the same, but of course the execution is meaningless and much busier, as I understand from what has been written.

I wish they had thought to write about it in the article, but in general it is clear that there is no reason to do the same thing several times.

But I had the goal to write to understand and work itself, not to optimize-that's after I counted.
Reason: