Questions from Beginners MQL4 MT4 MetaTrader 4 - page 21

 
bablusut:

Thanks for the reply ... So, to search orders in the trading history, we use the functionOrdersHistoryTotal, which, after discarding everything we don't need, looks like this

for(int i=OrdersHistoryTotal()-1; i>=0; i--) // - the question here is what "accTotal" meansin the function template that we discarded, and why did you take "i--" and not "i++" as in the template?
- the second functionOrderComment returns the comment of the selected order if it is selected by the previous functionOrdersHistoryTotal, takes the form

if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) //- where "i", this is "i>=0" from the previous function, and "SELECT_BY_TICKET" was replaced with "SELECT_BY_POS" and "MODE_HISTORY" was added- why?

- The third line is definition, we don't actually need to check the necessary order since we only have market orders closed by TP and SL in this history (we might have a closed pending order, but it will be rare), all other order parameters are not important to us. The only important thing is the amount of closed orders in the history will constantly increase, is it possible to make our recalculation take certain amount of the last orders, for example, 5-10, and not all of them?

- The last four lines are quite clear, the only question is about the PlaySound function, the code of which should be inserted after each"Print("..." linelike this



OrderComment returns the comment of the selected order, if it is selected by the previous functionOrdersHistoryTotal - this function doesn't select anything - it returns the total number of closed and deleted orders(The number of closed and deleted orders in the history of the current account, loaded in the client terminal. The size of the history list depends on current settings of the "Account History" tab of the terminal. Quotation from the tutorial).


accTotal in the example from the tutorial:

int i,accTotal=OrdersHistoryTotal(); - This is an int variable - taking value OrdersHistoryTotal
for(i=0;i<accTotal;i++)// How to loop through history list is not important from first to last order or vice versa, it still goes through all list in sequence.

But in the previous case, we have 1 less variable, but the request OrdersHistoryTotalis processed in every cycle.

SELECT_BY_POS - the index parameter contains the index number of the order in the list, the list itself is the second operator - MODE_HISTORY is the list of closed, MODE_TRADES - open or pending. SELECT_BY_TICKET - the ticket number is passed in the index parameter. Which should be taken somewhere before the order is selected.


- The

last four lines are generally clear, the only question is about the PlaySound function, the code of which should be inserted after each "Print("..." linein the following form:

bool PlaySound(

string payment // file name

)

; ...

Or is it also converted somehow?

Declare

bool PlaySound( in the program header - you'll get the possibility to turn on and off the sound in the set file extern bool Play = TRUE;

then what will Print print? And under what condition?

What is the point of this action? To play a sound when the order is closed and to write the comment (by TP or SL)?






 
bablusut:
Thanksto Vitalie Postolache for the help, thanks for the advice, and the information on these textbooks is probably a little late for me to study in my sixth decade, I probably can not do so much, I should have earlier, but there was no time. I'm really boring you here, sorry if that, I won't go on, I'm leaving.
I'd rather have a separate topic, I want it to work like this. I'll be interested, for example, to see different options and also to understand which of them is more correct from the standpoint of logic.
 

By the way, I also have a question.

I need to write a Spread check.

I have been using a simple request for its value and prohibition to open an order if spread exceeds the specified value.

But what has happened is that when spread is decreasing, the EA opens an order and that spread increases.

Now I cannot find the correct way to take it into account: if we add the spread to the array every tick, how big will the array get? Then again, for how long will it last?

Of course, we may not use similar values or use only smaller and bigger values, but in this case we have to reset it to zero somehow.

And most importantly, I cannot understand if I should take into account the minimum and maximum spread or an indication of its jumps.
 
struct MqlRates
  {
   datetime time;         // время начала периода
   double   open;         // цена открытия
   double   high;         // наивысшая цена за период
   double   low;          // наименьшая цена за период
   double   close;        // цена закрытия
   long     tick_volume;  // тиковый объем
   int      spread;       // спред
   long     real_volume;  // биржевой объем
  };
Can you tell me what Spread value will be saved? The state at the start of the bar opening?
 
A1exPit:
struct MqlRates
  {
   datetime time;         // время начала периода
   double   open;         // цена открытия
   double   high;         // наивысшая цена за период
   double   low;          // наименьшая цена за период
   double   close;        // цена закрытия
   long     tick_volume;  // тиковый объем
   int      spread;       // спред
   long     real_volume;  // биржевой объем
  };
Can you tell me which value of Spread will be saved? Is it the state at the beginning of the bar opening?

int spread;// spread

i.e. no

 
A1exPit:
struct MqlRates
  {
   datetime time;         // время начала периода
   double   open;         // цена открытия
   double   high;         // наивысшая цена за период
   double   low;          // наименьшая цена за период
   double   close;        // цена закрытия
   long     tick_volume;  // тиковый объем
   int      spread;       // спред
   long     real_volume;  // биржевой объем
  };
Can you tell me what Spread value will be saved? Is it the state at the beginning of the bar opening?
If requesting the current bar, then the current spread, if from the history, then at the time of closing.
 
Vitalie Postolache:
If you ask for the current bar, then the current spread, if from history, then at the time of closing.
Thank you.
 

I understand correctly, that to write data to the array, you need to assign each cell a different value array1[i] = x; indicating a specific cell number

or can the array be filled sequentially from i=0 onwards?

 
A1exPit:

I understand correctly, that to write data to the array, you need to assign each cell a different value array1[i] = x; indicating a specific cell number

or can the array be filled sequentially from i=0 onwards?

what is the difference? it seems to me that these are just two different ways
 
Renat Akhtyamov:
What's the difference? I think it's just two different paths.
I meant that when you pass data to an array, it will fill itself sequentially i.e. array1[] = x; which cell will the value of x be written to if the cell number is not explicitly specified?