Neural networks, how to master them, where to start? - page 5

 
meta-trader2007 >> :

I mean a simple linear perseptron, like the one used by Reshetov. Rosenblatt created his perseptron as a model of brain function), a very primitive model...

The simple linear perseptron used by Mr Reshetov is more than 40 years out of date.

The real history of neural networks began with the Rosenblatt perseptron with its activation function.

 
TheXpert >> :

The simple linear perseptron used by Mr Reshetov is more than 40 years out of date.

The real history of neural networks began with the Rosenblatt perseptron with its activation function.

But his perseptron is not perfect either. And it is no good at predicting course direction.

So in Rosenblatt's two layer perseptrons (he created them first), the first hidden layer played the role of an activation function?

 
meta-trader2007 >> :

But his perseptron is not perfect either. And it is not suitable for predicting the direction of the course.

I.e. in Rosenblatt's two layer perseptrons (he created them first) the first hidden layer played the role of an activation function?

I'm following the topic, but you are talking about higher matters. We should at least understand how to do something simple...


Here's an algorithm of a simple Expert Advisor:

Let's take for example a simple algorithm that gives entry points with stop losses and take profits based on the last fractal:

If we have a fractal upwards, we put a Buy Stop order for a fractal breakthrough, with a stop loss below the minimum price among the bars from zero to the bar at which the fractal was formed. Take profit is equal to the stop loss.


Here is the code of this Expert Advisor:

extern double    Lot=0.1;
extern int       Slippage=3; // Проскальзывание
extern int       Magic=1;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
 int i;
 
// Фрактал вверх 
 int iUpFr;   // Номер бара на котором образовался последний фрактал вверх
 double UpFr; // Значение последнего фрактала вверх 

for ( i=3; i<Bars; i++){
UpFr=iFractals(NULL,0,MODE_UPPER, i);
  if ( UpFr>0){
  iUpFr= i;
  //Print ("UpFr = ", UpFr, ", ", " iUpFr = ", iUpFr);
  break;
  }
}   
// Проверяем прорван-ли найденый фрактал, если он прорван, то по нему не имеет смысла выставлять ордер
bool OkUpFr; // Если false, то прорван, если true, то не прорван
if( UpFr>=High[iHighest(NULL,0,MODE_HIGH, iUpFr,0)]){ OkUpFr=true;}

double SellSl=High[iHighest(NULL,0,MODE_HIGH, iUpFr+1,0)]; // Минимальное значение цены от нулевого бара до номера на котором сформировался последний фрактал вверх


// Фрактал вниз
 int iDnFr;   // Номер бара на котором образовался последний фрактал вниз
 double DnFr; // Значение последнего фрактала вниз
 
for ( i=3; i<Bars; i++){
DnFr=iFractals(NULL,0,MODE_LOWER, i);
  if ( DnFr>0){
  iDnFr= i;
  //Print ("DnFr = ", DnFr, ", ", " iDnFr = ", iDnFr);
  break;
  }
} 
// Проверяем прорван-ли найденый фрактал, если он прорван, то по нему не имеет смысла выставлять ордер
bool OkDnFr; // Если false, то прорван, если true, то не прорван
if( DnFr<=Low[iLowest(NULL,0,MODE_LOW, iDnFr,0)]){ OkDnFr=true;}

double BuySl=Low[iLowest(NULL,0,MODE_LOW, iDnFr+1,0)]; // Максимальное значение цены от нулевого бара до номера на котором сформировался последний фрактал вниз
 
 // Параметры ордеров
  double Tick=MarketInfo(Symbol(),MODE_TICKSIZE);
  double spread=MarketInfo(Symbol(),MODE_SPREAD)* Tick;

  double B;
  double Bsl;
  double S;
  double Ssl;    
  double Btp; 
  double Stp; 
  B=NormalizeDouble( UpFr+1* Tick+ spread,Digits);      // Цена для покупки
  Bsl=NormalizeDouble( BuySl-1* Tick,Digits);          // Стоп лосс для ордера на покупку
  Btp=NormalizeDouble( B+( B- Bsl),Digits);             // Тейк профит для ордера на покупку
  S=NormalizeDouble( DnFr-1* Tick,Digits);             // Цена для продажи
  Ssl=NormalizeDouble( SellSl+ spread+1* Tick,Digits);  // Стоп лосс для ордера на продажу
  Stp=NormalizeDouble( S-( Ssl- S),Digits);             // Тейк профит для ордера на продажу
  
