Author: Copyright � 2008, MetaQuotes Software Corp.
0 Views
0 Downloads
0 Favorites
mt4fann2
//+------------------------------------------------------------------+
//|                                                     mt4fann1.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#include <mt4fann200_1.mqh>
#define NUM_INPUT 2
#define NUM_HIDDEN 3
#define NUM_OUTPUT 1

string EA_NAME = "FANN_";
int train_iterations = 10000;
double input[NUM_INPUT];
double output[NUM_OUTPUT];


int fann = 0;

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----

  
  // *** INITIALIZE ***
  string fname = EA_NAME + Symbol() + "P" + Period() + ".NN";

  Print( "Creating a brand new Neural Network..." );
  fann = FANN_Create( NUM_INPUT, NUM_OUTPUT, NUM_HIDDEN );



  // *** TRAIN ***
  for ( int k = 0; k < train_iterations; k++ )
  {
      input[0]=0;
      input[1]=0;    
      output[0]=0;       
      FANN_Train( fann, input, output );                
      input[0]=0;
      input[1]=1;
      output[0]=1;       
      FANN_Train( fann, input, output );                                  
      input[0]=1;
      input[1]=0;      
      output[0]=1;       
      FANN_Train( fann, input, output );                            
      input[0]=1;
      input[1]=1;     
      output[0]=0;             
      FANN_Train( fann, input, output );                      
  }

  string s1="";
  
      input[0]=0;
      input[1]=0;    
      output[0]=0;       
      FANN_Run( fann, input, output );                
      s1=s1+input[0]+" xor "+input[1]+" = "+output[0]+"\n";
      input[0]=0;
      input[1]=1;
      output[0]=0;       
      FANN_Run( fann, input, output );                                  
      s1=s1+input[0]+" xor "+input[1]+" = "+output[0]+"\n";
      input[0]=1;
      input[1]=0;      
      output[0]=0;       
      FANN_Run( fann, input, output );                            
      s1=s1+input[0]+" xor "+input[1]+" = "+output[0]+"\n";
      input[0]=1;
      input[1]=1;     
      output[0]=0;             
      FANN_Run( fann, input, output );       
      s1=s1+input[0]+" xor "+input[1]+" = "+output[0]+"\n";
  Comment(s1);
  // *** SHUTDOWN ***
  Print( "Saving network..." + fname );
  FANN_Save( fann, fname );
  
  Print( "Cleanup..." );
  FANN_Destroy( fann );   
  
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments