Print price not correct

Posted By: tradingest

Print price not correct - 09/06/18 21:10

Hi all,

why this print for the value Close and Open is always 0.0000
what am I doing wrong?

Code:
while(asset(loop(Assets)))
{
string CurrentAsset = Asset;
vars C = series(priceClose(0)); 
vars O = series(priceOpen(0));

print(TO_WINDOW,"n Asset = %s, C = %f, O = %f", CurrentAsset,C,O);

Posted By: AndrewAMD

Re: Print price not correct - 09/06/18 21:30

You can't print a vars. You can print an element of a vars, which is a var. C[0] is a var, for example.
Posted By: tradingest

Re: Print price not correct - 09/07/18 06:51

Originally Posted By: AndrewAMD
You can't print a vars. You can print an element of a vars, which is a var. C[0] is a var, for example.


The correct code is
var C = series(priceClose(0));
var O = series(priceOpen(0));

Right?

Is necessary to calculate series for each asset takes into loop right?
Posted By: Dalla

Re: Print price not correct - 09/07/18 06:53

Yes, the price series must be inside the asset loop as in your first example.
Also the declaration string CurrentAsset = Asset; is redundant.
The Asset variable already holds the current Asset, so no need to also define CurrentAsset
Posted By: tradingest

Re: Print price not correct - 09/07/18 10:24

Originally Posted By: Dalla
Yes, the price series must be inside the asset loop as in your first example.
Also the declaration string CurrentAsset = Asset; is redundant.
The Asset variable already holds the current Asset, so no need to also define CurrentAsset


But I can write this code?

Code:
while(asset(loop(Assets)))
{
string CurrentAsset = Asset;
var C = priceClose(0); 
var O = priceOpen(0);



I must use necessary series or I can use the code above in this answer?
Posted By: AndrewAMD

Re: Print price not correct - 09/07/18 12:54

There is no need to declare CurrentAsset if Asset is always the current asset. Asset is a string, so you can use it in your printf function.

var C = series(priceClose(0)) is wrong because series() is a vars.

var C = priceClose(0) is correct because priceClose(0) is a var.

Finally, do not be afraid to experiment with coding. Try a code, see if it works, and if not, find out why. Master your craft. laugh
Posted By: tradingest

Re: Print price not correct - 09/07/18 14:17

Hi Andrew,

my question was different.
I ask if necessary use the series to use close < High for instance or is necessary only price close and price high

Thank for your help
Posted By: AndrewAMD

Re: Print price not correct - 09/07/18 14:56

If this is the full scope of your code, you have no need for series.

Certain indicators will need series. But you're not using indicators.

You need to learn when and why to use a series. This is a fundamental lesson one learns from the Zorro tutorial - highly recommended.
Posted By: tradingest

Re: Print price not correct - 09/07/18 21:46

Originally Posted By: AndrewAMD
If this is the full scope of your code, you have no need for series.

Certain indicators will need series. But you're not using indicators.

You need to learn when and why to use a series. This is a fundamental lesson one learns from the Zorro tutorial - highly recommended.


Thanks Andrew, your answer are very precious
© 2024 lite-C Forums