# NumToStr strange behavior

Questions about MultiCharts and user contributed studies.
arjfca
Posts: 1276
Joined: 23 Nov 2010
Has thanked: 722 times
Been thanked: 222 times

### NumToStr strange behavior

Hello

I'm building a string that contain information on bar and past pivot price. The last 2 elements of the string are not the good value.

Code: Select all

`   If barstatus[1] = 2  then begin      LSL1 = PivotLowVS(1, Low, 1, 1, 21);      LSL2 = PivotLowVS(2, Low, 1, 1, 21);      LSH1 = PivotHighVS(1, High, 1, 1, 21);       LSH2 = PivotHighVS(2, High, 1, 1, 21);       end;   //Print (LSl1:5:5, spaces(1), lsl2:5:5);  // for debug onlyprint ("1   LSH1: ",lsh1:5:5, "              LSH2 ", lsh2:5:5);  // These are the number value before being transform in a stringDataString =     Numtostr(Open,5) + coma + NumtoStr(High,5) + coma + NumtoStr(Low,5) + coma + NumToStr(Close,5) + coma +                    Numtostr(Open[1],5) + coma + NumtoStr(High[1],5) + coma + NumtoStr(Low[1],5) + coma + NumToStr(Close[1],5) + coma +                   NumtoStr(LSL1,5) + coma + NumToStr(LSL2,5) + coma + NumToStr(LSH1,5) + coma + NumToStr(LSH2,5);print ("2   LSH1: ",lsh1:5:5, "                LSH2 ", lsh2:5:5); // These are the same variable Number afterPrint (datastring);[code]If barstatus[1] = 2  then begin      LSL1 = PivotLowVS(1, Low, 1, 1, 21);      LSL2 = PivotLowVS(2, Low, 1, 1, 21);      LSH1 = PivotHighVS(1, High, 1, 1, 21);       LSH2 = PivotHighVS(2, High, 1, 1, 21);       end;   //Print (LSl1:5:5, spaces(1), lsl2:5:5);  // for debug onlyDataString =     Numtostr(Open,5) + coma + NumtoStr(High,5) + coma + NumtoStr(Low,5) + coma + NumToStr(Close,5) + coma +                    Numtostr(Open[1],5) + coma + NumtoStr(High[1],5) + coma + NumtoStr(Low[1],5) + coma + NumToStr(Close[1],5) + coma +                   NumtoStr(LSL1,5) + coma + NumToStr(LSL2,5) + coma + NumToStr(LSH1,5) + coma + NumToStr(LSH2,5);print (lsh1:5:5, " ", lsh2:5:5);Print (datastring);[/code]`

1 LSH1: 1.42150 // LSH2 1.42330
2 LSH1: 1.42150 // LSH2 1.42330
1.42045,1.42055,1.42030,1.42050,1.42085,1.42085,1.42035,1.42045,1.42080,1.42170,1.42045,1.42055

The weird behavior is from the last 2 elements of the string. They represent string value of the last 2 pivots high. It is not the good value that came out of the NumToString.

LSH1 = 1.42150 String = 1.42045
LSH2 = 1.42330 String = 1.42055

I'm confuse. Hope I'm clear enough
Any help appreciated
Martin

JoshM
Posts: 2099
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1527 times
Been thanked: 1494 times
Contact:

### Re: NumToStr strange behavior

Hi Martin,

If I understand your example correctly, I've recently had a similar problem: viewtopic.php?f=1&t=8860

In that case, there was a bug in MC <7 which caused the NumToStr() to 'recycle' the first values when reaching a length of 9 or 10.

What MultiCharts version are you using?

Edit: Here's the Project Management entry: https://www.multicharts.com/pm/viewissue ... _no=MC-223

Edit2:
I get this output from your code:
1 LSH1: 107.42000 LSH2 107.43000
2 LSH1: 107.42000 LSH2 107.43000
107.41500;107.42000;107.41000;107.41500;107.41500;107.42000;107.41000;107.41500;107.41000;107.41500;107.42000;107.43000
107.42000 107.43000
107.41500;107.42000;107.41000;107.41500;107.41500;107.42000;107.41000;107.41500;107.41000;107.41500;107.42000;107.43000

That are the correct values, right? (I'm running MultiCharts Version 7.0 Release (Build 4510)).

Btw, if you don't want to update yet to MC7, as a temporarily workaround you can format the numbers with Print(LSH1:0:5); (which gives 5 numbers behind the decimal, i.e. 1.43258).

Regards,
Josh
These users thanked the author JoshM for the post:
arjfca

arjfca
Posts: 1276
Joined: 23 Nov 2010
Has thanked: 722 times
Been thanked: 222 times

Hello Josh