Neural network in the form of a script - page 4

 
rip:
YuraZ:

It is not always necessary to normalize, who says that the grid MAY and MUST only work with 0 and 1?


I can attach a simple grid with an example, (unfortunately there are no materials at hand right now) - I will do it later

where a simple NN solves this problem without data preparation with normalization

unfortunately this is not the source


the example I gave, though! it's like it's already normalised

the condition has two ranges


1 0-100

2 10-30


you just need to find the ratio of the position in one range - which is known to

in essence this is scaling.

Normalisation is almost always needed. The data must be within the definition range of the activation function.

In the script the sigmoid is [-1;+1]. If you replace it with, say, an exponential ... or square root.


http://www.statsoft.ru/home/portal/applications/NeuralNetworksAdvisor/Adv-new/ActivationFunctions.htm








http://www.statsoft.ru/statportal/tabID__32/MId__141/ModeID__0/PageID__354/DesktopDefault.aspx


here is an example of network creation ... Input is LOW i.e. no normalization

 
YuraZ:

http://www.statsoft.ru/statportal/tabID__32/MId__141/ModeID__0/PageID__354/DesktopDefault.aspx


here is an example of network creation ... The input is LOW i.e. no normalisation


Using non-normalised data is sometimes very useful. They do not lose informativeness, which can be lost during transformations.

And there is no formalized mechanism for determining the informativeness of the training sample...


By the way, the article doesn't show anywhere what activation function is used. Apparently, something with the definition area [-inf;+inf] or [0;+inf] ...

 

changed the program a bit!

slightly changed the output format


SCRIPT now considers it a duty to calculate output data with high accuracy

of course, the program is not universal but specialized for a number of inputs and outputs.

but the size of the hidden layer! is adjusted in the learning process



the next release - I'll try to make it flexible in the number of inputs and outputs

and if successful, I'll add a genetic algorithm

the goal of which will be to kill NEURONS with a large number of errors

and reproduce neurons with few errors!

i.e. search for those neurons in the array that have the least number of errors and breed from them to replace

those neurons that have poorly behaved...


1 The learning rate is currently low

2 Change - the number of hidden neurons of the 1st level is random without logic

3 Stops the learning process if it gets high accuracy on the input and output sample data


Files:
 

How do I use this? Put a script on the chart, piles of numbers started to rewrite... What do they say these numbers say?

 
Blast:

How do I use this? Put a script on the chart, piles of numbers started to rewrite... What do these numbers say?

What do you need them for? I've got my own GA algorithm, but I've hardly understood the code - I need time to figure out where to put inputs, how to output them, when to buy-settle and whether I can do it at all ? Or are you here for the grail?

 
Loknar:
Blast:

How do I use this? Put a script on the chart, piles of numbers started to rewrite... What do these numbers say?

What do you need them for? I've got my own GA algorithm, but I've hardly understood the code - I need time to figure out where to put inputs, how to take them out and when to buy-settle them, if at all? Or maybe you are after the grail here?

Blast , don't look for an Expert Advisor or indicator - it's a long way off.


This is more of a study of the principles of a neural network in MQL4

---

in general, it's reasonable to write it in C++ in the form of DLL, or other fast languages


Loknar - it's just a modification of the script from the beginning to try to get a more accurate output

--

by the way tried to add a layer :-), not to mention outputs inputs ... the pipe learning algorithm just dies in a moment...


---

want to try something like

3 outputs

the output is not just 0 or 1 or -1 0 +1 but a range

x 0 0 - buy hold

0 x 0 - flat (exit buy or sell)

0 0 x sell - hold sell

where x is not 0 or 1 but has some deviation in some range for example -1.000 0.000 +1.000

i.e. can take a value of say 0.1122 or -0.012


the combination of three outputs is analyzed for boundary crossing


entrances 9 on each timeframe - take M1 M5 M15 M30 H1 H4 54 entries in total

we feed the difference between the averages 3 5 8 13 21 34 55 89 144 233 on each traf

total 3-5 5-8 8-13 13-21 21-34 34-55 55-89 89-144 144-233 in total 9 per timeframe

we obtain a sort of VERIABLE of averages in the grid view... :-) in the matrix

when we have something like pattern 2 3 4 5 6 7 8 9 10 11 fan is fully opened upwards judging it is Sell

when we have -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 pattern, the pattern is fully open downwards - BAY

The numbers are arbitrary and sometimes a pattern -1 -3 -7 -10 -15 -20 -30 -40 -80 on a larger timeframe



---

a training sample of something like


1 2 1 0 -3 2 3 0 4 M1

-1 2 -1 0 1 2 3 0 -4 M5

...

........................ H4

 

Preparing data for training





#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
 
static int hWR;
 
static double    ma[9][233] ;
static datetime  SaveTime[9];
static int       indx[8]={3,5,8,13,21,34,55,89,144};
static  int iFW = 0;
 
int init()
  {
   hWR = FileOpen( "MA.CSV", FILE_BIN|FILE_WRITE) ; 
   string strPut="DATETIM            |"+
   "m100035|m010058|m010813|m011321|m012134|m013455|m015589|"+
   "m500035|m050058|m050813|m051321|m052134|m053455|m055589|"+
   "m150035|m150058|m150813|m151321|m152134|m153455|m155589|"+
   "m300035|m300058|m300813|m301321|m302134|m303455|m305589|"+
   "h010035|h010058|h010813|h011321|h012134|h013455|h015589|";
 
 
 
// "-0.0001|-0.0001|-0.0001|-0.0001|-0.0001|-0.0001|-0.0001|-0.0001|
   FileWrite(hWR, strPut);
   return(0);
  }
