Discussion of article "Using Self-Organizing Feature Maps (Kohonen Maps) in MetaTrader 5" - page 4

 
Graff:

I don't know what they're for. You can get the information directly from the terminal.

It's scary to even imagine what they are used for, probably someone counted them manually.

SZY: can someone post a mod so that the Expert Advisor can directly pull in information from the terminal, without a script?

Well, if you are scared, then of course not).
 
sergeev:
What information do you need?
Which is unloaded by the script into a file and retracted by the Expert Advisor for analysis. i.e. so that the SOM.mq5 Expert Advisor can independently (without the help of the DJ.mq5 and FX.mq5 script) receive data from the terminal.
 

Does this article include everything to get a expert advisor?

Im interested in implementing Neural Network Expert Advisor.

 

Hello, dear forum members!

Very interesting article! I am trying to use this SOM code too.

somk

Weights p1-p4 - data from the market (so far just the difference between ZZ points).

p5 - result of a virtual Buy trade - TP=1, SL=-1 (so far TP=SP=300pp). On the forward just one p5 BMU (closest vector) is not enough to predict the result, it seems to me.

Can anyone suggest how to make calculation of the result of the area around the BMU (for clarity obver blue), taking into account the distance from the BMU ?

 
sealdo:

Can anyone tell me how easier it is to calculate the result of the area around the BMU (circled in blue for clarity), taking into account the distance from the BMU ?

I was wondering, is that what I was thinking too? you mean how to programmatically find this area with coordinates?
 
progma137:
I'm wondering, is that what I thought too? You mean how to programmatically find this area with coordinates?

There is already a function in the CSOM class:

int BestMatchingNode(double &vector[]); // find the best node in the grid based on a given vector

Knowing the dimensionality of our grid, it is easy to calculate the coordinates of the BMU (or BMN in this implementation).
Here we want to do exactly the calculation of the total result (by one parameter (weight)) of the area around the BMU, taking into account the distance from the BMU. For example, we take a region with a diameter of 10 neurons (cells). The closest neurons have a high influence on the result. And the further away, the weaker....

Here we have a question how we should treat BMU-shells located at the edges of the grid. After all, they have fewer neighbours.

 

Can you please tell me how to find bars on maps?

We input four vectors and get 4 maps. I would like to draw a trajectory on all of them, say, from the current day (for the days) to 3 bars back and analyse the state of clusters.

It is possible to do it programmatically, for example, with void DrawTrajectory(int from, int count) function, which will draw a trajectory from a given bar number on all maps.

And the second question, how to get the output map and, most importantly, the frequency map?

 

I didn't wait for a response... I wrote the method of displaying on the input maps of the trajectory from the given number of the input vector by the given number of steps, don't forgive me if something is wrong - I'm not a programmer :)

Can someone bring this very clever library (thanks to the author and Alexey Sergeev) to the level of practical application?!!!!!


//------------------------------------------------------------------ ShowTrajectory
void CSOM::ShowTrajectory(int n_patern, int m_cnt) // Method of showing the trajectory of input vectors
{
        if(m_cnt<=0) return;
        int idx=0,x[],y[], dy=0;
        string name[];
        ArrayResize(x,m_cnt);
        ArrayResize(y,m_cnt);
        ArrayResize(name,m_cnt);
        double data[]; ArrayResize(data, m_dimension);
   for(int ind=0; ind<m_nSet; ind++) // set data by vector values from the training set
  {
        if(ind<n_patern) continue;  // wait for the required input pattern
        for(int k=0; k<m_dimension; k++) data[k]=m_set[m_dimension*(ind)+k];
        int winningnode=BestMatchingNode(data); // find the index of the nearest node
                
         // save coordinates of input patterns selected for tracing
        int x1,y1,x2,y2;
        m_node[winningnode].GetCoordinates(x1,y1,x2,y2);
        if(m_bHexCell) // if hexagons
      {
          int x_size=int(MathAbs(x2-x1));
          int y_size=int(MathAbs(y2-y1));
          dy=y_size;
          y1=y1+y_size/4; 
          y2=y2+y_size/4;
      }
        x[idx]=(x1+x2)/2;
        y[idx]=(y1+y2)/2;               
        name[idx]=(string)ind;
        //x[idx]=(int)m_node[winnode].X();
        //y[idx]=(int)m_node[winnode].Y();
        idx++;
        m_cnt--;        
        if(m_cnt==0) break;      // record the required number of input paternions
  }
  // draw the trajectory, nodes and inscriptions
   int bcol=clrBlack;
   for(int k=0; k<m_dimension; k++)
  {
      int yp=0, yc;
      int sz=ArraySize(x);
      for(int j=0; j<sz; j++) 
    {
         yc=y[j];
         // node
         int sh=2;
         if(j>0) sh=1;
         m_bmp[k].DrawRectangle(x[j]-sh,y[j]-sh,x[j]+sh,y[j]+sh,bcol,true);
         // trajectory
         if(j<sz-1) m_bmp[k].DrawLine(x[j],y[j],x[j+1],y[j+1],bcol);  
         yc=y[j]-dy;
         if(MathAbs(yp-yc)<dy) yc-=dy;
         yp=yc;
         // number of paternas (bars) 
         m_bmp[k].TypeText(x[j],yc,name[j], clrIndigo);
    }    
  }
}
 

In CSOM class the counter of loaded training vectors m_nSet is reset only in CSOM::CSOM() constructor.

As a result, the number of training vectors is constantly growing in the looped retraining mode.

It is better to add the line m_nSet=0; to the method CSOM::LoadTrainData(...) .

 
GSB:

Maybe someone will bring a very useful library (thanks to the author and Alexey Sergeev) to the level of practical use?!!!!


What do you mean? beautiful SDK? or beautiful pictures produced by the program? who needs what, he does it. these maps are nothing more than a means to establish data that need to be analysed and based on them to make conclusions