Examples: Using Neural Networks In MetaTrader - page 8

 

Hi, Mariusz,

Thanks for your respond. I've read about bias neuron but I didn't knew that it indicated by profile...

And one else )) I found a small inaccuracy in Fann2MQL.mqh. On the left side present list, on the right side correct list. Am I right?

#define FANN_LINEAR                     0	FANN_LINEAR,                
#define FANN_THRESHOLD	                1       FANN_THRESHOLD,                 
#define FANN_THRESHOLD_SYMMETRIC        2       FANN_THRESHOLD_SYMMETRIC,       
#define FANN_SIGMOID                    3       FANN_SIGMOID,                   
#define FANN_SIGMOID_STEPWISE           4       FANN_SIGMOID_STEPWISE,          
#define FANN_SIGMOID_SYMMETRIC          5       FANN_SIGMOID_SYMMETRIC,         
#define FANN_SIGMOID_SYMMETRIC_STEPWISE 6       FANN_SIGMOID_SYMMETRIC_STEPWISE,
#define FANN_GAUSSIAN                   7       FANN_GAUSSIAN,                  
#define FANN_GAUSSIAN_SYMMETRIC         8       FANN_GAUSSIAN_SYMMETRIC,        
#define FANN_ELLIOT                     9       FANN_GAUSSIAN_STEPWISE,         
#define FANN_ELLIOT_SYMMETRIC           10      FANN_ELLIOT,                    
#define FANN_LINEAR_PIECE               11      FANN_ELLIOT_SYMMETRIC,          
#define FANN_LINEAR_PIECE_SYMMETRIC     12      FANN_LINEAR_PIECE,              
#define FANN_SIN_SYMMETRIC              13      FANN_LINEAR_PIECE_SYMMETRIC,    
#define FANN_COS_SYMMETRIC              14      FANN_SIN_SYMMETRIC,             
#define FANN_SIN                        15      FANN_COS_SYMMETRIC,             
#define FANN_COS                        16      FANN_SIN,                       
                                                FANN_COS                        
 
Henry_White:

Hi, Mariusz,

Thanks for your respond. I've read about bias neuron but I didn't knew that it indicated by profile...

And one else )) I found a small inaccuracy in Fann2MQL.mqh. On the left side present list, on the right side correct list. Am I right?

#define FANN_LINEAR                     0	FANN_LINEAR,                
#define FANN_THRESHOLD	                1       FANN_THRESHOLD,                 
#define FANN_THRESHOLD_SYMMETRIC        2       FANN_THRESHOLD_SYMMETRIC,       
#define FANN_SIGMOID                    3       FANN_SIGMOID,                   
#define FANN_SIGMOID_STEPWISE           4       FANN_SIGMOID_STEPWISE,          
#define FANN_SIGMOID_SYMMETRIC          5       FANN_SIGMOID_SYMMETRIC,         
#define FANN_SIGMOID_SYMMETRIC_STEPWISE 6       FANN_SIGMOID_SYMMETRIC_STEPWISE,
#define FANN_GAUSSIAN                   7       FANN_GAUSSIAN,                  
#define FANN_GAUSSIAN_SYMMETRIC         8       FANN_GAUSSIAN_SYMMETRIC,        
#define FANN_ELLIOT                     9       FANN_GAUSSIAN_STEPWISE,         
#define FANN_ELLIOT_SYMMETRIC           10      FANN_ELLIOT,                    
#define FANN_LINEAR_PIECE               11      FANN_ELLIOT_SYMMETRIC,          
#define FANN_LINEAR_PIECE_SYMMETRIC     12      FANN_LINEAR_PIECE,              
#define FANN_SIN_SYMMETRIC              13      FANN_LINEAR_PIECE_SYMMETRIC,    
#define FANN_COS_SYMMETRIC              14      FANN_SIN_SYMMETRIC,             
#define FANN_SIN                        15      FANN_COS_SYMMETRIC,             
#define FANN_COS                        16      FANN_SIN,                       
                                                FANN_COS                        

FANN_GAUSSIAN_STEPWISE not implemented yet in FANN
http://fann.cvs.sourceforge.net/viewvc/fann/fann/src/include/fann_data.h?view=markup
 
Dali:
FANN_GAUSSIAN_STEPWISE not implemented yet in FANN
http://fann.cvs.sourceforge.net/viewvc/fann/fann/src/include/fann_data.h?view=markup

  You are right, but the point is that this record implemented in "enum"-record in FANN-kernel sources. That means if you choose FANN_SIN_SYMMETRIC mode in MQL it will be translated in FANN-kernel as number 13, where it means FANN_LINEAR_PIECE_SYMMETRIC.

 

Henry_White wrote:

You are right, but the point is that this record implemented in "enum"-record in FANN-kernel sources. That means if you choose FANN_SIN_SYMMETRIC mode in MQL it will be translated in FANN-kernel as number 13, where it means FANN_LINEAR_PIECE_SYMMETRIC.

Indeed. I was thinking this omitting is adjusted in F2M, but doesn't looked up in source. I was wrong.
 

The Fann2MQL is linked with FANN version that is using following definition:


enum fann_activationfunc_enum
{
FANN_LINEAR = 0,
FANN_THRESHOLD,
FANN_THRESHOLD_SYMMETRIC,
FANN_SIGMOID,
FANN_SIGMOID_STEPWISE,
FANN_SIGMOID_SYMMETRIC,
FANN_SIGMOID_SYMMETRIC_STEPWISE,
FANN_GAUSSIAN,
FANN_GAUSSIAN_SYMMETRIC,
/* Stepwise linear approximation to gaussian.
* Faster than gaussian but a bit less precise.
* NOT implemented yet.
*/
FANN_GAUSSIAN_STEPWISE,
FANN_ELLIOT,
FANN_ELLIOT_SYMMETRIC,
FANN_LINEAR_PIECE,
FANN_LINEAR_PIECE_SYMMETRIC,
FANN_SIN_SYMMETRIC,
FANN_COS_SYMMETRIC,
FANN_SIN,
FANN_COS
};


Which means the numbers are as follows:

0 FANN_LINEAR = 0,
1 FANN_THRESHOLD,
2 FANN_THRESHOLD_SYMMETRIC,
3 FANN_SIGMOID,
4 FANN_SIGMOID_STEPWISE,
5 FANN_SIGMOID_SYMMETRIC,
6 FANN_SIGMOID_SYMMETRIC_STEPWISE,
7 FANN_GAUSSIAN,
8 FANN_GAUSSIAN_SYMMETRIC,
9 FANN_GAUSSIAN_STEPWISE,
10 FANN_ELLIOT,
11 FANN_ELLIOT_SYMMETRIC,
12 FANN_LINEAR_PIECE,
13 FANN_LINEAR_PIECE_SYMMETRIC,
14 FANN_SIN_SYMMETRIC,
15 FANN_COS_SYMMETRIC,
16 FANN_SIN,
16 FANN_COS

so the numbers in Fann2MQL.mqh are correct.



Always when in doubt please use FannExplorer or FanTool to create your network, save it to the file then examine it with editor (preferably a decent vim). Also many network management operations are MUCH easier to perform using aforementioned tools than coding it with Fann2MQL in MQL. Consider Fann2MQL as useful only to execute (train/run) the networks not to create it, manage, modify or find the best suitable one. There are better tools to do that.

 
emsi:

so the numbers in Fann2MQL.mqh are correct.

See my attachment. This Fann2MQL.mqh file was extracted by installation pakage ("Fann2MQL 0.1.2.msi"). There are only 17 records instead of FANN-source (18 records).

By the way, in listing below you have a double enumerating:

16 FANN_SIN,
16 FANN_COS


Always when in doubt please use FannExplorer or FanTool to create your network, save it to the file then examine it with editor (preferably a decent vim). Also many network management operations are MUCH easier to perform using aforementioned tools than coding it with Fann2MQL in MQL. Consider Fann2MQL as useful only to execute (train/run) the networks not to create it, manage, modify or find the best suitable one. There are better tools to do that.

Yep. I've realized this. The most useful thing in FANN Tools is detecting "Optimum activation function". And of course, training is much faster than by MQL.
 
Henry_White:
emsi:

so the numbers in Fann2MQL.mqh are correct.

See my attachment. This Fann2MQL.mqh file was extracted by installation pakage ("Fann2MQL 0.1.2.msi"). There are only 17 records instead of FANN-source (18 records).

By the way, in listing below you have a double enumerating:

16 FANN_SIN,
16 FANN_COS

Yes you are right! There is a bug! Thanks for spotting it! I'll correct it next release. Oddly I almost repeated it while checking if it's correct.

Once again thank you for reporting it.

 

The new version fixing this bug is available at:

http://fann2mql.wordpress.com/download/ !

 

 I would like to try other signals and would like to modify the code.

Some Questions: 

   AnnInputs=(AnnInputs/3)*3; // Make it integer divisible by 3
   if(AnnInputs<3) 
     {
      debug(0,"AnnInputs too low!");
     }
// Compute MagicNumber and AnnPath
   MagicNumber+=(SlowMA+256*FastMA+65536*SignalMA);
   AnnPath=StringConcatenate(ANN_PATH,NAME,"-",MagicNumber);

"MagicNumber+=(SlowMA+256*FastMA+65536*SignalMA);"

Q1: What is the significance of 256? Can any magic number works? What is the rational of "SlowMA+256*FastMA+65536*SignalMA"

 

void ann_prepare_input()
  {
   int i;
   for(i=0;i<=AnnInputs-1;i=i+3) 
     {
      InputVector[i]=
         10*iMACD(NULL,0,FastMA,SlowMA,SignalMA,PRICE_CLOSE,
                  MODE_MAIN,i*3);
      InputVector[i+1]=
         10*iMACD(NULL,0,FastMA,SlowMA,SignalMA,PRICE_CLOSE,
                  MODE_SIGNAL,i*3);
      InputVector[i+2]=InputVector[i-2]-InputVector[i-1];
     }
  }

Q2: 

Why 10*?

Why i*3?

What is  InputVector[i+2]=InputVector[i-2]-InputVector[i-1];?

 

Thanks in advance! 

 

I think its a pitty that this thread comes first in google when one searches for neural networks in metatrader...

apart from the fact that the parameters of the example are highly optimized so as to show good results, if someone tries to really filter some signals by setting the delta to zero he would get the same negative value whatever the input values would be...

in fact,the network output relies heavily on the training that is done while it is forward-tested.....so if many signals get filtered out then it stops working...

great bug that I think emsi should take a look at and remove the library if he doesnt find a solution