Questions from Beginners MQL4 MT4 MetaTrader 4 - page 202

 
Yurij Kozhevnikov:

=

This seems to be the case, if I understand the substitution principle correctly.

Extra semicolons after the curly brackets. And it's not clear what else is being referred to.

It's a pity there's apparently no easy way to automate macro expansion to see what happens. Unless I can make up my own script.

Thank you! There's a reason there's no semicolon after while in the macro.

Macros are a good thing, but the line between good and evil, in their case, is even finer than with a woman))) You have to be very, very careful with them. And yes, in my example, not ';', but exactly else, which started to refer to if, which is in the macro, after you remove ;.

I'm very good at macros, so for a case like yours I've given up using them for about 1.5 years now, it's optimal:

inline bool CheckRead(){
   ...
}

if (!CheckRead()) return;
 

Except that I can't find anything about inline here.

And I don't know C++.

 

Good afternoon! Please help!

There is a fairly simple code to open and modify an order. The functions OrderSend, OrderSelect and OrderModify are put into a loop with a small delay between attempts. To minimize communication errors, etc.

The following strange thing happens: the order is normally opened, followed by successful modification of StopLoss and successful modification of TakeProfit. But when I set TP, StopLoss is nulled. I can't understand the reason.

Here is this part of the code:

send = 5; //maximum number of attempts to set an order

tick=0;

sendschet=0; //try counter

while(!tick && sendschet<=send)

{

tick=OrderSend(Symbol(),OP_SELL,NormalizeDouble(lot,2),Bid,150,0.0,0.0,komm,MagNum,0,Yellow);

sendschet++;

Sleep(1000); //Delay 1 second before next attempt

}

select = 5; //maximum number of attempts to select an order

slschet=0; //try counter for order selection

while(!OrderSelect(tick,SELECT_BY_TICKET) && slschet<=select)

{

slschet++;

Sleep(500); //Delay 0.5 second before next attempt

}

if(slschet<select) //tries were fewer than maximum, it means the order was successfully selected

{

modify = 5; //maximum number of attempts to modify the order

mdschet=0;

while(!OrderModify(tick,OrderOpenPrice(),NormalizeDouble(SL,Digits),OrderTakeProfit(),0,Yellow)

&& mdschet<=modify)

{

mdschet++;

Sleep(500); //Delay 0.5 second before the next attempt

}

*Here everything is fine - SL is set

mdschet=0; //reset counter before changing TP

while(!OrderModify(tick,OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(TP,Digits),0,Yellow)

&& mdschet<=modify)

{

mdschet++;

Sleep(500);

}

}

*Here TP is set normally, but SL is already equal to 0.0. So it turns out that OrderStopLoss() is equal to 0.0.

The order selection hasn't changed though.

If we add OrderSelect once again between setting SL and TP, everything seems to work. But it contradicts the logic.

Thank you in advance for your help in this matter.

 

Good afternoon!

Please help me deal with changing the size of a dynamic array.

Let's say I am setting up an array:

int DB[][8];

Then in the first subroutine in the loop, possibly several times (no questions about that -- so far it works as intended):

ushort i = 0;
ArrayResize(DB,i+1);

In the next subroutine I'll be adding elements in the first dimension in the loop. I don't know how many in advance. I know it's slower than if you declare the dimension beforehand. But I think up to 500 additions per year won't make a difference.

The question is, how do I find out the existing size of the array in this subroutine? To take it as a base size and add one new value to it.

To take ArraySize() and divide by 8? Or is there some other function that would suit me better?

Thanks in advance!

 
Oleg_Ko:

Good afternoon!

Please help me deal with changing the size of a dynamic array.

Let's say I am setting up an array:

Then in the first subroutine in the loop, possibly several times (no questions about that -- so far it works as intended):

In the next subroutine I'll be adding elements in the first dimension in the loop. I don't know how many in advance. I know it's slower than if you declare the dimension beforehand. But I think up to 500 additions per year won't make a difference.

The question is, how do I find out the existing size of the array in this subroutine? To take it as a base size and add one new value to it.

To take ArraySize() and divide by 8? Or is there some other function that would suit me better?

Thanks in advance!

ArrayRange()

Документация по MQL5: Операции с массивами / ArrayRange
Документация по MQL5: Операции с массивами / ArrayRange
  • www.mql5.com
Операции с массивами / ArrayRange - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Artyom Trishkin:

ArrayRange()

Artem, thank you.
 

Good afternoon.

Haven't traded on MT4 for a very long time, decided to try it again. Previously used the script (attached), but now it won't run, please see what has gone wrong.

Files:
RiskAdvisor.mq4  12 kb
 
Nauris Zukas:

Hello!
Is there any way to know immediately CopyHigh the number of elements of an array in any time period?

I'll answer it myself, maybe someone will come across the question through a search engine.

SeriesInfoInteger(symbol_name,timeframe,SERIES_BARS_COUNT);
 
Nauris Zukas:

I'll answer it myself, maybe someone will come across the question through a search engine.

Also Bars(), iBars()
 
Artyom Trishkin:
Also Bars(), iBars()

With Bars(), you cannot find out the number of array elements in any time period, but only in the current graph.

Reason: