NumToStr strange behavior

Questions about MultiCharts and user contributed studies.
arjfca
Posts: 1263
Joined: 23 Nov 2010
Has thanked: 717 times
Been thanked: 221 times

NumToStr strange behavior

Postby arjfca » 20 Jul 2011

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 only

print ("1   LSH1: ",lsh1:5:5, "              LSH2 ", lsh2:5:5);  // These are the number value before being transform in a string


DataString =     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 after
Print (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 only
DataString =     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

User avatar
JoshM
Posts: 2075
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1523 times
Been thanked: 1480 times
Contact:

Re: NumToStr strange behavior

Postby JoshM » 20 Jul 2011

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: 1263
Joined: 23 Nov 2010
Has thanked: 717 times
Been thanked: 221 times

Re: NumToStr strange behavior.... Resolve

Postby arjfca » 20 Jul 2011

Hello Josh
Thanks for your input

I just had a chat with Andrew at MC. This is a confirmed problem that as been resolved in Version 7. I'm still waiting for the last and final update to install it

I did resolved the problem by splitting my string with shorter one and then replace them together

Martin


Return to “MultiCharts”