int deinit()
  {
  FileClose(hWR);
  }
 
int start()
{
  iFW = 0;
  getMA( PERIOD_M1 ,1);
  getMA( PERIOD_M5 ,2);
  getMA( PERIOD_M15,3);
  getMA( PERIOD_M30,4);
  getMA( PERIOD_H1 ,5);
  getMA( PERIOD_H4 ,6);
   if ( iFW == 1 )
   {
      PutFile( );
   }
   return(0);
}
void getMA(int TF,int iTF)
{
 if ( SaveTime[iTF] != iTime(Symbol(),TF,0) )
 {
 SaveTime[iTF] = iTime(Symbol(),TF,0);
 ma[iTF][89] =  iMA(Symbol(),TF,89,0,MODE_EMA,PRICE_CLOSE,0);
 ma[iTF][55] =  iMA(Symbol(),TF,55,0,MODE_EMA,PRICE_CLOSE,0);
 ma[iTF][34] =  iMA(Symbol(),TF,34,0,MODE_EMA,PRICE_CLOSE,0);
 ma[iTF][21] =  iMA(Symbol(),TF,21,0,MODE_EMA,PRICE_CLOSE,0);
 ma[iTF][13] =  iMA(Symbol(),TF,13,0,MODE_EMA,PRICE_CLOSE,0);
 ma[iTF][ 8] =  iMA(Symbol(),TF, 8,0,MODE_EMA,PRICE_CLOSE,0);
 ma[iTF][ 5] =  iMA(Symbol(),TF, 5,0,MODE_EMA,PRICE_CLOSE,0);
 ma[iTF][ 3] =  iMA(Symbol(),TF, 3,0,MODE_EMA,PRICE_CLOSE,0);
 iFW = 1;
 }
}
void  PutFile( )
{
 string strPut;
 strPut = TimeToStr( SaveTime[1] , TIME_DATE|TIME_MINUTES|TIME_SECONDS) ;
 for ( int iiTF = 1; iiTF <= 6; iiTF++)
 {
   for ( int jM = 0; jM <= 6; jM++)
   {
      int nMA = indx[jM];
      int nMA_N = indx[jM+1];
      double nn = NormalizeDouble( (ma[iiTF][ nMA] - ma[iiTF][ nMA_N])/Point,0) ;
      string sss = DoubleToStr( nn , 0);
      if ( nn >= 0 )
         sss =" "+sss;
      if (MathAbs(nn)  <= 9)
         sss =" "+sss;
       
         
      // strPut = strPut+DoubleToStr( ma[iiTF][ nMA] , 4)+"|";
      strPut = strPut+"|"+sss;
   }
 }
 FileWrite(hWR, strPut);
}
 
Loknar:
Blast:

How do I use this? Put a script on the chart, piles of numbers started to rewrite... What do these numbers say?

What do you need them for? I've got my own GA algorithm, but I've hardly understood the code - I need time to figure out where to put inputs, how to take them out and when to buy-settle them, if at all? Or have you gone for the grail here?

Initially I like the idea of neural networks. All I know about it is that having 1000 points somehow the network will converge to one point... and that autotrading was won with an EA based on the network algorithm. I have plans to create my own version of such network but at this stage I do not understand anything either in mql4 or in neural networks.

Therefore, first I will put my strategy into Expert Advisor to learn mql4. And then I will start thinking about networks.

I have downloaded your version just for the sake of interest. It is the first time I have encountered such things. I do not understand the operation of such networks. I have no idea how such networks work, so I have got such questions.

I shall be glad to any references on the similar subjects, which in your opinion are worthy of attention!

 

THIS NETWORK

YuraZ:

changed the software a bit!

changed a little the format of displaying

now SCRIPT considers it a duty to calculate with high accuracy the output data

the program is not universal but specialized for number of inputs and outputs

but the size of the hidden layer! is adjusted in the learning process



the next release - I'll try to make it flexible in the number of inputs and outputs

and if successful, I'll add a genetic algorithm

the goal of which will be to kill NEURONS with a large number of errors

and reproduce neurons with few errors!

i.e. search for those neurons in the array that have the least number of errors and breed from them to replace

those neurons that have poorly behaved...


1 The learning rate is currently low

2 Change - the number of hidden neurons of the 1st level is random without logic

3 Stop learning if it gets high accuracy on the input and output sample data


THE SAME NETWORK but written in Microsoft Visual C++ 6.0

Speed is orders of magnitude higher than in MQL4

the algorithm is unchanged, the transfer from MQL4 to C++ is as straightforward as possible without using class objects

Files:
yzpnn.zip  63 kb
 

Another option but on MQL


just trying to work on M1 shows the current trend direction

exit on the 3rd, in theory you can not teach at startup - but immediately take ready Weights - teach in advance


---

9 inputs to which the normalized difference of muwings is fed

---

out-1 out-2 out-3 output

0.9 0.01 0.01 trend up

0.01 0.9 0.01 flet

0.01 0.01 0.9 trend down



---

I plan to add 3-4 timeframes and count them all at once!

PNN when already weighed works very fast

---


Experimental test code - please dont kick me.






Files: