Stupid question ..

Posted By: Sundance

Stupid question .. - 04/02/14 20:13

After some month I'am trying to program a strategy on my own.

Within the run routine I want for debugging to printf a variable. But the only value I get is 0.000 .

I'am surely doing a stupid failure but after two days of searching I need help :-)


Here is a simple testcode:

// Simple Test to output a value

function run()
{
BarPeriod = 15;
LookBack = 150;
StartDate = 20130401;
EndDate = 20130531;
asset("EUR/USD");

vars Price = series(price());

printf("%.5f", Price[0]);
quit();
return;
}


The output is only 0.00000. Why can't I see the price value?


thanks in advance for answering blush

Sundance
Posted By: swingtraderkk

Re: Stupid question .. - 04/02/14 20:27

Sundance,

Try removing the quit & return, I don't see a need for them. esp quit, rem it will execute on the first run (INITRUN) when indicators and prices are not loaded.

Also try

printf("\n%1.5f", Price[0]);

\n for new line so its readable, and I think you need the 1 for the digit before the decimal point.
Posted By: Sundance

Re: Stupid question .. - 04/03/14 05:48

Hi SwinTraderkk,

thanks for the feedback. The quit and return are resulting from a msg command I used instead of the printf.
But even with this code I have no output. I can't believe that I'am stuck at such a simple point.


// Simple Test to output a value

function run()
{
BarPeriod = 15;
LookBack = 150;
StartDate = 20130401;
EndDate = 20130531;
asset("EUR/USD");

vars Price = series(price());

printf("%1.5f\n", Price[0]);
}
Posted By: CanadianDavid

Re: Stupid question .. - 04/03/14 06:26

I know this forum isn't Lite-C, but check the format string of the printf; is Price[0] really a float?
Posted By: Sundance

Re: Stupid question .. - 04/03/14 07:02

I read the manual and it says that Price is a VARS (var*) and to output I do %f.
But I will try another values. I know that I had such a problem in the past and it was of the wrong usage of printf. :-)

I think I have a deep misunderstanding. I get no output at all. Shouldn't I see current price line after line?
This is from the manual:

"%[flags][width][.precision]f" for var or double variables with decimals.


Posted By: jcl

Re: Stupid question .. - 04/03/14 08:34

It's no misunderstanding, but just 2 different mistakes:

In the first script you get no output because you've quit the script before even loading price history, which happens after the first run.

In the second script you get no output because "\n" is like a carriage return on a typewriter: It jumps back to the begin of the line. For starting at a new line, you must place the "\n" _before_ and not after the rest of the line.
Posted By: Sundance

Re: Stupid question .. - 04/03/14 09:07

Hi jcl,

man what a mess. I never had read that thingy about the \n. Thanks. Now I've got the output! :-)

The manual clearly states this:

For printing on a new line in the message window, begin the text with the linefeed symbol "\n". Otherwise printf appends the text to the end of the current line.

So I haven't read the manual good enough. My fault. I programmed in other C languages and there you can set the \n at the end of the line...
Posted By: jcl

Re: Stupid question .. - 04/03/14 10:18

Yes, what the "\n" does depends on the implementation. When writing to a printer or in a file, "\n" at the end is perfectly fine - something that's already written won't get erased. This is different for Zorro's message window that behaves like a text terminal.
© 2024 lite-C Forums