get string from R

Posted By: maxwellreturn

get string from R - 09/30/19 18:27

hi guys,
is there a way to get a string value from R? i tried every function like "ri" "rd" and "rv" with a character array but nothing appened.
I have to get an asset name from the Rterm.

Thanks, have a nice day
Posted By: AndrewAMD

Re: get string from R - 09/30/19 18:38

In R, save strings to a file. Read the file from Zorro.
Posted By: maxwellreturn

Re: get string from R - 10/03/19 21:37

Originally Posted by AndrewAMD
In R, save strings to a file. Read the file from Zorro.

thank you andrew, can you post an example of how i can store a string like this "EUR/USD,GBP/USD,EUR/JPY" from an external csv in a zorro string variable? thank you so much
Posted By: AndrewAMD

Re: get string from R - 10/04/19 14:11

There are many R samples on the internet, and Zorro is very well-documented. Why not give it a try? laugh

If you want to make it easy, forget CSV's. Just put a single string in a temp file and load one at a time.
https://zorro-project.com/manual/en/str_.htm
https://zorro-project.com/manual/en/file_.htm
Posted By: maxwellreturn

Re: get string from R - 10/09/19 12:47

thank you andrew, i ve tried to do what you suggest, but i think i get a bug.
this is mycode:
Code
        NumYears = 10;
	BarPeriod = 60;
	MaxLong = MaxShort = 1;
	LookBack = 500;
asset(file_content("C:\\Users\\utente\\Zorro\\Data\\best1.csv"));
vars Price = series(priceClose());
int per = 100;
var x = 2.5;
vars Trends1 = series(SMA(Price,per));
vars Trends2 = series(SMA(Price,per*x));
	
       if(crossOver(Trends1,Trends2))
       enterLong();
      if(crossUnder(Trends1,Trends2))
       enterShort();	


in the "best1.csv" there is only a line with written "GBP/AUD".
And i get this error:
Quote

Error 055: "GBP/AUD"
no history (2010 History\ "GBPAUD" , t6)
Error055: no bars generated


its like if it cant read the "/" in the file. Can someone explain why i get this wrong output?
Ps: i ve got the t6 file 2010 of GBP/AUD
Posted By: AndrewAMD

Re: get string from R - 10/09/19 13:13

Zorro eliminates the slash intentionally for things such as filenames, like t6 files. After all, you cannot have a slash in a filename.

I see no problems with this snippet. If you're still confused, post your entire script. It's more likely there's a problem with your history setup.
Posted By: maxwellreturn

Re: get string from R - 10/09/19 14:10

Code
function run()
{
        NumYears = 10;
	BarPeriod = 60;
	MaxLong = MaxShort = 1;
	LookBack = 500;
asset(file_content("C:\\Users\\utente\\Zorro\\Data\\best1.csv"));
vars Price = series(priceClose());
int per = 100;
var x = 2.5;
vars Trends1 = series(SMA(Price,per));
vars Trends2 = series(SMA(Price,per*x));
	
       if(crossOver(Trends1,Trends2))
       enterLong();
      if(crossUnder(Trends1,Trends2))
       enterShort();	
		}


this is the entire code
this is what i get, you can see error message in zorro and other file you see is the csv file. I tried even without the "" but it give me the same error.
[img]https://ibb.co/5jQPxBt[/img]
Posted By: maxwellreturn

Re: get string from R - 10/09/19 14:15

https://ibb.co/VHzkyDk
this is my history folder with the history of EUR/TRY (i said GBP/USD in the first post but i was wrong)
can be something relative to the name of t6 files? or is it a bug?
Posted By: AndrewAMD

Re: get string from R - 10/09/19 15:36

I bet your csv file uses quote characters! You cannot have any of that. Your file must be perfect.

Your file contents must be exactly seven characters: GBP/AUD

No quotes, no commas, no newline characters. It must be pure.

If you right-click on the file and click Properties, the file size must be seven bytes.

From R, one very good way to write the file would be to use the sink() method:
https://stackoverflow.com/a/2471806
Posted By: maxwellreturn

Re: get string from R - 10/09/19 17:11

wow thank you so much man, you were right the file was with quote characacters and it was 9 bytes. With sink function in R i get 7 bytes file thank you so much.
Posted By: maxwellreturn

Re: get string from R - 10/09/19 17:45

for sake of community, you can get csv files of 7 bytes even with function write.table() with arguments quote = FALSE,eol = "".
© 2024 lite-C Forums