Duplicate: [Puzzle] iif + numtostr

Dear All,
Please help me to figure out a solution or point out what I have done incorrectly.
I have the following very very simple code.

j1=IIf(ROC(C,1)>0,12,13);
j1text=NumToStr(j1,2.0,False);
Filter=1;
AddColumn(j1,"j1",1.0);
AddtextColumn(j1text,"j1text",1.0); //<---

In the exploration windows, all values of the text column "j1text" were equal=12.

Please advise if I have used NumToStr incorrectly. I have not been able to use NumToStr in conjunction with NumToStr to get the expected result.

Thank you.
IMG_20200501_011034453_HDR

NumtoStr returns single value (Last Value, Selected Value if inserting array as first argument). It is not returning array of strings.

In AFL there is numerical array only.

So to get expected result simply use AddColumn as you do in your second to last code line. It is array result already.

Also may additionally read here on why no array of strings.


Another thing... please read below post and please follow forum rule to include code tags if inserting code into post.

Thank you for your reply.

I was trying to do
newprice=Foreign("Ticker" + j1, "H");
The result is
newprice=Foreign("Ticker12", "H"); regardless the value of j1.
for all cases.

I could not substitute 13 (when j1=13) as to get newprice=Foreign("Ticker13", "H");
because j1 was read as text "12".

So, I tried to convert j1 to string and it does not help.
Any additional help is much appreciated.

As @fxshrat wrote you - this has already been explained:

Also it is actually explained in manual. NumToStr is synonym of WriteVal function, so read the docs
http://www.amibroker.com/f?writeval

Specifically first comnent of mine:

WriteVal always returns one value of the array
(not arrays of values). In almost all cases this is LastValue
of the array but in indicators it is "selected value" -
the one that is selected by the vertical line.

Duplicate of: Puzzled by NumToStr function result