Calcolo delle differenze, esempi. - pagina 8

 
Yuriy Asaulenko:


Qual è il vantaggio di RU?

Non pretendendo affatto un vantaggio.

Secondo me:

Se inizialmente immaginiamo un'immagine del sistema da modellare (anche complessa: aereo, automobile) con qualche certezza, è più conveniente marcare immediatamente lo spazio (per esempio il sistema cartesiano) e modellare il sistema utilizzando l'intero apparato matematico. L'approccio "design from the top".

Se non avete un quadro completo del sistema (avvicinatevi alla foresta, alla palude o al forex:) sto parlando di me stesso ), allora dovete fare affidamento sui passi già fatti e su una visione abbastanza ristretta. Questo è più vicino al calcolo delle differenze (ricorrenza). Un approccio di "ricerca dal basso". Gli algoritmi permettono anche sulla base di pochi passi di capire cosa sta succedendo in termini diapproccio "design from the top".

In questa analogia, una rete neurale è un sistema con droni - sonde che indagano, suggeriscono un percorso e un quadro generale. Nel processo di esplorazione prenderà molte decisioni programmate sul significato di ciò che viene osservato e sulle scelte che fa. Personalmente, non sono sempre disposto (o addirittura costretto :)) ) ad affidarmi alle decisioni degli altri. :)))))


Ho risposto come meglio potevo. )) Solo che siamo di nuovo a un passo da Philo-Sophia. Non voglio andarci. ))

Forum sul trading, sistemi di trading automatico e test di strategie di trading.

Calcolo delle differenze, esempi.

Aleksey Panfilov, 2018.01.10 16:51


Suggerisco che non c'è filosofia in questo thread, solo matematica, programmazione, test, ottimizzazione.


 
Nikolai Semko:

SMA per SMA è, secondo me, "negli occhi di chi guarda", e a proposito, su Fourier. Forse ci arriveremo ancora un po'.

P/S 01.02.2018 Penso che ci sia anche una differenza, prova a ripetere il tuo indicatoreBanzai.mq4su questa linea.

La SMA è un dente di sega per natura solo molto fine, quindi quando si prende la seconda differenza assumo la linea del dente di sega dell'indicatore.

 
Aleksey Panfilov:

Naturalmente, le differenze successive possono anche essere considerate come nuove informazioni.

Tuttavia, già sulla prima differenza non mi è del tutto chiaro quale linea algebrica stiamo tracciando. E man mano che la "leva" aumenta, tutto si confonde. ))))

Ecco, per esempio, un'altra variante dell'uso degli incrementi di prezzo come nuova informazione. Qui l'incremento viene letto esplicitamente come una differenza.

1*Y1-1*Y2-2*Y2+3*Y3-1*Y4 =0

1*Y1-1*Y2-3*Y2+6*Y3-4*Y4 + 1*Y5 =0

1*Y1-1*Y2-4*Y2+10*Y3-10*Y4 + 5*Y5 -1*Y6=0

1*Y1-1*Y2-5*Y2+15*Y3-20*Y4 + 15*Y5 -6*Y6 + 1*Y7=0

1*Y1-1*Y2-6*Y2+21*Y3-35*Y4 + 35*Y5 -21*Y6 + 7*Y7 -1*Y8=0


2*Y2=1*Y1-1*Y2+3*Y3-1*Y4

3*Y2=1*Y1-1*Y2+6*Y3-4*Y4 + 1*Y5

4*Y2=1*Y1-1*Y2+10*Y3-10*Y4 + 5*Y5 -1*Y6

5*Y2=1*Y1-1*Y2+15*Y3-20*Y4 + 15*Y5 -6*Y6 + 1*Y7

6*Y2=1*Y1-1*Y2+21*Y3-35*Y4 + 35*Y5 -21*Y6 + 7*Y7 -1*Y8

      a1_Buffer[i]=(open[i]-open[i+1]   +3*a1_Buffer[i+1 ]   -1*a1_Buffer[i+2 ]  )/2;
      a2_Buffer[i]=(open[i]-open[i+1]   +6*a2_Buffer[i+1 ]   -4*a2_Buffer[i+2 ]   +1*a2_Buffer[i+3 ]  )/3;
      a3_Buffer[i]=(open[i]-open[i+1]   +10*a3_Buffer[i+1 ]  -10*a3_Buffer[i+2 ]  +5*a3_Buffer[i+3 ]  -1*a3_Buffer[i+4 ])/4;
      a4_Buffer[i]=(open[i]-open[i+1]   +15*a4_Buffer[i+1 ]  -20*a4_Buffer[i+2 ]  +15*a4_Buffer[i+3 ]  -6*a4_Buffer[i+4 ]  +1*a4_Buffer[i+5 ])/5;
      a5_Buffer[i]=(open[i]-open[i+1]   +21*a5_Buffer[i+1 ]  -35*a5_Buffer[i+2 ]  +35*a5_Buffer[i+3 ]  -21*a5_Buffer[i+4 ]  +7*a5_Buffer[i+5 ]  -1*a5_Buffer[i+6 ])/6;
Nell'immagine si può vedere che anche la linea (rossa) costruita condizionatamente da un polinomio di grado cinque (dal numero di punti collegati) ha iniziato a stare costantemente vicino al grafico.


È come se usando il polinomio della quarta potenza sulle prime differenze (incrementi di prezzo) avessimo aumentato (del numero di punti) la potenza alla quinta.

Forum sul trading, sistemi di trading automatico e test di strategia

Calcolo delle differenze, esempi.

Maxim Dmitrievsky, 2018.01.31 05:37

La matrice è semplicemente degenerata :) In questi casi, si usa la regolarizzazione, i gradi sono ridotti
È questa, la regolarizzazione?



 
Imho, il perseptron è il miglior calcolo delle differenze. Questo è quello che uso io.
 

Per l'ottimizzazione aggiungeremo all'indicatore descritto nel messaggio 51 la possibilità di cambiare la leva di estrapolazione. Estrapolazione per polinomio di terzo grado.

//|                                Copyright 2018, Aleksey Panfilov. |
//|                                                filpan1@yandex.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2018, Aleksei Panfilov. filpan1@yandex.ru"
#property link      "filpan1@yandex.ru"
#property version   "1.2"
#property description    "2018_01_10_Polynom_s4_s2_p72"
#property strict

#include <MovingAverages.mqh>


#property indicator_chart_window
#property indicator_buffers 6
#property indicator_plots   2
//--- plot a1_
#property indicator_label1  "MACD"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrSilver
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
//--- plot a2_
#property indicator_label2  "Signal"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrYellow
#property indicator_style2  STYLE_SOLID
#property indicator_width2  3
//--- plot a3_
#property indicator_label3  "Fast_line_1"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrSilver
#property indicator_style3  STYLE_SOLID
#property indicator_width3  8
//--- plot a4_
#property indicator_label4  "Fast_line_2"
#property indicator_type4   DRAW_LINE
#property indicator_color4  clrBlue
#property indicator_style4  STYLE_SOLID
#property indicator_width4  3
//--- plot a5_
#property indicator_label5  "Slow_line_1"
#property indicator_type5   DRAW_LINE
#property indicator_color5  clrDarkGreen
#property indicator_style5  STYLE_SOLID
#property indicator_width5  3
//--- plot a6_
#property indicator_label6  "Slow_line_2"
#property indicator_type6   DRAW_LINE
#property indicator_color6  clrRed
#property indicator_style6  STYLE_SOLID
#property indicator_width6  3//--- input parameters

//         int   LIN_1_STEP    =4; //line_1_power
//input int      LIN_1_PLECHO  =72; //Fast_line_1_leverage
//         int   LIN_2_STEP    =2;//line_2_power
//input int      LIN_2_PLECHO  =78; //Fast_line_2_leverage
//         int   LIN_3_STEP    =4;//line_3_power
//input int      LIN_3_PLECHO  =72; //Slow_line_1_leverage
//         int   LIN_4_STEP    =2;//Slow_line_4_power
//input int      LIN_4_PLECHO  =72;//Slow_line_2_leverage
input        int leverage = 72;
input        int TOCHKA_VHODA = 300;// start_point
//input int           base  =450;
      int   point_shift_1 = 0;
      int   point_shift_2 = 0;
//input int   Multiplikator = 10;
//input int   InpSignalSMA  = 9;  // Signal SMA Period



//--- indicator buffers

double a1_Buffer[];
double a2_Buffer[];
double a3_Buffer[];
double a4_Buffer[];
double a5_Buffer[];
double a6_Buffer[];
//double a7_Buffer[];
//double a8_Buffer[];
/**/


//===========================================================================================
   double Znach;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
 
//--- indicator buffers mapping
   SetIndexBuffer(0,a5_Buffer,INDICATOR_DATA);
   SetIndexBuffer(1,a6_Buffer,INDICATOR_DATA);
   SetIndexBuffer(2,a1_Buffer,INDICATOR_DATA);
   SetIndexBuffer(3,a2_Buffer,INDICATOR_DATA);
   SetIndexBuffer(4,a3_Buffer,INDICATOR_DATA);
   SetIndexBuffer(5,a4_Buffer,INDICATOR_DATA);
//----
//----
   SetIndexShift(2,0);
   SetIndexShift(0,20);
   SetIndexShift(3,92-leverage);
   SetIndexShift(4,38);
   SetIndexShift(5,56);
   SetIndexShift(1,74);

//    if(TOCHKA_VHODA <= (LIN_1_PLECHO+25)*LIN_1_INTERVAL) TOCHKA_VHODA=(LIN_1_PLECHO+25)*LIN_1_INTERVAL;  
//    if(TOCHKA_VHODA <= (LIN_2_PLECHO+25)*LIN_2_INTERVAL) TOCHKA_VHODA=(LIN_2_PLECHO+25)*LIN_2_INTERVAL;  
//    if(TOCHKA_VHODA <= (LIN_3_PLECHO+25)*LIN_3_INTERVAL) TOCHKA_VHODA=(LIN_3_PLECHO+25)*LIN_3_INTERVAL;  
//    if(TOCHKA_VHODA <= (LIN_4_PLECHO+25)*LIN_4_INTERVAL) TOCHKA_VHODA=(LIN_4_PLECHO+25)*LIN_4_INTERVAL;  
//    if(TOCHKA_VHODA <= (base*2+25))                      TOCHKA_VHODA=(base*2+25);  

//------
//===========================================================================================
//===========================================================================================

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {

   int i,z,limit;
//   int Bars=Bars(_Symbol,_Period);

   if(prev_calculated==0)// first calculation    
     {
      limit=rates_total-TOCHKA_VHODA;
      //--- set empty value for first limit bars
//Print("Bars=",Bars," rates_total=",rates_total," TOCHKA=",TOCHKA_VHODA," limit=",limit);
      if(limit<1)return(0);
      for(i=rates_total-1;i>=limit;i--)
      {
       a1_Buffer[i]=open[limit+1];
       a2_Buffer[i]=open[limit+1];
       a3_Buffer[i]=open[limit+1];
       a4_Buffer[i]=open[limit+1];
       a5_Buffer[i]=open[limit+1];
       a6_Buffer[i]=open[limit+1];
      }

     }
   else limit=rates_total-prev_calculated;
//--- main loop
   for(i=limit;i>=0 && !IsStopped();i--)
   {
//===========================================================================================
   Znach = 0; //iMA(NULL,0,base*2,0,MODE_SMA,PRICE_OPEN,i);
//===========================================================================================

 
      a1_Buffer[i]=((open[i] - Znach)    +5061600*a1_Buffer[i+1 ]-7489800    *a1_Buffer[i+2 ]+4926624*a1_Buffer[i+3 ]-1215450*a1_Buffer[i+4 ])/1282975;

      a5_Buffer[i+92]=a1_Buffer[i];   if(i>=0) { for(z=92-1;z>=0;z--){        a5_Buffer[i+0+z]=  4*a5_Buffer[i+1+z]  -  6*a5_Buffer[i+2+z]  +  4*a5_Buffer[i+3+z]  - 1*a5_Buffer[i+4+z];  }}


      a2_Buffer[i+92-leverage]=a5_Buffer[i+92-leverage]; 
      
//      a3_Buffer[i+38]=a5_Buffer[i+38]; 
      
//      a4_Buffer[i+56]=a5_Buffer[i+56];
        
//      a6_Buffer[i+74]=a5_Buffer[i+74];
      
 //     a4_Buffer[i+92]=a1_Buffer[i];   if(i<=1) { for(z=92-1;z>=0;z--){        a4_Buffer[i+0+z]=  5*a4_Buffer[i+1+z]  -  10*a4_Buffer[i+2+z]   +   10*a4_Buffer[i+3+z]  -  5*a4_Buffer[i+4+z]  +  1*a4_Buffer[i+5+z];  }}

 //     a3_Buffer[i+292]=a2_Buffer[i];   if(i<=1) { for(z=292-1;z>=0;z--){         a3_Buffer[i+0+z]=  2.998096443*a3_Buffer[i+1+z]  -  2.998096443*a3_Buffer[i+2+z]   +   1*a3_Buffer[i+3+z]   ;  }}

 //     a5_Buffer[i+92]=a2_Buffer[i];   if(i<=1) { for(z=92-1;z>=0;z--){        a5_Buffer[i+0+z]=  3*a5_Buffer[i+1+z]  -  3*a5_Buffer[i+2+z]   +   1*a5_Buffer[i+3+z]   ;  }}

 //     a6_Buffer[i+292]=a2_Buffer[i];   if(i<=1) { for(z=292-1;z>=0;z--){         a6_Buffer[i+0+z]=  3.998096443*a6_Buffer[i+1+z]  -  5.996192886*a6_Buffer[i+2+z]   +   3.998096443*a6_Buffer[i+3+z]  -  1*a6_Buffer[i+4+z] ;  }}


//      a3_Buffer[i]=((open[i] - Znach)    +5061600*a3_Buffer[i+1 ]-7489800    *a3_Buffer[i+2 ]+4926624*a3_Buffer[i+3 ]-1215450*a3_Buffer[i+4 ])/1282975;

//      a4_Buffer[i]=  2701*a3_Buffer[i]   -5328   *a3_Buffer[i+1 ]    +  2628 *a3_Buffer[i+2 ];



//================================================================================================================================================================================================
//================================================================================================================================================================================================

//   a5_Buffer[i] = (a2_Buffer[i+point_shift_1] - a4_Buffer[i+point_shift_2])* Multiplikator;

   } 
//----
//--- signal line counted in the 2-nd buffer

//     ExponentialMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,a5_Buffer,a6_Buffer);

//--- done

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


Разностное исчисление, примеры.
Разностное исчисление, примеры.
  • 2018.01.18
  • www.mql5.com
Предлагаю собрать в эту ветку индикаторы и эксперты на разностном исчислении, в открытом коде...
 

Per vedere le possibilità di questo indicatore, usiamo il ben noto Expert AdvisorMoving Average.mq4.

Come singolo segnale useremo l'incrocio di due curve. Facciamo qualche cambiamento:

//+------------------------------------------------------------------+
//|                                               Moving Average.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property description "Moving Average sample expert advisor"

#define  MAGICMA  20131111
//--- Inputs
input double Lots          =0.1;
input double MaximumRisk   =0.02;
input double DecreaseFactor=3;
input int    leverage_1  =72;
input int    leverage_2  =56;
//input int    MovingPeriod  =12;
//input int    MovingShift   =6;
//+------------------------------------------------------------------+
//| Calculate open positions                                         |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;
//---
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }
//--- return orders volume
   if(buys>0) return(buys);
   else       return(-sells);
  }
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double LotsOptimized()
  {
   double lot=Lots;
   int    orders=HistoryTotal();     // history orders total
   int    losses=0;                  // number of losses orders without a break
//--- select lot size
   lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1);
//--- calcuulate number of losses orders without a break
   if(DecreaseFactor>0)
     {
      for(int i=orders-1;i>=0;i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
           {
            Print("Error in history!");
            break;
           }
         if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL)
            continue;
         //---
         if(OrderProfit()>0) break;
         if(OrderProfit()<0) losses++;
        }
      if(losses>1)
         lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);
     }
//--- return lot size
   if(lot<0.1) lot=0.1;
   return(lot);
  }
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |2018_02_02_EMA_Polynom_s4_s3_p72_v.2
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   double ma_1,ma_2,ma_1_P,ma_2_P;
   int    res;
//--- go trading only for first tiks of new bar
//   if(Volume[0]>1) return;
//--- get Moving Average 
//   ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
 ma_1=iCustom(NULL,0,"2018_02_02_EMA_Polynom_s4_s3_p72_v.2",leverage_1,300,3,0);
 ma_2=iCustom(NULL,0,"2018_02_02_EMA_Polynom_s4_s3_p72_v.2",leverage_2,300,3,0);
 ma_1_P=iCustom(NULL,0,"2018_02_02_EMA_Polynom_s4_s3_p72_v.2",leverage_1,300,3,1);
 ma_2_P=iCustom(NULL,0,"2018_02_02_EMA_Polynom_s4_s3_p72_v.2",leverage_2,300,3,1);
//--- sell conditions
   if(ma_2_P < ma_1_P && ma_1 < ma_2)
     {
      res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red);
      return;
     }
//--- buy conditions
   if(ma_2_P > ma_1_P && ma_1 > ma_2)
     {
      res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Blue);
      return;
     }
//---
  }
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
  {
   double ma_1,ma_2,ma_1_P,ma_2_P;
//--- go trading only for first tiks of new bar
//   if(Volume[0]>1) return;
//--- get Moving Average 
//   ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
 ma_1=iCustom(NULL,0,"2018_02_02_EMA_Polynom_s4_s3_p72_v.2",leverage_1,300,3,0);
 ma_2=iCustom(NULL,0,"2018_02_02_EMA_Polynom_s4_s3_p72_v.2",leverage_2,300,3,0);
 ma_1_P=iCustom(NULL,0,"2018_02_02_EMA_Polynom_s4_s3_p72_v.2",leverage_1,300,3,2);
 ma_2_P=iCustom(NULL,0,"2018_02_02_EMA_Polynom_s4_s3_p72_v.2",leverage_2,300,3,2);
//---
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
      //--- check order type 
      if(OrderType()==OP_BUY)
        {
         if(ma_2_P <= ma_1_P && ma_1 < ma_2)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(ma_2_P >= ma_1_P && ma_1 > ma_2)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
     }
//---
  }
//+------------------------------------------------------------------+
//| OnTick function                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false)
      return;
//--- calculate open orders by current symbol
   if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
   else                                    CheckForClose();
//---
  }
//+------------------------------------------------------------------+
 


File:
2018_02_02.zip  523 kb
 

EURUSD, M15, lo spread di 2 punti è lì:

Mi dispiace, ma non posso inserire il codice.

File:
 
Renat Akhtyamov:

Mi dispiace, ma non posso mettere giù il codice.

In ogni caso, le ultime barre sono ridisegnate, il che significa che il valore del codice= 0.
 
Renat Akhtyamov:

EURUSD, M15, lo spread di 2 punti è lì:

Scusa, ma non posso mettere il codice

Sulle"quattro cifre"?