Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (frutza, Quad, AndrewAMD), 385 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
How to use dataFromCSV #485937
05/13/22 13:13
05/13/22 13:13
Joined: Mar 2021
Posts: 42
Casablanca, Morocco
anissyo Offline OP
Newbie
anissyo  Offline OP
Newbie

Joined: Mar 2021
Posts: 42
Casablanca, Morocco
Hello guys,

I need to use this function to read some CSV file, I am unable to figure out how this function works

dataFromCSV (int Handle, string Format, string Filename, int Column, int Offset)

what I don't understand is the Handle, the Format and Offeset.

cheers,

Re: How to use dataFromCSV [Re: anissyo] #485938
05/13/22 13:49
05/13/22 13:49
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
The dataset function arguments (Handle, Format, and Offset) are described near the bottom of the manual page:
https://zorro-project.com/manual/en/data.htm

Re: How to use dataFromCSV [Re: anissyo] #485939
05/13/22 15:25
05/13/22 15:25
Joined: Mar 2021
Posts: 42
Casablanca, Morocco
anissyo Offline OP
Newbie
anissyo  Offline OP
Newbie

Joined: Mar 2021
Posts: 42
Casablanca, Morocco
I tried my friend i used this code :


Code
#include <contract.c>
function run()

{

LookBack = 100;
set(LOGFILE);
BarPeriod = 600;
set(PLOTNOW);


int column = dataFromCSV (1,"CSV", "aaa", 1, 1);

print (TO_LOG,column);
}



all I get is : Error 058: Bad code 'C' for '2, "1.7 Cub' in aaa.csv

PS: I have the CSV file in the history folder

Re: How to use dataFromCSV [Re: anissyo] #485941
05/13/22 15:42
05/13/22 15:42
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
"CSV" isn't a string format and "aaa" isn't a file name. Please read the link again that Andrew has provided.

When you still receive a 058 message after fixing this then have a look at the error message section.

https://zorro-project.com/manual/en/errors.htm

Re: How to use dataFromCSV [Re: anissyo] #485942
05/13/22 15:52
05/13/22 15:52
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Also, definitely check out the CSVtoHistory script included with Zorro for some excellent sample code.

Not all CSVs are made the same, so you will need to edit the CSV format to suit. See, you have different kinds of time stamps and field values to work with. Plus the sort order can be backwards.

Re: How to use dataFromCSV [Re: anissyo] #485944
05/13/22 16:06
05/13/22 16:06
Joined: Mar 2021
Posts: 42
Casablanca, Morocco
anissyo Offline OP
Newbie
anissyo  Offline OP
Newbie

Joined: Mar 2021
Posts: 42
Casablanca, Morocco
Hello guys, thanks for the replies, really appreciate it

this CSV file contains some breakouts that I detected using a python script, I want to take those break out and add them as signals in my zorro script so the format is irrelevant I guess since the format of the column is as follow: "YYYY/MM/DD strong up" or "YYYY/MM/DD medium up" or "YYYY/MM/DD weak down" etc. I just want to get the values from the CSV, regardless of what format is being used.

By the way Andrew I use occasionally CSVtoHistory to convert my data to T format, and I don't see datafromCSV used in the script...

Last edited by anissyo; 05/13/22 16:13.
Re: How to use dataFromCSV [Re: anissyo] #485945
05/13/22 16:19
05/13/22 16:19
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
What are you trying to do with the CSV, exactly?

Re: How to use dataFromCSV [Re: anissyo] #485946
05/13/22 16:27
05/13/22 16:27
Joined: Mar 2021
Posts: 42
Casablanca, Morocco
anissyo Offline OP
Newbie
anissyo  Offline OP
Newbie

Joined: Mar 2021
Posts: 42
Casablanca, Morocco
I want to extract the data from that CSV, every cell contains a date followed by "strong up" or "medium down" etc. but the format is as follows: "YYYY/MM/DD strong up"
every cell contains values extracted from an end-of-day candles break-out detector that I coded in python.

and I will write a c lite script to check if I am on a break-out day and then try some intraday strategies to see the result, how to get the CSV values? lol

Last edited by anissyo; 05/13/22 16:29.
Re: How to use dataFromCSV [Re: anissyo] #485948
05/14/22 06:58
05/14/22 06:58
Joined: Apr 2008
Posts: 585
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 585
Austria
First convert your data to CSV. You only need a comma after the date, a simple find/replace should do.

Then read the CSV with dataParse.

Re: How to use dataFromCSV [Re: anissyo] #485949
05/14/22 13:19
05/14/22 13:19
Joined: Mar 2021
Posts: 42
Casablanca, Morocco
anissyo Offline OP
Newbie
anissyo  Offline OP
Newbie

Joined: Mar 2021
Posts: 42
Casablanca, Morocco
ok i will try, i found this line here in an example in documentation : int Records = dataParse(1,Format,"History\\BTCEUR.csv");

the only thing I am not understanding is the Format argument, what should I do in Format in my case ?? Let's say for example that the CSV contains one line: "AAA;BBB;CCC" how to get this value from within the CSV ?? what format should I use ??

Thanks a lot my friend =)

Last edited by anissyo; 05/14/22 13:25.
Re: How to use dataFromCSV [Re: anissyo] #485950
05/14/22 13:40
05/14/22 13:40
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Originally Posted by anissyo
Let's say for example that the CSV contains one line: "AAA;BBB;CCC" how to get this value from within the CSV ?? what format should I use ??

That's not a CSV (comma separated value) file, that's a SSV (semicolon separated value) file, a format that nobody uses. And there's no timestamp in the first column, which is required.

So your first error is that your source material is no good. Fix that.

Here's an example of a good CSV file, with a header line included (also supported by Zorro):
Code
Date,Value
2022/01/01,100.0
2022/01/02,101.0
2022/01/03,102.0
2022/01/04,103.0

Once you fix your source material, write the format string to match the format of your file. The manual spells this out very clearly, and there are examples in the example script.

Re: How to use dataFromCSV [Re: anissyo] #485951
05/14/22 13:57
05/14/22 13:57
Joined: Mar 2021
Posts: 42
Casablanca, Morocco
anissyo Offline OP
Newbie
anissyo  Offline OP
Newbie

Joined: Mar 2021
Posts: 42
Casablanca, Morocco
In the docs i found this in https://zorro-project.com/manual/en/data.htm :

ss... - for an extended text field of size 4n-1, where n is the number of 's'. Occupies n adjacent fields in the dataset, while field 0 counts as 2 fields.

since the dummy csv file contains only one line with "AAA;BBB;CCC" i told myself that the format should be "sss,sss,sss" here is my code :

Code

function run()

{

LookBack = 100;
set(LOGFILE);
BarPeriod = 600;


string t=dataNew(1,9,9);
dataParse(1,"sss,sss,sss","History\\vvv.csv");
//print (TO_LOG,sftoa (t, 6));
}


but its not working i get this message error :
Quote

Error 058: Bad file format for 'aaa;bbb;cc' in vvv.csv
Error 111: Crash in run: run() at bar 35


Last edited by anissyo; 05/14/22 14:05.
Re: How to use dataFromCSV [Re: anissyo] #485952
05/14/22 14:31
05/14/22 14:31
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Why didn't you change the source CSV file yet like I suggested? Do it. I don't understand why you continue to work with this bad file.

Re: How to use dataFromCSV [Re: anissyo] #485953
05/14/22 15:08
05/14/22 15:08
Joined: Mar 2021
Posts: 42
Casablanca, Morocco
anissyo Offline OP
Newbie
anissyo  Offline OP
Newbie

Joined: Mar 2021
Posts: 42
Casablanca, Morocco
I am sorry the previous message was sent before I saw your last message here is what I did after reading your last response :


I did replace the CSV file content with the sample you provided but nothing is solved

Code
function run()

{

LookBack = 100;
set(LOGFILE);
BarPeriod = 600;


string t=dataNew(1,9,9);
dataParse(1,"+%Y/%m/%d,f","History\\vvv.csv");

}



but I still get this error message unfortunately :
Quote

csvreader compiling...........
Error 058: Bad file format for 'Date,Value' in vvv.csv
Error 111: Crash in run: run() at bar 35

Last edited by anissyo; 05/14/22 15:10.
Re: How to use dataFromCSV [Re: anissyo] #485959
05/16/22 16:43
05/16/22 16:43
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
It looks like the parser tried to read the header line for some reason. The default is one line, but try manually setting it to 1 using the Format string field.

Page 1 of 2 1 2

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1