[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 403

 
solnce600:
What button does it use to make you smile or to cheer up?

Urri didn't know that, and I don't know the button either, but sometimes we wag our tail ... :)))
 
lottamer:

2 hours trying to write a test piece, to further test different conditions.

Doesn't work!

Please give me the error.

the point is that orders open after 2pp in their own direction.

opens sell and ends...



Everything seems to be logically correct! Only attention - all variables must be declared above the start, including the one in brackets.
 
hoz:


I'm wondering why there is a condition here?


There is a while loop, which in principle could be infinite, so measures have been taken to make it easier to take the EA off the chart or turn it off.

It's better to terminate start if something goes wrong, rather than looping. At the next tick, repeat it.

 
lottamer:

Kim's function has the time parameter ="Date and time in seconds since 1970"

I tried 2 variants.

and both give a profit not for the current day, but a full profit over the whole history....

The current day begins at the beginning of the current D1 bar (iTime (NULL, PERIOD_D1, 0)), but you are not looking for easy ways? :)))
 
hoz:

I do not quite understand the logic of writing a separate function. After all, function RefreshRates() itself serves to update data of predefined variables. And Bid and Ask are predefined variables. If function RefreshRates() updates predefined variables, why write some additional function?

There's a peculiarity there:

bool RefreshRates( )

Refresh data in predefined variables and time-series arrays. This function is used when an Expert Advisor or script has been performing calculations for a long time and needs updated data. It returns TRUE if the data is updated, otherwise FALSE. The data may not be updated only because it corresponds to the current state of the client terminal. Expert Advisors and scripts work with their own copy of historical data. The copy of data on the current symbol is created at the first launch of the Expert Advisor or script. At every next launch of the Expert Advisor (remember, the script is executed once and does not depend on incoming ticks), the initially created copy is updated. While the Expert Advisor or script is running, one or several new ticks can arrive, so the data can get out of date.

The data is not updated instantly, too. This has to be controlled.

 
Zhunko:

There's a peculiarity there:

bool RefreshRates( )

Refresh data in predefined variables and time-series arrays. This function is used when an Expert Advisor or script has been performing calculations for a long time and needs updated data. It returns TRUE if the data is updated, otherwise FALSE. The data may not be updated only because it corresponds to the current state of the client terminal. Expert Advisors and scripts work with their own copy of historical data. The copy of data on the current symbol is created at the first launch of the Expert Advisor or script. At every next launch of the Expert Advisor (remember, the script is executed once and does not depend on incoming ticks), the initially created copy is updated. While the Expert Advisor or script is running, one or several new ticks can arrive, so the data can get out of date.

The data is not updated instantly, too. This has to be controlled.


Based on the given reference, let's take the ASK price. If we run RefreshRates(), the data in the arrays of predefined variables is updated. If the ASC price has changed, then after runningRefreshRates(), ASC will take the new value. And if it does:

The data may not refresh just because it matches the current state of the client terminal.

then the ASC value has not changed. Thus, the previous ASK value will be used in the calculation, as it was, since it has not changed.

After all, ifRefreshRates() returns the value of TRU, it means it has successfully updated the data, so we don't need to check it! Don't you agree?

 
hoz:


Based on this reference, let's take the ASC price. If we run RefreshRates(), the data in the arrays of predefined variables is updated. So, if the ASC price has changed, then after runningRefreshRates() theASC will take the new value. And if it goes like this:

then the ASC value has not changed. Thus, the previous ASK value will be used in the calculations, which is what it was because it has not changed.

After all, ifRefreshRates() returns the TRU value, it has successfully updated the data and we do not need to check it! Don't you agree?

No. It can return FALSE and the data will be fresh.

The only reason the data might not be updated is because it corresponds to the current state of the client terminal.

You have to find an indication that will tell you that the data is fresh. It may be different for different tasks.
 
Zhunko:

No. It can return FALSE and the data will be fresh.

So there is an obvious bug in the documentation? And the documentation cannot be trusted?

Zhunko:

You have to find an indication which will allow you to assume that the data are fresh. It may be different for different tasks.

Suppose we are talking about the ASK price. We have two variables:

ASC - Ask value afterRefreshRates().

_ASK - value of Ask last known.

_____________________________________________________________________________________

It's hard to say. What could be the sign here? There are two possibilities:

1. The value of the predefined variable has changed. RefreshRates() returns True.

2. The value of the predefined variable has not changed. RefreshRates() returns False.

If we look at the other side, about finding a sign. There are 2 possibilities:

1. The value of the predefined variable has changed. I.e. in our case Ask = ASC

2. The value of the predefined variable has not changed. I.e. Ask = _ASK

There is either a changed value or an unchanged value, there is no other option. What do you want to do then?

 
hoz:

So there is a glaring error in the documentation? And the documentation cannot be trusted?

Let's say we are talking about the ASK price. We have 2 variables:

ASC - Ask value afterRefreshRates().

_ASK - value of Ask last known.

_____________________________________________________________________________________

It's hard to say. What could be the sign here? There are two possibilities:

1. The value of the predefined variable has changed. RefreshRates() returns True.

2. The value of the predefined variable has not changed. RefreshRates() returns False.

If we look at the other side, about finding a sign. There are 2 possibilities:

1. The value of the predefined variable has changed. I.e. in our case Ask = ASC

2. The value of the predefined variable has not changed. I.e. Ask = _ASK

There is either a changed value or an unchanged value, there is no other option. How do you want to proceed then?

The documentation is all in order. It is exactly described and that's what I pointed out to you.

TRUE is returned if the data was updated, otherwise FALSE is returned. The only reason why the data may not be updated is because it matches the current state of the client terminal.

So this function only says that new data has been received.

I don't know how you want to do the rest. I check data from server (MarketInfo()) with zero bar. I wait until they are the same. By the way, this does not guarantee that there is no "hole" in the near future history. There could easily be 1, 2 or 3 bars or several bars missing, and the zero bar will be there. Sometimes they come afterwards. Sometimes they don't.

 
Zhunko:

I.e. this function says that new data has arrived, but that's it.

So if new data came in, that's what we need, isn't it?
Zhunko:

I check the data from the server (MarketInfo()) against the zero bar. I wait for them to be the same. By the way, it doesn't guarantee that there is no "hole" in the nearest history. There could easily be 1, 2 or 3 bars or several bars missing, and the zero bar will be there. Sometimes they come later. Sometimes they do not.

Well, yes, we need the data from the 0-th bar. MarketInfo() pulls data from the zero bar, that's it. Why should we check it with something else?
Zhunko:

By the way, it does not guarantee the absence of a "hole" in the nearest history. There could easily be 1, 2 or 3 bars or several bars missing and zero will be there. Sometimes they come later. Sometimes they do not.

Even if there is a gap in the history, it will not affect the current calculations. It would have at the time there was a hole. I.e., if we obtain the current Ask, we do not really care what prices were several bars ago (I mean not formally, but concerning the current moment regarding a certain market variable, because function RefreshRates() will do the trick regarding the current moment in time on the 0-th bar!

Of course, I'm digging deep, but I want to understand how to behave better.

You, Vadim, said that I wrote the function incorrectly above, I'll duplicate it again, with added lines:

double fGet_TradePrice(int fi_price,       // Цена: 0 - Bid; 1 - Ask
                       string fs_symbol)   // валютная пара
{
   double ld_price = 0.0;
   
   switch (fi_price)
   {
         case 0:
         if (fs_symbol == Symbol())
         {
             RefreshRates();
             ld_price = Bid;
         }
         else
             ld_price = MarketInfo(fs_symbol, MODE_BID);
         
         case 1:
         if (fs_symbol == Symbol())
         {
             RefreshRates();
             ld_price = Ask;
         }
         else
             ld_price = MarketInfo(fs_symbol, MODE_ASK);
   }
   
    if (ld_price != 0)
        return (ld_price);
}

What is wrong in it in your opinion?