bool Buy; // если Buy==true, значит появились условия для Buy stop
bool Sell;// если Sell==true, значит появились условия для Sell stop

if( OkUpFr==true){ Buy=true;}
if( OkDnFr==true){ Sell=true;}
 
// Проверка открытых ордеров и выставленых ордеров
int total = OrdersTotal(); // Общее кол-во открытых и отложеных ордеров.
int Ticket = OrderTicket( ); // Возвращает номер тикета для текущего выбранного ордера. 
bool PendingOrderBuy=false;  
bool PendingOrderSell=false;   
bool MarketOrderBuy=false;
bool MarketOrderSell=false;
if( total>0){  
  for( i=0; i<= total; i++){
     if (OrderSelect( i, SELECT_BY_POS)==true){
        if (OrderSymbol()==Symbol() && OrderMagicNumber()== Magic){
         double OpenPrice=NormalizeDouble(OrderOpenPrice(),Digits);
         double StopLoss=NormalizeDouble(OrderStopLoss(),Digits);
         double TakeProfit=NormalizeDouble(OrderTakeProfit(),Digits);
         Ticket = OrderTicket( );
           if (OrderType( )==OP_BUY){
           MarketOrderBuy = true;
           }
           if (OrderType( )==OP_SELL){
           MarketOrderSell = true;
           }
           if (OrderType( )==OP_BUYSTOP){
           PendingOrderBuy = true;
           if( OpenPrice!= B) {OrderDelete( Ticket,CLR_NONE);} 
           if( StopLoss!= Bsl){OrderDelete( Ticket,CLR_NONE);}       
           }
           if (OrderType( )==OP_SELLSTOP){
           PendingOrderSell = true;
           if( OpenPrice!= S) {OrderDelete( Ticket,CLR_NONE);} 
           if( StopLoss!= Ssl){OrderDelete( Ticket,CLR_NONE);}    
           }  
        }
     }
  }
} 
// Выставление отложеных ордеров
if( Buy==true && PendingOrderBuy==false && MarketOrderBuy==false){
         Ticket=OrderSend (Symbol(),OP_BUYSTOP, Lot, B, Slippage, Bsl, Btp,NULL, Magic,0,CLR_NONE);
         if( Ticket<0)
         {
         Print("OrderSend failed with error #",GetLastError());
         return(0);
         }
}
if( Sell==true && PendingOrderSell==false && MarketOrderSell==false){
         Ticket=OrderSend (Symbol(),OP_SELLSTOP, Lot, S, Slippage, Ssl, Stp,NULL, Magic,0,CLR_NONE);
         if( Ticket<0)
         {
         Print("OrderSend failed with error #",GetLastError());
         return(0);
         }
}     
//----
   return(0);
  }

In this algorithm, you can select several anchor points, on the basis of which the fractal model will be measured:


Parameters, which can be used as weights:

To buy:
iUpFr
iUpFr-iSellSl
UpFr-SellSl
(UpFr-SellSl)/(iUpFr-iSellSl)
(UpFr-SellSl)/(iUpFr)

To sell:
iDnFr
iDnFr-iBuySl
BuySl-DnFr
(BuySl-DnFr)/(iDnFr-iBuySl)
(BuySl-DnFr)/(iDnFr)


Do I understand correctly that the next step of neural network creation will be introduction of variables that will be compared to these properties?

And the comparison will take place during optimization?

If I'm wrong, what further practical steps do I need to take in order to bolt on this EA, a simple neural network?



 

The mathematics of neural networks is not that complicated. The choice of input parameters is much more important to the success of network prediction. The question here is: which indicators and their parameters fully describe the current state of the market and its history? Knowing only a few past prices of a currency is far from sufficient to predict the future price no matter how many layers are in the network. This is why you have to choose either a lot of past prices or indicators of different periods. The vast majority use indicators as they allow a more efficient way to describe the position of the last price to past prices. Maybe we should switch the discussion to the selection of input parameters. I think the correlation of recent values of muves of different periods can be a good input for the network. Who has a different opinion? Can different types of indicators, e.g. MACD, RSI, AC, Stoch, etc., be mixed on the input of the same network?

 
gpwr >> :

Can different types of indicators, e.g. MACD, RSI, AC, Stoch, etc., be mixed on the input of the same network?

I think you can, as long as the set of indicators gives good market entries. After this we have another difficult question - what should we provide to the net output during training? What do we want? To recognize a pattern? Predict the colour of the next candle? Or maybe not one but several? Or maybe we want to predict the magnitude of the movement? )))

I would like to find the answers to these questions.

Maybe practitioners will tell me, what do they train their nets on? :))

 

Dear forum members, the topic of this thread is Neural Networks, how to master them, where to start?

Let's get closer to the topic....

 

Guys, it's not about neural networks - it's about the way they are applied......

 
Andrey4-min писал(а) >>

Dear forum members, the topic of this thread is Neural Networks, how to learn them to begin with?

Let's get closer to the topic....

Here is a short description of forward networks, which I sometimes quote when a similar topic arises. So, let's create a simple forward network.

Step 1: Choose input data. For example,

x1 = WPR Per1

x2 = WPR Per2

x3 = WPR Per3

Step 2: Select the number of neurons in the hidden layer, for example two neurons, y1 and y2. Select the number of neurons in the output layer, for example two neurons, z1 and z2. Thus, we have created a 3-2-2 network. z1 and z2 are our outputs.

Step 3: Set decision logic. For example z1>=u buy, z1<=-u sell, z2<=-v close buy, z2>=v close sell, where |u|<=1 and |v|<=1.

Step 4: Describe the hidden neurons y1=F(x1,x2,x3) and y2=F(x1,x2,x3):

y1 = F(a0+a1*x1+a2*x2+a3*x3)

y2 = F(b0+b1*x1+b2*x2+b3*x3)

where F() is a non-linear function. For example, F(x)=tanh(x)=(exp(x)-exp(-x))/(exp(x)+exp(-x)). I prefer a simpler function to avoid errors when calculating exp():

F(x) = -1 if x<=-1, x if -1<x<1, 1 if x>=1.

Step 5: Describe the output neurons z1=F(y1,y2) and z2=F(y1,y2):

z1 = F(c0+c1*y1+c2*y2)

z2 = F(d0+d1*y1+d2*y2)

where F() is the same neuron activation function.

So, the network has been created and described. Give periods Per1, Per2 and Per3 for Williamps-Percent-Range (WPR) and optimize via metadrae batter a0, a1, a2, a3, b0, b1, b2, b3, c0, c1, c2, d0, d1, d2, -1<=u<=+1, -1<=v<=+1. You can also optimize Per1, Per2 and Per3. You can play around with different inputs. For example, instead of WPR try MACD or another indicator. You can limit it to one output neuron for opening positions: z(y1,y2)>=u buy, z(y1,y2)<=-u sell. And close by stoploss, trailing stop or takeprofit.

You can also create a more complex network where each trade decision is associated with a corresponding output neuron. For example, with the same input data and hidden neurons we create 4 output neurons

z1(y1,y2)>u1 - open long

z2(y1,y2)>u2 - open short

z3(y1,y2)>u3 - close long

z4(y1,y2)>u4 - close short

In this case, the number of optimized coefficients increases significantly. Usually u1=u2=u3=u4=0.9.

You can increase the number of hidden layers and neurons in them if you have a powerful computer.

 
Andrey4-min писал(а) >>

Dear forum members, the topic of this thread is Neural Networks, how to master them and where to start?

Let's get closer to the subject....

Don't bother programming neural networks yourself, there are ready-made programs. The only program that has a book in Russian - Statistica Neural Networks, and this book gives the impression that it is really written by experts in neural networks, and has a pretty decent introduction and overview of neural networking techniques and existing types of neural networks. The program allows to export trained networks as a dll which can be used in MT Expert Advisors (haven't tried it myself though, sorry if I'm wrong). The specialised trader programs with non-networks are not so easy to attach to MT, and if it is possible, they are crooked or very expensive. There are broker terminals that export data to meta files, it is not so easy to implement specialized software for working with non-growing networks. Eh! Why don't MT developers provide the possibility to export data to be able to use any other programs of theancial analysis without unnecessary changes.

 

For starters, imho, the best program is NeuroShell -2, there is a Russian helpline and examples in Russian. Also, neural networks from NS 2 can be easily attached to expert advisors and indicators in MT4.

You can read here: http://www.fxreal.ru/forums/forums.php?forum=3

Reason: