Domande dai principianti MQL4 MT4 MetaTrader 4 - pagina 223

 

Provo a riempire il buffer dell'indicatore dall'altra parte (ArraySetAsSeries (..., false)), tutto funziona bene per un po', ma poi succede qualcosa al buffer e l'ultimo indice dell'array viene riempito, anche se non dovrebbe.
Immagino che il terminale tagli il buffer ad un certo momento e che il peso del buffer sia riempito anche con l'ultimo indice dell'array. Forse, il buffer dell'array dovrebbe essere rilasciato ad un certo momento, ma quando? Puoi correggere l'esempio del test?


#property indicator_buffers 1

double ExtMapBuffer[]; // AQUA   "Line"
int      LastData;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

   SetIndexBuffer(0,ExtMapBuffer);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,7,clrAqua);
   SetIndexEmptyValue(0,0.0);
   SetIndexLabel(0,"Line");

   LastData=0;
//---
   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;
   bool Series=false;
   ArraySetAsSeries(ExtMapBuffer,Series);
   ArraySetAsSeries(high,Series);

   i=prev_calculated-1;

   if(i<1) 
     {
      LastData=0;
      i=1;
      while(i<rates_total-1)
        {
         ExtMapBuffer[i]=high[i];
         i++; 
         LastData=i;
        }
     }
   else
     {
      i=LastData;
     }

   while(i<rates_total-1)
     {
      ExtMapBuffer[i]=high[i];
      i++;
      LastData=i;
     }

   return(rates_total);
  }
//+------------------------------------------------------------------+
 

Salve.

Potete dirmi perché questo indicatore disegna raramente le frecce sulla storia, ma quando si inizia a fare trading inizia a disegnare spesso.

Poi se chiudete MT4 e lo riaprite, allora nello stesso posto dove in tempo reale l'indicatore come una mitragliatrice ha disegnato delle operazioni, è di nuovo 1-2 operazioni.

Quando guardo la cronologia sembra che l'indicatore dovrebbe commerciare bene, ma appena passo al trading in tempo reale ottengo ogni sorta di cose strane.

Per favore, spiega perché? Ecco il codice dell'indicatore:

//---- indicator settings
#property  indicator_chart_window
#property  indicator_buffers 2
#property  indicator_color1  Blue
#property  indicator_color2  Red
//---- indicator parameters
extern int  period = 4; //12
extern int  shift  = 0; //сдвиг по бару
//---- indicator buffers
double BufferUp[],BufferDn[];
int q,st=5;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(2);
//---- drawing settings
   SetIndexStyle(0,DRAW_ARROW,2);
   SetIndexArrow(0,233);
   SetIndexStyle(1,DRAW_ARROW,2);
   SetIndexArrow(1,234);

   SetIndexBuffer(0,BufferUp);//стрелка синяя верх
   SetIndexBuffer(1,BufferDn);//стрелка красная вниз
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("T3MA-ALARM ("+period+")");
//---- initialization done
   if(Digits==3 || Digits==5) q=10;
   st=st*q;
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete("low");
   ObjectDelete("high");
  }
//+----------------------------------------------------------------------+
//| Moving Average of Oscillator                                         |
//+----------------------------------------------------------------------+
int start()
  {
//---- ArraySetAsSeries --------------------------------------------------  
   double Ma[],MaOn[];
   double y0[],y1[],y2[];
//   int i;
   int    i;
   ArraySetAsSeries(Ma,true);
//---- IndicatorCounted --------------------------------------------------
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit1=Bars-counted_bars;
   if(counted_bars==0) limit1-=1+MathMax(period,shift)+2;

   int buffer_size=ArraySize(BufferUp);
   ArrayResize(Ma,buffer_size);
   ArrayResize(MaOn,buffer_size);

   ArrayResize(y0,buffer_size+shift+2);
   ArrayResize(y1,buffer_size+shift+2);
   ArrayResize(y2,buffer_size+shift+2);

   int limit=ArraySize(Ma);
//---- EMA --------------------------------------------------------------- 
   for(i=limit1; i>=0; i--)  Ma[i]  =iMA(NULL,0,period,0,MODE_EMA,PRICE_CLOSE,i);
   for(i=limit1; i>=0; i--)  MaOn[i]=iMAOnArray(Ma,limit,period,0,MODE_EMA,i);

   for(i=limit1; i>=0; i--)
     {
      y0[i+shift]=MaOn[i+shift];
      y1[i+1+shift]=MaOn[i+1+shift];
      y2[i+2+shift]=MaOn[i+2+shift];

      if(y0[i+shift]-y1[i+1+shift]<0 && y1[i+1+shift]-y2[i+2+shift]>0){BufferDn[i+1]=High[i+1]+st*Point;}
      if(y0[i+shift]-y1[i+1+shift]>0 && y1[i+1+shift]-y2[i+2+shift]<0){BufferUp[i+1]=Low[i+1]-st*Point;}
      //---- Signal Trend Up || Dn ---------------------------------------------   
      if(y0[i]-y1[i+1]>0) Comment("\n SWAPLONG = ",MarketInfo(Symbol(),MODE_SWAPLONG),
         "   SWAPSHORT = ",MarketInfo(Symbol(),MODE_SWAPSHORT),"\n BUY TREND ",DoubleToStr(Close[i],Digits));

      else if(y0[i]-y1[i+1]<0) Comment("\n SWAPLONG = ",MarketInfo(Symbol(),MODE_SWAPLONG),
         "   SWAPSHORT = ",MarketInfo(Symbol(),MODE_SWAPSHORT),"\n SELL TREND ",DoubleToStr(Close[i],Digits));
     }

//---- done
   return(0);
  }
//+---------------------------------------------------------------------+
Документация по MQL5: Константы, перечисления и структуры / Константы индикаторов / Стили рисования
Документация по MQL5: Константы, перечисления и структуры / Константы индикаторов / Стили рисования
  • www.mql5.com
При создании пользовательского индикатора можно указать один из 18 типов графического построения (способа отображения на главном окне графика или в подокне графика), значения которых указаны в перечислении ENUM_DRAW_TYPE. В зависимости от стиля рисования, может потребоваться от одного до четырех буферов значений (отмеченных как INDICATOR_DATA...
 

prova a sostituire 0 con 1 in tre punti

   int limit=ArraySize(Ma);
//---- EMA --------------------------------------------------------------- 
   for(i=limit1; i>=1; i--)  Ma[i]  =iMA(NULL,0,period,0,MODE_EMA,PRICE_CLOSE,i);
   for(i=limit1; i>=1; i--)  MaOn[i]=iMAOnArray(Ma,limit,period,0,MODE_EMA,i);

   for(i=limit1; i>=1; i--)
 
Aleksei Stepanenko:

prova a sostituire 0 con 1 in tre punti

   int limit=ArraySize(Ma);
//---- EMA --------------------------------------------------------------- 
   for(i=limit1; i>=1; i--)  Ma[i]  =iMA(NULL,0,period,0,MODE_EMA,PRICE_CLOSE,i);
        // вот сюда
   for(i=limit1; i>=1; i--)  MaOn[i]=iMAOnArray(Ma,limit,period,0,MODE_EMA,i);

   for(i=limit1; i>=1; i--)

Sposterei anche questo

 
Vitaly, ho notato che le persone scrivono una domanda e si fanno gli affari loro, mentre noi ci divertiamo tra di noi. A volte ci sono diverse pagine di estratti.
 
Aleksei Stepanenko:

prova a sostituire 0 con 1 in tre punti

Grazie mille. Ora come posso fare in modo che apra gli scambi solo alla fine della candela corrente sul timeframe corrente? :)) Non so quando apre le offerte ora... Le frecce sembrano essere giuste, e guarda le candele, tutto è ok, ma le offerte sembrano essere aperte nel mezzo o vicino alla fine della candela, in generale, ovunque, ma non dove è necessario. :(

//---- indicator settings
#property  indicator_chart_window
#property  indicator_buffers 2
#property  indicator_color1  Blue
#property  indicator_color2  Red
//---- indicator parameters
extern int  period = 4; //12
extern int  shift  = 0; //сдвиг по бару
//---- indicator buffers
double BufferUp[],BufferDn[];
int q,st=5;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(2);
//---- drawing settings
   SetIndexStyle(0,DRAW_ARROW,2);
   SetIndexArrow(0,233);
   SetIndexStyle(1,DRAW_ARROW,2);
   SetIndexArrow(1,234);

   SetIndexBuffer(0,BufferUp);//стрелка синяя верх
   SetIndexBuffer(1,BufferDn);//стрелка красная вниз
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("T3MA-ALARM ("+period+")");
//---- initialization done
   if(Digits==3 || Digits==5) q=10;
   st=st*q;
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete("low");
   ObjectDelete("high");
  }
//+----------------------------------------------------------------------+
//| Moving Average of Oscillator                                         |
//+----------------------------------------------------------------------+
int start()
  {
//---- ArraySetAsSeries --------------------------------------------------  
   double Ma[],MaOn[];
   double y0[],y1[],y2[];
//   int i;
   int    i;
   ArraySetAsSeries(Ma,true);
//---- IndicatorCounted --------------------------------------------------
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit1=Bars-counted_bars;
   if(counted_bars==0) limit1-=1+MathMax(period,shift)+2;

   int buffer_size=ArraySize(BufferUp);
   ArrayResize(Ma,buffer_size);
   ArrayResize(MaOn,buffer_size);

   ArrayResize(y0,buffer_size+shift+2);
   ArrayResize(y1,buffer_size+shift+2);
   ArrayResize(y2,buffer_size+shift+2);

   int limit=ArraySize(Ma);
//---- EMA --------------------------------------------------------------- 
   for(i=limit1; i>=1; i--)  Ma[i]  =iMA(NULL,0,period,0,MODE_EMA,PRICE_CLOSE,i);
   for(i=limit1; i>=1; i--)  MaOn[i]=iMAOnArray(Ma,limit,period,0,MODE_EMA,i);

   for(i=limit1; i>=1; i--)
     {
      y0[i+shift]=MaOn[i+shift];
      y1[i+1+shift]=MaOn[i+1+shift];
      y2[i+2+shift]=MaOn[i+2+shift];

      if(y0[i+shift]-y1[i+1+shift]<0 && y1[i+1+shift]-y2[i+2+shift]>0){BufferDn[i+1]=High[i+1]+st*Point;}
      if(y0[i+shift]-y1[i+1+shift]>0 && y1[i+1+shift]-y2[i+2+shift]<0){BufferUp[i+1]=Low[i+1]-st*Point;}
      //---- Signal Trend Up || Dn ---------------------------------------------   
      if(y0[i]-y1[i+1]>0) Comment("\n SWAPLONG = ",MarketInfo(Symbol(),MODE_SWAPLONG),
         "   SWAPSHORT = ",MarketInfo(Symbol(),MODE_SWAPSHORT),"\n BUY TREND ",DoubleToStr(Close[i],Digits));

      else if(y0[i]-y1[i+1]<0) Comment("\n SWAPLONG = ",MarketInfo(Symbol(),MODE_SWAPLONG),
         "   SWAPSHORT = ",MarketInfo(Symbol(),MODE_SWAPSHORT),"\n SELL TREND ",DoubleToStr(Close[i],Digits));
     }

//---- done
   return(0);
  }
//+---------------------------------------------------------------------+
 

In generale, è consuetudine aprire trade nel momento in cui si forma una nuova candela, quando ci sono già tutte le informazioni sulla candela che è appena stata chiusa

datetime LastTime=0;


void OnTick()
   {
   if(LastTime==iTime(symbol,frame,0)) return;
   LastTime=iTime(symbol,frame,0);
 
Vitaly Muzichenko:

Sposterei anche questo.

Sei sicuro che è lì che ti hanno mostrato?

 int limit=ArraySize(Ma);
//---- EMA --------------------------------------------------------------- 
// а не вот сюда?
   for(i=limit1; i>=1; i--)  Ma[i]  =iMA(NULL,0,period,0,MODE_EMA,PRICE_CLOSE,i);
        
   for(i=limit1; i>=1; i--)  MaOn[i]=iMAOnArray(Ma,limit,period,0,MODE_EMA,i);

   for(i=limit1; i>=1; i--)
 
Aleksei Stepanenko:

In generale, è consuetudine aprire trade nel momento in cui si forma una nuova candela, quando tutte le informazioni sulla candela che si è appena chiusa sono già presenti

Dove devo inserire questo codice per farlo funzionare correttamente? Non lo capisco molto bene, sono solo all'inizio del mio viaggio...
 
Aleksei Stepanenko:
Vitaly, ho notato che le persone scrivono una domanda e si fanno gli affari loro, mentre noi ci divertiamo tra di noi. A volte ci sono diverse pagine di estratti.
Come potete vedere, non è sempre così. :))
Motivazione: