to make it 0.2. ps the number of digits after the decimal point will always be used differently
There are up to 8 fractional decimal digits, correct as you need.
// Переводит в строку курсstring KursS(double Ku) {
int k, i;
string S; // 8 дробных цифр для составного курса открытия позиции в MT5
S=DoubleToString(NormalizeDouble(Ku,8),8); // Уберем концевые нули
i=StringLen(S)-1;
if (StringSubstr(S,i,1)!="0") return(S); // Их нетfor (k=i-1;k>0;k--) if (StringSubstr(S,k,1)!="0") {S=StringSubstr(S,0,k+1); break;}
i=StringLen(S)-1; // Уберем концевую точкуif (StringSubstr(S,i,1)==".") S=StringSubstr(S,0,i);
return (S);
} // KursS
Vlad143: There are up to 8 fractional decimal digits here, correct as you wish.
// Переводит в строку курс Вот так короче!!! Строк меньше и в каждой строке прозрачнее
string Kurs(double Ku)
{
string S="0"; int n=8; // Количество знаков дробной части
while(S[StringLen(S)-1]=='0' && n>=0)
{
S=DoubleToString(Ku,n); // n дробных цифр
n--;
}
return (S);
} // Kurs
Shorter in the source code, longer in the execution. I'm all for fast execution. Run the comparison script, I got 6 seconds and 11 seconds. Blame the number to string operation, it's better to do it once.
#property copyright"Copyright 2016, MetaQuotes Software Corp."#property link"https://www.mql5.com"#property version"1.00"#property strict// Переводит в строку курсstring KursS(double Ku) {
int k, i;
string S; // 8 дробных цифр для составного курса открытия позиции в MT5
S=DoubleToString(NormalizeDouble(Ku,8),8); // Уберем концевые нули
i=StringLen(S)-1;
if (StringSubstr(S,i,1)!="0") return(S); // Их нетfor (k=i-1;k>0;k--) if (StringSubstr(S,k,1)!="0") {S=StringSubstr(S,0,k+1); break;}
i=StringLen(S)-1; // Уберем концевую точкуif (StringSubstr(S,i,1)==".") S=StringSubstr(S,0,i);
return (S);
} // KursS// Переводит в строку курс Вот так короче!!! Строк меньше и в каждой строке прозрачнееstring Kurs(double Ku)
{
string S="0"; int n=8; // Количество знаков дробной частиwhile(S[StringLen(S)-1]=='0' && n>=0)
{
S=DoubleToString(Ku,n); // n дробных цифр
n--;
}
return (S);
} // Kurs voidOnStart() {
string S;
datetime TBeg,T1, T2;
double x;
int N,i;
N=10000000; x=0.2;
TBeg=TimeLocal();
for (i=0;i<N;i++) S=KursS(x);
T1=TimeLocal()-TBeg;
TBeg=TimeLocal();
for (i=0;i<N;i++) S=Kurs(x);
T2=TimeLocal()-TBeg;
Alert ("KursS -",(long)(T1),"сек Kurs - ",(long)(T2),"сек");
}
How do you understand it's going? Are the two horizontal lines being created? There are no errors in my log but lines do not appear after the start of the script
It`s strange, though - it worked and created lines on AUDCAD, but not on AUDCHF and EURUSD...
I think I understand it... It does not appear on charts that already have horizontal lines. If I remove them and run the script, lines will appear. But why do they appear? Question.
LRA: Time can be saved in the name of the horizontal line
Thank you, but the name is occupied by a comment , the trend line is better suited both prices are the same time the first time is 0 and the second is the right one ... this is probably the most reasonable
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Another question is how to cut off extra zeros?
to make it 0.2.
ps the number of digits after the decimal point will always be used differently
There are up to 8 fractional decimal digits, correct as you need.
Reworked it like this - everything goes
Shorter in the source code, longer in the execution. I'm all for fast execution. Run the comparison script, I got 6 seconds and 11 seconds. Blame the number to string operation, it's better to do it once.
Reworked it like this - it's going
How do you understand it's going? Are the two horizontal lines being created? There are no errors in my log but lines do not appear after the start of the script
It`s strange, though - it worked and created lines on AUDCAD, but not on AUDCHF and EURUSD...
I think I understand it... It does not appear on charts that already have horizontal lines. If I remove them and run the script, lines will appear. But why do they appear? Question.
Re-creating a line or even another object with the same name is forbidden
Any object has a name. Right-click on the graphic --> List of objects
Time can be saved in the name of the horizontal line
There are up to 8 fractional decimal digits here, correct as you wish.