#PNN_ARTIFICAL

Download script
Author: Copyright � 2008, MetaQuotes Software Corp.
#PNN_ARTIFICAL

This script implements a Probabilistic Neural Network (PNN), which is a type of artificial intelligence designed to recognize patterns and categorize data based on historical examples. Instead of using standard linear logic, it uses a "neighborhood" approach to determine how similar new market information is to past events.

Here is a breakdown of the core logic in non-technical terms:

1. Pattern Recognition via Similarity

The heart of this script is its ability to compare current market data against a "memory" of past examples. When the script receives new data (a "test example"), it doesn't just look for a direct match. Instead, it measures the distance between the current situation and every saved example in its database.

  • The closer the current market conditions are to a stored example, the higher the "similarity score" becomes.
  • It uses a mathematical formula to ensure that very similar patterns have a much stronger influence on the final decision than distant or unrelated patterns.

2. Class-Based Learning (Buy vs. Sell)

The logic is organized into distinct "classes." In the context of trading, these represent different outcomes—most notably Buy signals and Sell signals.

  • The script maintains separate databases for both Buy and Sell examples.
  • When evaluating a new situation, it calculates a score for the "Buy" class and a separate score for the "Sell" class.

3. Data Management (Storage and Retrieval)

To function effectively, the script includes built-in tools to manage its "memory":

  • Reading: It can pull previously saved historical data from external files into the active system.
  • Writing: It can save new successful patterns into those same files, allowing the system to "learn" or expand its library over time.
  • Updating: It has the ability to dynamically add new examples to its current memory bank as they occur.

4. Final Decision Logic

Once the script has compared the current market data against all saved Buy and Sell examples, it performs a final calculation:

  • It takes the cumulative score of the "Buy" similarity and compares it against the "Sell" similarity.
  • The goal is to determine which class has a higher probability of occurring. By calculating the relative weight of these two scores, the system can produce a normalized value that indicates the strength and direction of the predicted move.

Summary for the User

Essentially, this script acts as an intelligent memory system. It looks at what the market is doing right now, scans its library of "past memories," finds the closest matches, and then predicts the most likely outcome based on which historical pattern is currently being mirrored most closely.

Miscellaneous
Uses files from the file systemIt reads information from a fileIt writes information to file
12 Views
0 Downloads
0 Favorites
#PNN_ARTIFICAL
//+------------------------------------------------------------------+
//|                                                #PNN_ARIFICAL.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#property library

//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
//#define MAX_INPUT 18
//double  SIGMA = ?;

//double INP_SIGNAL[MAX_INPUT];

//int Number_Exempls_Buy = 0;//×èñëî ïðèìåðîâ äëÿ Buy
//double Class_Example_Buy[][MAX_INPUT];
//double Out_class_Buy=0;

//int Number_Exempls_Sell;//×èñëî ïðèìåðîâ äëÿ Buy
//double Class_Example_Sell[][MAX_INPUT];
//double Out_class_Sell=0;

//double test_example[MAX_INPUT];

//PNN_Read_Class("Num_Exempls_Byu",Class_Example_Buy,Number_Exempls_Buy);
//PNN_Read_Class("Num_Exempls_Sell",Class_Example_Sell,Number_Exempls_Sell);
//PNN_Write_Class("Num_Exempls_Byu",Class_Example_Buy);
//PNN_Write_Class("Num_Exempls_Sell",Class_Example_Sell);

//Number_Exempls_Buy = ADD_EXAMPLE(test_example,Class_Example_Buy);
//if(Number_Exempls_Buy  > 0)Out_class_Buy = PNN(SIGMA, test_example,Class_Example_Buy);

//if(NetOutBuy > 0 && NetOutSell > 0)
//OUT =(NetOutBuy - NetOutSell)/(NetOutBuy + NetOutSell);

//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//


//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
//Âûçûâàåòñÿ îòäåëüíî äëÿ êàæäîãî êëàññà
// Ðàññ÷èòûâàåì âûõîä äëÿ êëàññà
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
double PNN(double sigma,double test_example[], double Examples[][]) 
{ 
   int Nk=ArrayRange(Examples,0);
   int d=ArrayRange(Examples,1);
   double sum; 
   sum = 0; 
   // The SUMMATION layer which accumulates the pdf 
   // for each example from the particular class k 
   for ( int i=0; i<Nk; i++ ) 
   { 
      double product = 0; 
      // The PATTERN layer that multiplies the test example by the weights 
      for ( int j=0; j<d; j++ ) 
      product += MathPow(test_example[j] - Examples[i][j],2.0);
      product = product/MathPow( sigma ,2.0); 
      product = MathExp( -product );      
      sum += product;
   } 
   sum /=Nk;
   return (sum);
}
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//


//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
//Äîáàâèòü ïðèìåð â êëàññ
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
int ADD_EXAMPLE(double test_example[],double & Examples[][])
{
   int Nk=ArrayRange(Examples,0);
   int d=ArrayRange(Examples,1);
   ArrayResize(Examples,Nk+1);
   
   for(int i=0;i<d;i++)
      Examples[Nk][i] = test_example[i];
   return (Nk);
}
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//

//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
//Ñ÷èòûâàåì äàííûå èç ôàéëà
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
int PNN_Read_Class(string fname,double & Class_Example[][],int Nk)
{
   int d=ArrayRange(Class_Example,1);
   int numDataRead=0;
   int handle=FileOpen(fname+".net",FILE_BIN|FILE_READ);
   if(handle>0)
    {
     numDataRead = FileReadArray(handle, Class_Example, 0, Nk*d);
     FileClose(handle);
     if(numDataRead != Nk*d) return (false);
     return (true);
    }   
    return (false);
}
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//



//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
//Ñîõðàíÿåì äàííûå â ôàéë
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//
int PNN_Write_Class(string fname,double Class_Example[][])
{
   int Nk=ArrayRange(Class_Example,0);
   int d=ArrayRange(Class_Example,1);

   int handle=FileOpen(fname+".net",  FILE_BIN |FILE_WRITE);
   if(handle>0)
   {
      FileWriteArray(handle, Class_Example, 0, Nk*d); // çàïèñü ïîñëåäíèõ 7 ýëåìåíòîâ
      FileClose(handle);
      return (true);
   }
   Print("Íå ñîõðàíèëîñü íè÷åãî!");
   return (false);   
}
//ææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææææ//

Comments