MC_File Writing Bug ?

Questions about MultiCharts and user contributed studies.
brodnicki steven
Posts: 407
Joined: 01 Jan 2008
Been thanked: 3 times

MC_File Writing Bug ?

Postby brodnicki steven » 25 Apr 2009

I'm not sure if it's MC or not but this code works in TS2ki but columns 7-10 are wrong on MC. It writes a simple .csv file that can be viewed in Excel.
I need to write out 14 columns of data in Excel, so I wrote this simple study. I apply it to the SPX (100 days of 60 minute bars)
Help ! Anyone see what I did wrong ?
Been trying to figure it out for weeks, (not exclusive to beta6, all MC versions do it wrong that I've tried).
(tip:The problem may be in the way MC reads my function)
Attachments
MC_File test.zip
(2.15 KiB) Downloaded 108 times

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 25 Apr 2009

this is a most interesting challenge.

I have added the print statement to code, so that I can monitor the changes in the PowerEditor.


osc1= c;
print("osc1=", text(osc1), ",", text(c));
osc2= c;
print("osc2=", text(osc2), ",", text(c));
osc3= c;
print("osc3=", text(osc3), ",", text(c));
osc4= c;
print("osc4=", text(osc4), ",", text(c));
osc5= c;
print("osc5=", text(osc5), ",", text(c));
osc6= c;
print("osc6=", text(osc6), ",", text(c));
osc7= c;
print("osc7=", text(osc7), ",", text(c));
osc8= c;
print("osc8=", text(osc8), ",", text(c));
osc9 = c;
print("osc9=", text(osc9), ",", text(c));
osc10 = c;
print("osc10=", text(osc10), ",", text(c));
osc11 = c;
print("osc11=", text(osc11), ",", text(c));
osc12 = c;
print("osc12=", text(osc12), ",", text(c));
osc13 = c;
print("osc13=", text(osc13), ",", text(c));
osc14 = c;
print("osc14=", text(osc14), ",", text(c));

print(
{DateToStr_Me(Date) + "," +
NumToStr(Time,0) + "," +}

NumToStr(osc1,6) + "," +
NumToStr(osc2,6) + "," +
NumToStr(osc3,6) + "," +
NumToStr(osc4,6) + "," +
NumToStr(osc5,6) + "," +
NumToStr(osc6,6) + "," +
NumToStr(osc7,6) + "," +
NumToStr(osc8,6) + "," +
NumToStr(osc9,6) + "," +
NumToStr(osc10,6) + "," +
NumToStr(osc11,6) + "," +
NumToStr(osc12,6) + "," +
NumToStr(osc13,6) + "," +
NumToStr(osc14,6) + ",");




this is my observation:


1. based on the print out put, these assignments are correct:
osc1= c;
print("osc1=", text(osc1), ",", text(c));


2. if I do the group print without the date and time, the output is ok.

3. if I do the group print with either the date or time, the print out is incorrect.

so there you go... even without your function, if the time is printed, the output is incorrect.

I would like to know the answer as well.

;-)

brodnicki steven
Posts: 407
Joined: 01 Jan 2008
Been thanked: 3 times

Postby brodnicki steven » 25 Apr 2009

Thanks for your observation TJ and your troubleshooting-
I hope Andrew-Marina can give us the answer.
It works fine in TS2ki, I've used it for years.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 25 Apr 2009

I think I narrowed down the problem...

see code in next post.
Last edited by TJ on 25 Apr 2009, edited 1 time in total.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 25 Apr 2009

run this code.

then check the output box in the PowerEditor.

I think the problem is in the print statement.

the assignment of variables osc1 to osc14 worked ok.

when printing out the variable values one by one, we have confirmed the variables are correct. (ie. valued 1 to 14, respectively).

when printing multiple variables in a print statement,
the print keyword can handle up to 10 variables correctly,
the rest of the print out do not make sense.



Code: Select all

Var: osc1(0),osc2(0),osc3(0),osc4(0),osc5(0),osc6(0),osc7(0),osc8(0),
osc9(0),osc10(0),osc11(0),osc12(0),osc13(0),osc14(0);


{assign the value to the variable,
then make a print out immediately to ensure the assignments are correct.}

osc1= 1;
print("osc1=", text(osc1), ",", NumToStr(osc1,6), ",", text(c));
osc2= 2;
print("osc2=", text(osc2), ",", NumToStr(osc2,6), ",",text(c));
osc3= 3;
print("osc3=", text(osc3), ",", NumToStr(osc3,6), ",", text(c));
osc4= 4;
print("osc4=", text(osc4), ",", NumToStr(osc4,6), ",", text(c));
osc5= 5;
print("osc5=", text(osc5), ",", NumToStr(osc5,6), ",", text(c));
osc6= 6;
print("osc6=", text(osc6), ",", NumToStr(osc6,6), ",", text(c));
osc7= 7;
print("osc7=", text(osc7), ",", NumToStr(osc7,6), ",", text(c));
osc8= 8;
print("osc8=", text(osc8), ",", NumToStr(osc8,6), ",", text(c));
osc9 = 9;
print("osc9=", text(osc9), ",", NumToStr(osc9,6), ",", text(c));
osc10 = 10;
print("osc10=", text(osc10), ",", NumToStr(osc10,6), ",", text(c));
osc11 = 11;
print("osc11=", text(osc11), ",", NumToStr(osc11,6), ",", text(c));
osc12 = 12;
print("osc12=", text(osc12), ",", NumToStr(osc12,6), ",", text(c));
osc13 = 13;
print("osc13=", text(osc13), ",", NumToStr(osc13,6), ",", text(c));
osc14 = 14;
print("osc14=", text(osc14), ",", NumToStr(osc14,6), ",", text(c));


{make a group printout, using numtostr }
print("numtostr=" +
NumToStr(osc1,6) + "," +
NumToStr(osc2,6) + "," +
NumToStr(osc3,6) + "," +
NumToStr(osc4,6) + "," +
NumToStr(osc5,6) + "," +
NumToStr(osc6,6) + "," +
NumToStr(osc7,6) + "," +
NumToStr(osc8,6) + "," +
NumToStr(osc9,6) + "," +
NumToStr(osc10,6) + "," +
NumToStr(osc11,6) + "," +
NumToStr(osc12,6) + "," +
NumToStr(osc13,6) + "," +
NumToStr(osc14,6) + ",");

{make a group printout, using text }
print(
"text=",
text(osc1) , "," ,
text(osc2) , "," ,
text(osc3) , "," ,
text(osc4) , "," ,
text(osc5) , "," ,
text(osc6) , "," ,
text(osc7) , "," ,
text(osc8) , "," ,
text(osc9) , "," ,
text(osc10) , "," ,
text(osc11) , "," ,
text(osc12) , "," ,
text(osc13) , "," ,
text(osc14) , ",");


{repeat print out to make sure the variable values have not been altered}

print("osc1a=", text(osc1), ",", NumToStr(osc1,6), ",", text(c));
print("osc2a=", text(osc2), ",", NumToStr(osc2,6), ",",text(c));
print("osc3a=", text(osc3), ",", NumToStr(osc3,6), ",", text(c));
print("osc4a=", text(osc4), ",", NumToStr(osc4,6), ",", text(c));
print("osc5a=", text(osc5), ",", NumToStr(osc5,6), ",", text(c));
print("osc6a=", text(osc6), ",", NumToStr(osc6,6), ",", text(c));
print("osc7a=", text(osc7), ",", NumToStr(osc7,6), ",", text(c));
print("osc8a=", text(osc8), ",", NumToStr(osc8,6), ",", text(c));
print("osc9a=", text(osc9), ",", NumToStr(osc9,6), ",", text(c));
print("osc10a=", text(osc10), ",", NumToStr(osc10,6), ",", text(c));
print("osc11a=", text(osc11), ",", NumToStr(osc11,6), ",", text(c));
print("osc12a=", text(osc12), ",", NumToStr(osc12,6), ",", text(c));
print("osc13a=", text(osc13), ",", NumToStr(osc13,6), ",", text(c));
print("osc14a=", text(osc14), ",", NumToStr(osc14,6), ",", text(c));

here's the print out.
I have highlighted the problem area in red.

osc1= 1.00,1.000000, 866.50
osc2= 2.00,2.000000, 866.50
osc3= 3.00,3.000000, 866.50
osc4= 4.00,4.000000, 866.50
osc5= 5.00,5.000000, 866.50
osc6= 6.00,6.000000, 866.50
osc7= 7.00,7.000000, 866.50
osc8= 8.00,8.000000, 866.50
osc9= 9.00,9.000000, 866.50
osc10= 10.00,10.000000, 866.50
osc11= 11.00,11.000000, 866.50
osc12= 12.00,12.000000, 866.50
osc13= 13.00,13.000000, 866.50
osc14= 14.00,14.000000, 866.50
numtostr=1.000000,2.000000,3.000000,4.000000,5.000000,6.000000,7.000000,8.000000,9.000000,10.000000,1.000000,2.000000,3.000000,4.000000,
text= 1.00, 2.00, 3.00, 4.00, 5.00, 6.00, 7.00, 8.00, 9.00, 10.00, 1.00, 2.00, 3.00, 4.00,
osc1a= 1.00,1.000000, 866.50
osc2a= 2.00,2.000000, 866.50
osc3a= 3.00,3.000000, 866.50
osc4a= 4.00,4.000000, 866.50
osc5a= 5.00,5.000000, 866.50
osc6a= 6.00,6.000000, 866.50
osc7a= 7.00,7.000000, 866.50
osc8a= 8.00,8.000000, 866.50
osc9a= 9.00,9.000000, 866.50
osc10a= 10.00,10.000000, 866.50
osc11a= 11.00,11.000000, 866.50
osc12a= 12.00,12.000000, 866.50
osc13a= 13.00,13.000000, 866.50
osc14a= 14.00,14.000000, 866.50

brodnicki steven
Posts: 407
Joined: 01 Jan 2008
Been thanked: 3 times

Postby brodnicki steven » 25 Apr 2009

TJ: In my original code only osc7-osc10 failed, before 7 or after 10 worked- it was weird.
Looks like some limit that needs to be changed in MC. 10 is too limited, I sometimes need 30+ columns. I'm surprised that others haven't run into this problem before.
Writing files to Excel is pretty common with traders.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 25 Apr 2009

TJ: In my original code only osc7-osc10 failed, before 7 or after 10 worked- it was weird.
Looks like some limit that needs to be changed in MC. 10 is too limited, I sometimes need 30+ columns. I'm surprised that others haven't run into this problem before.
Writing files to Excel is pretty common with traders.

it is possible that osc11 to osc14 also failed to print properly previously.

because the values were the same across osc1 to osc14, you cannot visually distinguish the failed print out.

once I assigned the osc to different value, the error surfaced.



if you put this "DateToStr_Me(Date) + "," + NumToStr(Time,0) + "," +" back into the group print code, you will get more strange print outs.

;-)

brodnicki steven
Posts: 407
Joined: 01 Jan 2008
Been thanked: 3 times

Postby brodnicki steven » 25 Apr 2009

TJ: Here is a snapshot of my file in Excel- notice only 7-10 are bad.
Attachments
MC_File Error.jpg
(557.95 KiB) Downloaded 860 times

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 25 Apr 2009

TJ: Here is a snapshot of my file in Excel- notice only 7-10 are bad.
I know. I have the same result.

But how could you know osc11 to osc14 are good?

just because they "appear" to produce the value does not prove they are good.

you have to have separately identifiable values for those variables to ascertain they are operating properly.

That is the reason I assigned different numbers to those variable... to see if the print statement can reproduce them.

On your worksheet, under column M, with the heading osc11, you have the number 1451.36.

Do you know if the print statement is reproducing the value of osc11? or osc1?

brodnicki steven
Posts: 407
Joined: 01 Jan 2008
Been thanked: 3 times

Postby brodnicki steven » 26 Apr 2009

You're correct TJ, I wasn't thinking about it that way. I should have had each column with different values to be sure. I may try that today. It is odd though, to be limited to 10 print values. I hope it's an easy registry fix.

brodnicki steven
Posts: 407
Joined: 01 Jan 2008
Been thanked: 3 times

Postby brodnicki steven » 29 Apr 2009

Andrew-Marina Please look into this file writing bug.

brodnicki steven
Posts: 407
Joined: 01 Jan 2008
Been thanked: 3 times

Postby brodnicki steven » 30 Apr 2009

Andrew-Marina Please look into this file writing bug.

brodnicki steven
Posts: 407
Joined: 01 Jan 2008
Been thanked: 3 times

Postby brodnicki steven » 03 May 2009

Andrew-Marina Please look into this file writing bug.

User avatar
Marina Pashkova
Posts: 2758
Joined: 27 Jul 2007

Postby Marina Pashkova » 05 May 2009

Dear Steven,

I apologize for the belated reply. Please find our engineers’ answer below.

The problem is related to the fact that functions returning strings are used within the same expression multiple times.
E.g.:

Code: Select all

aa=numtostr(c,0)+numtostr(c,0)+numtostr(c,0)+.....;
or print(numtostr(c,0),numtostr(c,0),numtostr(c,0),..... )
or text(numtostr(c,0),numtostr(c,0),numtostr(c,0),..... )
It is recommended that such expressions should be simplified. Ideally, 1 expression should contain one call from a function string.

The bug will be fixed, but it might take quite a long time.

In the meantime, your original script can be modified as follows:

Code: Select all

var: out_str("");
out_str=DateToStr_Me(Date) + ",";
out_str=out_str + NumToStr(Time,0) + ",";
out_str=out_str + NumToStr(osc1,6) + ",";
out_str=out_str + NumToStr(osc2,6) + ",";
out_str=out_str + NumToStr(osc3,6) + ",";
out_str=out_str + NumToStr(osc4,6) + ",";
out_str=out_str + NumToStr(osc5,6) + ",";
out_str=out_str + NumToStr(osc6,6) + ",";
out_str=out_str + NumToStr(osc7,6) + ",";
out_str=out_str + NumToStr(osc8,6) + ",";
out_str=out_str + NumToStr(osc9,6) + ",";
out_str=out_str + NumToStr(osc10,6) + ",";
out_str=out_str + NumToStr(osc11,6) + ",";
out_str=out_str + NumToStr(osc12,6) + ",";
out_str=out_str + NumToStr(osc13,6) + ",";
out_str=out_str + NumToStr(osc14,6) + ",";
FileAppend(fileid,out_str+ NewLine);

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 05 May 2009

ok, I got it...

one should FIRST finish ALL the calculations and variable assignments...
then make the PRINT or TEXT statement.

simple enough.

thanks for the clarification.

TJ

brodnicki steven
Posts: 407
Joined: 01 Jan 2008
Been thanked: 3 times

Postby brodnicki steven » 05 May 2009

Thanks Marina, I'll try that !!!!
Thanks for the code as well , as I'm not a programmer and would have struggled to get it right.


Return to “MultiCharts”