R strategy in Zorro Trader

Posted By: Joaquin

R strategy in Zorro Trader - 01/02/17 09:58

Hi, I'm a newcomer to Zorro. I've been programming in mql4 for a long time. I have several strategies in R and would like to backtest and real trade them with Zorro.
The thing is that I don't know what is the best way to bridge a Zorro script with an R Session and don't keep reloading the R Session every new bar or tick.
I've tried in my script with a
Quote:
if (is(INITRUN)) {
if(!g->sRTermPath) {
printf("R path missing! ");
return;
}
if(!file_date(g->sRTermPath)) {
printf("%s not found! ",g->sRTermPath);
return;
}
string Cmd = strf("%s --no-save",g->sRTermPath);
printf(Cmd);
hR = RInit_(Cmd,2);
if(!hR) {
printf("Can't initialize RTerm! ");
return;
}

printf("nR initialized!");
Rx("library(tseries)");
printf("n%s",RLastOutput(hR));
if(!RIsRunning(hR)) {
printf("nR stopped!");
return;
} else
printf("nR running...");
}

section, and initializing the R session inside that code, but for that purpose I would need the R handler to be a static variable, right? And if I try the code
Quote:
static int hR;

it fails, as this variable is also used in the helper file...

With this code snippet of 'is(INITRUN) (...)' I have not been able to get it working. If I remove the is(INITRUN) clause the script works, but what I get is that every new candle the R Session is started, but it takes a looong time to complete (and it is nonsense to keep an R session starting and stopping every single execution of the main loop of the script, right?)
Could anybody give me a hint on how to achieve this?
Posted By: jcl

Re: R strategy in Zorro Trader - 01/02/17 13:40

You need not care of the R handle. It is already handled in the r.h header and not intended to be accessed by the user. For initializing R, just call RStart() in the INITRUN.
Posted By: Joaquin

Re: R strategy in Zorro Trader - 01/03/17 09:02

Thanks!
© 2024 lite-C Forums