vorher_berechnet - Seite 9

 
Alexey Kozitsyn:
Ja, die Schleife ist wahrscheinlich zu viel. Aber wenn bei prev_calculated = 0 (wenn der Puffer vorher voll ist) einige Werte in diesem Puffer zurückgesetzt werden, ist das vielleicht ein Fehler. Schauen wir jetzt nach...

Es geht nicht darum, dass sie zurückgesetzt werden, sondern der gesamte Indikator, die gesamte Tiefe der Geschichte wird neu berechnet. Wenn ich also nur den äußersten rechten Index des Puffers füllen muss, diese Werte aber erhalten bleiben müssen, wenn ich ihn nach links verschiebe, habe ich zwei Möglichkeiten:

1. Bei der Initialisierung des Indikatorpuffers ist dieser voll mit Müll und muss gereinigt werden.

2. Ich habe ihn gesäubert, aber wenn prev_calculated = 0 ist, wird der Puffer erneut gesäubert und löscht alle aufgelaufenen Werte.


Und im Allgemeinen ist die Lösung wahnsinnig einfach. prev_calculated = 0 zusammen mit einem Flag löst dieses Problem.

 
Alexey Viktorov:

...

Im Allgemeinen ist die Lösung wahnsinnig einfach. prev_calculated = 0 zusammen mit einem Flag löst das Problem.

Das ist nicht der Fall. Es kommt zu einem Verbindungsabbruch von mehreren Takten Dauer, mehrere Takte enden uninitialisiert mit Müll.
 
Alexey Viktorov:

Tun Sie nicht so, als ob... Es ist alles klar, aber hier ist ein Bild nur für Sie.



Der Computer funktionierte, ohne sich abzuschalten, das Diagramm wurde nicht geschlossen, der Indikator wurde nicht zurückgesetzt...

Frage: Wohin sind die 2-Minuten-Takte verschwunden?

Wahrscheinlich haben Sie einen Fehler in Ihrem Code. Ich habe jetzt einen Testindikator geschrieben, wenn ich mit der Aktualisierungsschaltfläche zurücksetze, ändert sich die Puffergröße nicht, die Daten im Puffer ändern sich nicht...

#property indicator_buffers 1
#property indicator_plots 1
#property indicator_chart_window
#property indicator_type1 DRAW_NONE
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double buf[];
const double _price=98000;
bool _firstLaunch=true;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0,buf);
//---
   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[])
  {
   if(prev_calculated==0)
     {
      if(_firstLaunch)
        {
         Print(__FUNCTION__,": Первый запуск! Размер буфера = ",ArraySize(buf));
         ArrayInitialize(buf,_price);
         _firstLaunch=false;
        }
      else
        {
         Print(__FUNCTION__,": prev_calculated после обновления = ",prev_calculated,". Размер буфера = ",ArraySize(buf));
         //--- Проверяем отличие значений от эталонного
         for(int i=rates_total-1; i>=0; i--)
            if(buf[i]!=_price)
               Print(__FUNCTION__,": Значение #",i," '"+DoubleToString(buf[i],_Digits)+
                     "' отличается от эталонного '"+DoubleToString(_price,_Digits));
        }
     }
   else
     {
      if(rates_total>prev_calculated)
         buf[rates_total-1]=_price;
     }
   return(rates_total);
  }
 

Vonprev_calculated bis rates_total muss der Puffer bereinigt werden.

 
Entweder gab es, wie Dimitri oben sagte, eine Unterbrechung in der Kommunikation von ein paar Takten... Gibt prev_calculated übrigens auch 0 zurück, wenn die Verbindung unterbrochen wird?
 
Dmitry Fedoseev:
Zeigen Sie mir den Code. Lasst uns lachen und erklären.

Ich lache schon.

/********************************************************************\
|                                               BalansEquityTest.mq5 |
|                                                           Viktorov |
|                                                  v4forex@yandex.ru |
\********************************************************************/

#property copyright "Viktorov"
#property link      "v4forex@yandex.ru"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers   6
#property indicator_plots     3
#property indicator_type1     DRAW_COLOR_LINE
#property indicator_color1    clrGold, clrGreen, clrRed
#property indicator_width1    2
#property indicator_label1    "Balance"
#property indicator_type2     DRAW_HISTOGRAM2
#property indicator_color2    clrCrimson
#property indicator_width2    2
#property indicator_label2    "EquityMin"
#property indicator_type3     DRAW_HISTOGRAM2
#property indicator_color3    clrDarkViolet
#property indicator_width3    2
#property indicator_label3    "EquityMax"

double balance[];
double clrBalance[];
double equityMaxB[];
double equityMinB[];
double equityMax[];
double equityMin[];
double maxEquity, minEquity;

bool flag = true;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0, balance, INDICATOR_DATA);
   SetIndexBuffer(1, clrBalance, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(2, equityMin, INDICATOR_DATA);
   SetIndexBuffer(3, equityMinB, INDICATOR_DATA);
   SetIndexBuffer(4, equityMax, INDICATOR_DATA);
   SetIndexBuffer(5, equityMaxB, INDICATOR_DATA);
   PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0.0);
   PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, 0.0);
   PlotIndexSetDouble(2, PLOT_EMPTY_VALUE, 0.0);
   PlotIndexSetDouble(3, PLOT_EMPTY_VALUE, 0.0);
   PlotIndexSetDouble(4, PLOT_EMPTY_VALUE, 0.0);
   ArraySetAsSeries(balance, true);
   ArraySetAsSeries(clrBalance, true);
   ArraySetAsSeries(equityMax, true);
   ArraySetAsSeries(equityMaxB, true);
   ArraySetAsSeries(equityMin, true);
   ArraySetAsSeries(equityMinB, true);
   IndicatorSetInteger(INDICATOR_DIGITS, 2);
   IndicatorSetString(INDICATOR_SHORTNAME, "Show Money");
//---
   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[])
  {
//---
if(prev_calculated == 0)
  {
   Print("prev_calculated = ", prev_calculated);
   if(flag)
    {
     ArrayInitialize(balance, 0.0);
      ArrayInitialize(equityMax, 0.0);
       ArrayInitialize(equityMaxB, 0.0);
      ArrayInitialize(equityMin, 0.0);
     ArrayInitialize(equityMinB, 0.0);
      flag = false;
    }
   return(rates_total);
  }
  double bal = NormalizeDouble(AccountInfoDouble(ACCOUNT_BALANCE), 2);
  double equity = NormalizeDouble(AccountInfoDouble(ACCOUNT_EQUITY), 2);
  if(rates_total > prev_calculated)
   {
    minEquity = 0;
    maxEquity = 0;
   }
   minEquity = NormalizeDouble(fmin((minEquity == 0 ? bal : minEquity), equity), 2);
    maxEquity = NormalizeDouble(fmax(maxEquity, equity), 2);
    balance[0] = bal;
    clrBalance[0] = 0.0;
    equityMinB[0] = balance[0];
    equityMin[0] = minEquity;
    equityMaxB[0] = balance[0];
    equityMax[0] = maxEquity;
    if(balance[0] > balance[1])
     clrBalance[0] = 1.0;
    if(balance[0] < balance[1])
     clrBalance[0] = 2.0;
    Comment(PositionsTotal());
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Über Nacht gab es so viele Nullstellungen von prev_calculate

2016.10.19 08:42:23.309 BalansEquityTest (EURUSD,M1)    prev_calculated = 0
2016.10.19 05:47:04.915 BalansEquityTest (EURUSD,M1)    prev_calculated = 0
2016.10.19 05:47:04.075 BalansEquityTest (EURUSD,M1)    prev_calculated = 0
2016.10.19 04:46:15.300 BalansEquityTest (EURUSD,M1)    prev_calculated = 0
2016.10.19 04:46:15.030 BalansEquityTest (EURUSD,M1)    prev_calculated = 0
2016.10.19 04:45:37.590 BalansEquityTest (EURUSD,M1)    prev_calculated = 0
2016.10.19 04:45:37.100 BalansEquityTest (EURUSD,M1)    prev_calculated = 0
2016.10.19 01:40:31.224 BalansEquityTest (EURUSD,M1)    prev_calculated = 0
2016.10.19 00:00:32.196 BalansEquityTest (EURUSD,M1)    prev_calculated = 0
2016.10.19 00:00:31.806 BalansEquityTest (EURUSD,M1)    prev_calculated = 0
2016.10.18 20:33:02.954 BalansEquityTest (EURUSD,M1)    prev_calculated = 0 // Это время последнего запуска индикатора.
 
Dmitry Fedoseev:

Vonprev_calculated bis rates_total muss der Puffer bereinigt werden.

Wenn dies meine Antwort ist, dann wird der Puffer beim ersten Start des Indikators vollständig mit dem angegebenen Wert initialisiert. Wenn ein neuer Balken gebildet wird, werden die neuen Werte überschrieben.
 
Alexey Kozitsyn:
Oder, wie Dmitriy oben sagte, gab es einen Verbindungsfehler in mehreren Bars... Gibt prev_calculated übrigens auch bei einem Verbindungsabbruch 0 zurück?

Früher war es so, dass prev_calculated bei allen Problemen 0 zurückgab. Dann gab es eine Diskussion im Forum, dass es möglich wäre, nicht immer auf 0 zurückzusetzen, sondern in manchen Fällen könnte man auf den letzten gezählten Wert zurücksetzen, in dem Thread beteiligte sich Slava und versprach, das Problem zu untersuchen.

Nach einer Weile habe ich festgestellt, dass prev_calculated manchmal Zwischenwerte hat. Nun weiß ich es nicht, ich schaue nicht jeden Tag, was prev_calculated zurückgibt.

 
Alexey Kozitsyn:
Wenn dies meine Antwort ist, wird der Puffer beim ersten Start des Indikators vollständig mit dem eingestellten Wert initialisiert. Wenn ein neuer Balken gebildet wird, werden die neuen Werte überschrieben.
Sie nicht.
 
Alexey Viktorov:

Ich lache schon.

/********************************************************************\
|                                               BalansEquityTest.mq5 |
|                                                           Viktorov |
|                                                  v4forex@yandex.ru |
\********************************************************************/

#property copyright "Viktorov"
#property link      "v4forex@yandex.ru"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers   6
#property indicator_plots     3
#property indicator_type1     DRAW_COLOR_LINE
#property indicator_color1    clrGold, clrGreen, clrRed
#property indicator_width1    2
#property indicator_label1    "Balance"
#property indicator_type2     DRAW_HISTOGRAM2
#property indicator_color2    clrCrimson
#property indicator_width2    2
#property indicator_label2    "EquityMin"
#property indicator_type3     DRAW_HISTOGRAM2
#property indicator_color3    clrDarkViolet
#property indicator_width3    2
#property indicator_label3    "EquityMax"

double balance[];
double clrBalance[];
double equityMaxB[];
double equityMinB[];
double equityMax[];
double equityMin[];
double maxEquity, minEquity;

bool flag = true;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0, balance, INDICATOR_DATA);
   SetIndexBuffer(1, clrBalance, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(2, equityMin, INDICATOR_DATA);
   SetIndexBuffer(3, equityMinB, INDICATOR_DATA);
   SetIndexBuffer(4, equityMax, INDICATOR_DATA);
   SetIndexBuffer(5, equityMaxB, INDICATOR_DATA);
   PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0.0);
   PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, 0.0);
   PlotIndexSetDouble(2, PLOT_EMPTY_VALUE, 0.0);
   PlotIndexSetDouble(3, PLOT_EMPTY_VALUE, 0.0);
   PlotIndexSetDouble(4, PLOT_EMPTY_VALUE, 0.0);
   ArraySetAsSeries(balance, true);
   ArraySetAsSeries(clrBalance, true);
   ArraySetAsSeries(equityMax, true);
   ArraySetAsSeries(equityMaxB, true);
   ArraySetAsSeries(equityMin, true);
   ArraySetAsSeries(equityMinB, true);
   IndicatorSetInteger(INDICATOR_DIGITS, 2);
   IndicatorSetString(INDICATOR_SHORTNAME, "Show Money");
//---
   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[])
  {
//---
if(prev_calculated == 0)
  {
   Print("prev_calculated = ", prev_calculated);
   if(flag)
    {
     ArrayInitialize(balance, 0.0);
      ArrayInitialize(equityMax, 0.0);
       ArrayInitialize(equityMaxB, 0.0);
      ArrayInitialize(equityMin, 0.0);
     ArrayInitialize(equityMinB, 0.0);
      flag = false;
    }
   return(rates_total);
  }
  double bal = NormalizeDouble(AccountInfoDouble(ACCOUNT_BALANCE), 2);
  double equity = NormalizeDouble(AccountInfoDouble(ACCOUNT_EQUITY), 2);
  if(rates_total > prev_calculated)
   {
    minEquity = 0;
    maxEquity = 0;
   }
   minEquity = NormalizeDouble(fmin((minEquity == 0 ? bal : minEquity), equity), 2);
    maxEquity = NormalizeDouble(fmax(maxEquity, equity), 2);
    balance[0] = bal;
    clrBalance[0] = 0.0;
    equityMinB[0] = balance[0];
    equityMin[0] = minEquity;
    equityMaxB[0] = balance[0];
    equityMax[0] = maxEquity;
    if(balance[0] > balance[1])
     clrBalance[0] = 1.0;
    if(balance[0] < balance[1])
     clrBalance[0] = 2.0;
    Comment(PositionsTotal());
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Möglicherweise liegt der Fehler hier:

if(rates_total > prev_calculated)
   {
    minEquity = 0;
    maxEquity = 0;
   }
   minEquity = NormalizeDouble(fmin((minEquity == 0 ? bal : minEquity), equity), 2);
    maxEquity = NormalizeDouble(fmax(maxEquity, equity), 2);

Wenn ein neuer Balken eintrifft, setzen Sie die Werte auf 0 zurück - gut. Aber dann prüfen Sie minEquity und 0 auf Gleichheit, was nicht empfehlenswert ist.

Zur Bestätigung meiner Worte - Ihr Bild. Sie können sehen, dass die "Müll"-Werte, wie Sie sagten, bei Null liegen.

Und es ist natürlich besser, das Datenfenster mit dem "Müll"-Wert zur Abbildung hinzuzufügen.
Grund der Beschwerde: