Jump to content

text calc displaying as zero


This topic is 1900 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hi,

I am trying to establish some simple code using a text calculation.  The calc I have written goes like this :

"[" & #_security_name & "]¶" & 
"security_name = " & #_security_name & "¶" & 
"security_type = " & #_security_type & "¶" & 
"account = " & #_account & "¶" & 
"sar_timeframe = " & #_sar_timeframe & "¶" & 
"sar_timeframe_switch = " & "#_sar_timeframe_switch" & ¶ & 
"sar_periods = {""1m"": ""1D"", ""2m"": ""1D"", ""3m"": ""1D"", ""5m"": ""1D"", ""10m"": ""1D"", ""15m"": ""1D"", ""20m"": ""1D"", ""30m"": ""3D"", ""60m"": ""1D"", ""120m"": ""1D"", ""240m"": ""2D"", ""1D"": ""5D""}" & ¶ & 
"sar_incremental_step = " & #_sar_incremental_step & ¶ & 
"sar_max_step = " & #_sar_max_step & ¶ & 
"ma_timeframe = " & #_ma_timeframe & ¶ & 
"ma_slow = " = #_ma_slow & ¶ & 
"ma_fast = " = #_ma_fast & ¶ & 
"order_size = " & #_order_size & ¶ & 
"activate = " & #_activate_security_name

The result I am getting at present is just "0".  However if I just use the first ten lines i get :

Quote

[CWBR]

security_name = CWBR

security_type = STK

account = U#####

sar_timeframe = 1D

sar_timeframe_switch = #_sar_timeframe_switch

sar_periods = {"1m": "1D", "2m": "1D", "3m": "1D", "5m": "1D", "10m": "1D", "15m": "1D", "20m": "1D", "30m": "3D", "60m": "1D", "120m": "1D", "240m": "2D", "1D": "5D"}

sar_incremental_step = 0.02

sar_max_step = 0.2

ma_timeframe = 1D

which is exactly what I want.  Would anyone have any idea why the line 

"ma_slow = " = #_ma_slow & ¶ 

impedes the calc from functioning properly?

Sorry.  Just figured it out.  Line 10 should read

"ma_slow = " & #_ma_slow & ¶

and not

"ma_slow = " = #_ma_slow & ¶

 

My bad

 

Edited by dysong3
Link to comment
Share on other sites

You can use  & ¶ & in all instances vs  & "¶" & as a single pilcrow will evaluate ( you have some with and without ) 

Or

start from line two and like 

"[" & #_security_name & "]" &  
"¶security_name = " & #_security_name &
"¶security_type = " & #_security_type &
Link to comment
Share on other sites

Using the List() function could make this both easier and more readable, I think.

That is assuming it's worth doing at all. It seems like you're preparing a text file for export; if that's true, I'd suggest you look into exporting as XML and using an XSLT stylesheet to create a text file in the required format. 

Link to comment
Share on other sites

i am not sure how this even evaluates with out escaping the quotes, unless you ignoring smart quotes? 

"sar_periods = {""1m"": ""1D"", ""2m"": ""1D"", ""3m"": ""1D"", ""5m"": ""1D"", ""10m"": ""1D"", ""15m"": ""1D"", ""20m"": ""1D"", ""30m"": ""3D"", ""60m"": ""1D"", ""120m"": ""1D"", ""240m"": ""2D"", ""1D"": ""5D""}" & ¶ &

another option would be:

InsertText ( to a variable ) script step as $template  (No need for quotes or & or ¶

[%A%]
security_name = %b%
security_type = %c%
account =  %d%
sar_timeframe = & %e%
sar_timeframe_switch = %f%
sar_periods = %g%
sar_incremental_step %h%
sar_max_step = %i%
ma_timeframe = %j%
ma_slow = %k%
ma_fast = %l%
order_size = %m%
activate =  %n%

Then substitute for each place holder. 

Substitute ( $template ; [ "%a% ; #_security_name ] ; [ "%b% ; #_security_name ] ; ..... ) 

Link to comment
Share on other sites

Thanks once again. With your demo I was able to create a stylesheet that pretty much suits my purposes.  Just two more questions.

Ideally I'd like to have 4 global records serve as a header is the stylesheet. So that their info only appears once at the beginning of the output file.  Is there any way of doing that?

And how do you add paragraphs characters, say between the each records block of text?  

Edited by dysong3
Link to comment
Share on other sites

3 hours ago, dysong3 said:

I'd like to have 4 global records serve as a header is the stylesheet.

I think you mean global fields? You would include them in the export (so that they would appear in every record) and use them outside the <xsl:for-each select="fmp:RESULTSET/fmp:ROW">...</xsl:for-each>  block.

To get the value of such field, use:

<xsl:value-of select="fmp:RESULTSET/fmp:ROW[1]/fmp:COL[x]/fmp:DATA"/>

where x is the number of the field in the field export order.

 

3 hours ago, dysong3 said:

And how do you add paragraphs characters

I have them in my stylesheet:

&#10; 

is a line feed character. If you need a carriage return, use:

&#13;

 

 

Edited by comment
Link to comment
Share on other sites

This topic is 1900 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.