Errors, bugs, questions - page 1554

 
-Aleks-:

Since I didn't get an answer in the other thread, I'll repeat the question here, maybe this will help

"

Can you please tell me what my mistake is.

for(int i=0;i<N_Sell;i++) printf("OpenSellTime[%d] = %G",i,TimeToString(OpenSellTime[i],TIME_DATE|TIME_MINUTES)," PriceOpenSell[%d] = %G",i,PriceOpenSell[i]);

The date from OpenSellTime array is not printed and not the second part of expression - PriceOpenSell.

And, can't find aboutprintf commandslike%G and%d.

"

Although, any C tutorial would be good for you as well.
 
Alexey Kozitsyn:
Although, any C tutorial would work for you as well.

Thanks for the reply, but the link is confusing... I can't figure it out right away - I saw this text in the help before I started posting to the forum.

If I understand correctly, %d is to ignore zeros, if any, while %G is to output a value without cutting off zeros? I'm not an idiot, but I can't understand the help and without understanding I can't understand why my string doesn't work properly...

 
-Aleks-:

Thanks for the reply, but the link is confusing... I can't figure it out right away - I saw this text in the help before I started posting to the forum.

If I understand it correctly, %d is to ignore zeros, if any, while %G is to output value without cutting off zeros? I'm not stupid, but I can't understand the help, and if I don't understand it I can't understand why my string doesn't work properly...

I don't use this function in my work, but I don't think it's hard to perform simple experiments yourself.
 
-Aleks-:

Thanks for the reply, but the link is confusing... I can't figure it out right away - I saw this text in the help before I started posting to the forum.

If I understand it correctly, %d is to ignore zeros, if any, while %G is to output value without cutting off zeros? I'm not stupid, but I can't understand the help, and if I don't understand it, I can't understand why my string doesn't work properly...

Read here.
 
Alexey Kozitsyn:
I do not use this function in my work, but I think you may easily perform simple experiments yourself.

But I do - I've looked it up and use it, but I can't figure out exactly the syntax, because it doesn't fit the specification

%[flags][width][.precision][{h | l | ll | I32 | I64}]type

It is not mentioned in the help file that not all parameters may be used. And, most importantly, it is not clear where I have an error in syntax, maybe if they would point it out to me, I would understand the matter better.

 
Artyom Trishkin:
Read it here.

Thank you. Read through it cursorily, looking for the right information - it turns out that the first part is a template and I got it wrong... right?

Like, you need to specify the places where the variables will be, in my case it's an index of the array, time and number of double type, and then the variables themselves. From the logic of the article, it should look like this

for(int i=0;i<N_Sell;i++) printf("OpenSellTime[%d] = %G, PriceOpenSell[%d] = %G",i,TimeToString(OpenSellTime[i],TIME_DATE|TIME_MINUTES),i,PriceOpenSell[i]);

Or is it wrong again?

 
-Aleks-:

Thank you. Read through it cursorily, looking for the right information - it turns out that the first part is a template and I made it up wrong... right?

Like, you need to specify the places where the variables will be, in my case it's an index of the array, time and number of double type, and then the variables themselves. From the logic of the article, it should look like this

for(int i=0;i<N_Sell;i++) printf("OpenSellTime[%d] = %G, PriceOpenSell[%d] = %G",i,TimeToString(OpenSellTime[i],TIME_DATE|TIME_MINUTES),i,PriceOpenSell[i]);

Or is it wrong again?

Well, it's very clearly written there about the template - the places where variables are inserted are marked with a % sign in the template. The whole template is enclosed in inverted commas. Then, after the template itself, comma separated variables are listed that are specified in the template. In order from left to right in the order in which they are written in the template.

There are also all the specifications for the different types of variables and their formatting. Just do not glance through it, starting with the heading"Formatting of strings on the template".

 
Artyom Trishkin:

Well, it's very clear about the template - the places where variables are inserted are indicated by a % sign in the template. The whole template is enclosed in inverted commas. Then, after the template itself, the variables in the template are listed, separated by commas. In order from left to right in the order in which they are written in the template.

There are also all the specifications for the different types of variables and their formatting. Just read without glancing, starting with the heading"Formatting strings by template".

That's how I wrote it - in quotes the template and then in order the variables, what's wrong?
 
-Aleks-:
That's how I wrote it - in inverted commas the template and then the variables in order, what's wrong?

"OpenSellTime[%index must be entered here] = %time, PriceOpenSell[%index] = %price" - is this the pattern?

If so, it should be like this:

"OpenSellTime[%i] = %I64u, PriceOpenSell[%i] = %.5f"

The values themselves should be listed next, separated by commas:

 ,i,OpenSellTime[i],i,PriceOpenSell[i]

total:

printf("OpenSellTime[%i] = %I64u, PriceOpenSell[%i] = %.5f",i,OpenSellTime[i],i,PriceOpenSell[i]);

... well ... if I didn't leave anything out...

 

MQL4, DoubleToStr() and DoubleToString(). In DoubleToStr() for the 2nd argument add "Default 8".

Code:

#property strict
void OnStart()
  {
   Print("1) DoubleToStr(0.123456789) = ",DoubleToStr(0.123456789));
   Print("2) DoubleToString(0.123456789) = ",DoubleToString(0.123456789));
  }

In the logs, the result for them will be = 0.12345679, i.e. the function rounds the value; it is not written in the help. I think it's worth writing more about this, or at least putting examples of the type there:

string value1=DoubleToStr(1.28473418, 5);
// содержимое строки value1 - "1.28473"

string value2=DoubleToStr(1.28473418, 3);
// содержимое строки value2 - "1.285"

, where rounding will be visible.