Strange problem with a global int

Posted By: laz

Strange problem with a global int - 02/22/19 03:37

I was just about to outsource my inputs to an external function, then I noticed something weird.

I define a global array + an int with the length of the array:

Code:
//--------------------------------------------------------------------------------------------

#include <r.h>

//--------------------------------------------------------------------------------------------

var  myINP[3];
int  myIPL = 3;

//--------------------------------------------------------------------------------------------

int loadINP() {

   //////////////////////////////////////////////////

   myINP[0]  = 0;
   myINP[1]  = 0;
   myINP[2]  = 0;

   //////////////////////////////////////////////////

   return(myIPL);

   //////////////////////////////////////////////////

}

//--------------------------------------------------------------------------------------------

function run() {

   //////////////////////////////////////////////////
	
   set(RULES);

   //////////////////////////////////////////////////
	
   StartDate    = 2015;
   EndDate      = 2017;

   BarPeriod    = 60;
   LookBack     = 200;
   LifeTime     = 3;
   Script       = "DeepLearn"; // DeepLearn.r needed
		
   //////////////////////////////////////////////////

   while(asset(loop("EURUSD"))) while(algo(loop("DeepLearn"))) {

      //////////////////////////////////////////////////

      var  obL = -1.0;
      var  obS = -1.0;

      //////////////////////////////////////////////////

      int ipc = loadINP();

      if(Bar>=LookBack-5) watch("bar",Bar,"| myIPL",myIPL,"| ipc",ipc);

      //////////////////////////////////////////////////

      var avL = adviseLong (NEURAL,obL,myINP,3);
      var avS = adviseShort(NEURAL,obS,myINP,3);

      //////////////////////////////////////////////////

      if(Bar>=LookBack+5) quit();

      //////////////////////////////////////////////////

   }

   //////////////////////////////////////////////////
	
}


Something sets the global variable (IN TRAIN) to 0 after the LookBack period?

Code:
bar 195 | myIPL 3 | ipc 3 
bar 196 | myIPL 3 | ipc 3 
bar 197 | myIPL 3 | ipc 3 
bar 198 | myIPL 3 | ipc 3 
bar 199 | myIPL 3 | ipc 3 
bar 200 | myIPL 3 | ipc 3 
bar 201 | myIPL 0 | ipc 0 
bar 202 | myIPL 0 | ipc 0 
bar 203 | myIPL 0 | ipc 0 
bar 204 | myIPL 0 | ipc 0 
bar 205 | myIPL 0 | ipc 0 
Quit


Removing the obL & obS solves the problem:
Code:
var avL = adviseLong (NEURAL,0,myINP,3);
var avS = adviseShort(NEURAL,0,myINP,3);

bar 195 | myIPL 3 | ipc 3 
bar 196 | myIPL 3 | ipc 3 
bar 197 | myIPL 3 | ipc 3 
bar 198 | myIPL 3 | ipc 3 
bar 199 | myIPL 3 | ipc 3 
bar 200 | myIPL 3 | ipc 3 
bar 201 | myIPL 3 | ipc 3 
bar 202 | myIPL 3 | ipc 3 
bar 203 | myIPL 3 | ipc 3 
bar 204 | myIPL 3 | ipc 3 
bar 205 | myIPL 3 | ipc 3 
Quit


BUT renaming "myINP" to "INPUT" also solves the problem!?

The funny thing is, also renaming "myIPL" to "UHHHH" solves the problem!?

But what is the problem here?


Attached File
input-array-crash000.c  (23 downloads)
Attached File
input-array-crash001.c  (31 downloads)
Posted By: jcl

Re: Strange problem with a global int - 02/22/19 07:48

That's indeed a strange problem. Maybe some internal variable has the same name. We'll look into it.

- It was a bug in NEURAL_LEARN. Had nothing to do with the variable name. This will be fixed in the next update. Workaround: Increase the input array by 1 element, because NEURAL_LEARN stores the objective at the end.

var myINP[4];
...
© 2024 lite-C Forums