Caratteristiche del linguaggio mql5, sottigliezze e tecniche - pagina 83

 
fxsaber:

Rileggi la mia risposta. Aprire il breve codice sorgente, capirlo e... Profitto!

Naturalmente ho aperto il codice sorgente, naturalmente. Anche se non ho indicato che ho bisogno di tutto questo per MT5, ma sto cercando un'idea...

Puoi dirmi quale linea risolve questo problema (idea nascosta) - nella funzioneGetBarSize()?

#property show_inputs

extern int Width = 1280;
extern int Height = 800;

#import "user32.dll"
  int GetClientRect( int hWnd, int lpRect[] );
#import

#define  BORDER_SIZE 44

int GetBarSize()
{
  int Rect[4], PrevBars, PrevRect, Res = 1;
  int hwnd = WindowHandle(Symbol(), Period());

  GetClientRect(hwnd, Rect);
  PrevRect = Rect[2] - BORDER_SIZE;
  PrevBars = WindowBarsPerChart();

  PrevBars += PrevBars;
    
  while(PrevBars <= PrevRect)
  {
    Res += Res;
    PrevBars += PrevBars;
  }
  
  return(Res);
}

string StrNumToLen( string Num, int Len )
{
  Len -= StringLen(Num);
  
  while (Len > 0)
  {
    Num = "0" + Num;
    Len--;
  }
  
  return(Num);
}

void start()
{
  int Pos = WindowFirstVisibleBar(), Step, i = 1;
  string Directory = Width + "x" + Height + "_" + Symbol() + Period() + " (" +
                     TimeToStr(Time[Pos], TIME_DATE) + "-" +
                     TimeToStr(Time[0], TIME_DATE) + ")/";

  Pos += 2;
  Step = 1 + (Width - BORDER_SIZE) / GetBarSize();
  
  while (Pos >= 0)
  {
    WindowScreenShot(Directory + StrNumToLen(i, 5) + ".gif", Width, Height, Pos);
    i++;
    Pos -= Step;
  }
  
  return;
}
 
Aleksey Vyazmikin:

Naturalmente ho aperto il codice sorgente, naturalmente. Anche se non ho specificato che ho bisogno di tutto questo per MT5, ma sto cercando un'idea...

Puoi dirmi quale linea risolve questo problema (idea nascosta) - nella funzioneGetBarSize()?

int GetBarSize( const ulong Chart = 0 )
{
  return(1 << (int)ChartGetInteger(Chart, CHART_SCALE));
}
 
fxsaber:

Mi sento un idiota, cosa significa "<<"? E cosa ha a che fare questo con la scala del grafico?

 
Aleksey Vyazmikin:

Mi sento un idiota, cosa significa "<<"?

Questo è uno spostamento bitwise a sinistra. Un 1 (in rappresentazione binaria 0000 0001) sarà spostato a sinistra tante volte quanto il valore restituito da ChartGetInteger. In pratica, è una potenza di 2.

Il risultato sarà il numero di pixel per 1 barra.

 
Ihor Herasko:

Questo è uno spostamento bitwise a sinistra. 1 (in rappresentazione binaria 0000 0001) sarà spostato a sinistra tante volte quanto il valore restituito da ChartGetInteger. Fondamentalmente è una potenza di 2.

Il risultato sarà il numero di pixel per 1 barra.

Grazie per il chiarimento, cercherò di implementarlo!

fxsaber:

Grazie!

 

Rosh, grazie mille per il tuo aiuto nel trovarlo!

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

Bug, bug, domande

Ilyas, 2016.08.24 11:08

L'array ("inside") memorizza quanti elementi sono allocati nell'array.

La logica per lavorare con le allocazioni (codice condizionale):
ArrayResize(arr,int size,int reserve)
  {
   if(arr.allocated<size)
      if(!ArrayAllocateMemory(arr,size+reserve))  // -> arr.allocated=size+reserve;
         return(-1);
   //---
   CallConstructorsOrDestructors(arr,size);
   //---
   arr.size=size;
   return(size);
  }

Peccato che non sia affatto disponibile (i wrapper di array non sono un'opzione). Forse potremmo ancora aggiungere funzionalità?

int ArrayAllocated( const void&  array[] );

C'è StringBufferLen per le stringhe, dopo tutto.

 
I commenti non pertinenti a questo argomento sono stati spostati in "Bugs, bugs, issues".
 
I commenti non pertinenti a questo argomento sono stati spostati in "Bugs, bugs, issues".
 
string Str = "123.456";

double Num1 = StringToDouble(Str);  
double Num2 = (double)Str; // Быстрее


Molto più veloce in questo modo (Release, non Debug)

double StringToDouble2( const string Str, const uint StartPos = 0 )
{
  const uint Size = StringLen(Str);
  
  bool Sign = false;  
  uint i = StartPos;
  
  while (i < Size)
  {
    const int Digit = Str[i];

    if ((Digit != ' ') && (Digit != '\t') && (Digit != '\n') && (Digit != '\r'))
    {
      if ((Sign = (Digit == '-')) || (Digit == '+'))
        i++;
      
      break;
    }
      
    i++;
  }

  long Res = 0;
  int point = 0;
  
  while (i < Size)
  {
    const int Digit = Str[i];
    
    if (!point && (Digit == '.'))
      point = 1;
    else if (((Digit >= '0') && (Digit <= '9')))
    {
      Res = Res * 10 + Digit - '0';
      
      if (point)
        point *= 10;
    }
    else
      break;
      
    i++;
  }
  
  if (Sign)
    Res = -Res;
  
  return((point > 1) ? Res / (double)point : Res); // Возможна потеря точности при делении
}

Quando si analizzano grandi quantità di dati, si ottiene una notevole accelerazione.

 
fxsaber:


Molto più veloce in questo modo (Release, non Debug)


Quando si analizzano dati voluminosi, si ottiene una velocità significativa.

Puoi fornire il codice di riferimento per dimostrarlo?

Motivazione: