Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by Martin_HH. 11/20/25 17:37
Zorro 2.66
by Martin_HH. 11/20/25 17:28
Training with the R bridge does not work
by Petra. 11/20/25 14:03
ZorroGPT
by TipmyPip. 11/19/25 10:10
MRC.c and WFO
by 11honza11. 11/18/25 15:22
webGL
by Ice2642. 11/17/25 21:27
Camera always moves upwards?
by NeoDumont. 11/17/25 09:56
Future of ZorroHFT
by TipmyPip. 11/16/25 13:52
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (AndrewAMD, Martin_HH, 1 invisible), 24,337 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
SkinnyApe, tritom, sheliepaley, Blueguy, blobplayintennis
19179 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Training with the R bridge does not work #488962
11/05/25 00:46
11/05/25 00:46
Joined: Jun 2023
Posts: 5
F
frutza Offline OP
Newbie
frutza  Offline OP
Newbie
F

Joined: Jun 2023
Posts: 5
Hi,

I am experimenting with the Zorro / R bridge. I have the following Lite-C script, which makes calls to R.


Code
#include <r.h>

function run()
{
  set(PLOTNOW+PARAMETERS+LOGFILE);
  BarPeriod = 1440;
  LookBack = 100;
  MaxLong = MaxShort = 1;
  
  if(Init) {
    if(!Rstart())
      return quit("Error - R won't start!");
    Rx("rm(list = ls());"); // clear the workspace
    Rx("library(tseries)"); // load time series library
  }
  
  if(is(LOOKBACK)) return;

  int size = optimize(50,10,100);

  Rset("Data",rev(seriesC(),size),size); // send Close series to R
  Rx("ADF = adf.test(Data)"); // Augmented Dickey-Fuller test
  var adf = Rd("ADF$p.value");
  
  if(adf > 0.6) enterLong();
  if(adf < 0.6) exitLong();
  
  plot("ADF p-value", adf ,NEW,RED); //display p-value
}


When I hit the train button, it takes the default value (50) and saves it in the .par file, but no actual training takes place.
Once the value 50 is saved, I can hit test, and everything runs fine. However, there is no optimization happening.

What am I doing wrong here?

Thanks!

Last edited by frutza; 11/05/25 00:56.
Re: Training with the R bridge does not work [Re: frutza] #488976
11/15/25 09:31
11/15/25 09:31
Joined: Apr 2008
Posts: 598
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 598
Austria
I believe it cannot train because your system starts with no optimize call. The number of optimize calls must not change from bar to bar, since the parameter count is derived from it.

Re: Training with the R bridge does not work [Re: Petra] #488983
Yesterday at 22:32
Yesterday at 22:32
Joined: Jun 2023
Posts: 5
F
frutza Offline OP
Newbie
frutza  Offline OP
Newbie
F

Joined: Jun 2023
Posts: 5
Hi Petra,

Thank you for your answer. I found (by trial and error) that my optimize call was misplaced within the code. I guess it has to be placed right at the beginning, after the flags and Zorro variables initialization. The following version of the code works as expected.

Code
#include <r.h>

function run()
{
  set(PLOTNOW+PARAMETERS+LOGFILE);
  BarPeriod = 1440;
  LookBack = 100;
  MaxLong = MaxShort = 1;

  int size = optimize(50,10,100);
  
  if(Init) {
    if(!Rstart())
      return quit("Error - R won't start!");
    Rx("rm(list = ls());"); // clear the workspace
    Rx("library(tseries)"); // load time series library
  }
  
  if(is(LOOKBACK)) return;

  Rset("Data",rev(seriesC(),size),size); // send Close series to R
  Rx("ADF = adf.test(Data)"); // Augmented Dickey-Fuller test
  var adf = Rd("ADF$p.value");
  
  if(adf > 0.6) enterLong();
  if(adf < 0.6) exitLong();
  
  plot("ADF p-value", adf ,NEW,RED); //display p-value
}


The optimize call is now right before the start of the R session.

Last edited by frutza; Yesterday at 22:33.
Re: Training with the R bridge does not work [Re: frutza] #488985
5 hours ago
5 hours ago
Joined: Apr 2008
Posts: 598
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 598
Austria
That looks better, but still a bit misplaced. Normally you place the optimize call just where you use that parameter. But of course before any return statements, whichever comes first.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1