Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 521

 
Happy Easter to all! How to solve the problem, in mql4 double type did not give -9315605757223320000.00, -9232595408891630000.00 when calculating prices, but mql5 dug them out from somewhere? Maybe a glitch in the quotes? How to circumvent this situation? Thanks.
 
mwwm:
Happy Easter to all! How to solve the problem, in mql4 double type did not give -9315605757223320000.00, -9232595408891630000.00 when calculating prices and mql5 dug them out from somewhere? Maybe a glitch in the quotes? How to circumvent this situation? Thank you.
Where is the code?
 
Artyom Trishkin:
Where's the code?

Here's a rough one:

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot OC
#property indicator_label1  ""
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
#property strict 
//--- indicator buffers
double Op[],Hi[],Lo[],Cl[],Ti[];
double q1[100],q2[100];

///---------
double Lim1[10],Lim2[10];
double Max1[10],Min1[10];
double Max2[10],Min2[10];
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXX

//+------------------------------------------------------------------+ 
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+ 
int OnInit()
  {
//--- откроем файл 
   ResetLastError();
//--- привязка массива к индикаторному буферу с индексом 0 
   SetIndexBuffer(0,Ti,INDICATOR_DATA); SetIndexBuffer(1,Op,INDICATOR_DATA);SetIndexBuffer(2,Hi,INDICATOR_DATA);
   SetIndexBuffer(3,Lo,INDICATOR_DATA); SetIndexBuffer(4,Cl,INDICATOR_DATA);
//---- установка значений индикатора, которые не будут видимы на графике 
//--- 
   ArraySetAsSeries(Ti,true);
   ArraySetAsSeries(Op,true);
   ArraySetAsSeries(Hi,true);
   ArraySetAsSeries(Lo,true);
   ArraySetAsSeries(Cl,true);
//---
   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[])
  {
   ArraySetAsSeries(time,true); 
   ArraySetAsSeries(open,true); 
   ArraySetAsSeries(high,true); 
   ArraySetAsSeries(low,true); 
   ArraySetAsSeries(close,true); 
   ArrayInitialize(Lim1,1);ArrayInitialize(Lim2,1);
  
   int f=1;
/////////      
//--- Проверка на минимальное колиество баров для расчёта
   if(rates_total<1) return 0;
//--- Проверка и расчёт количества просчитываемых баров
   int limit=rates_total-prev_calculated;
   if(limit>1) // если это первый запуск, или изменение истории, или открытие нового бара
     {
      limit=rates_total-1;                   // установим начало цикла на начало исторических данных
      ArrayInitialize(Ti,EMPTY_VALUE);       // инициализируем массив
      ArrayInitialize(Op,EMPTY_VALUE);
      ArrayInitialize(Hi,EMPTY_VALUE);
      ArrayInitialize(Lo,EMPTY_VALUE);
      ArrayInitialize(Cl,EMPTY_VALUE); 
     }
 int p=0;
    
//--- Расчёт индикатора
   for(int i=limit-1; i>=0 && !IsStopped(); i--)
     {
      Op[i]=open[i];Hi[i]=high[i];Lo[i]=low[i];Cl[i]=close[i];

            q1[1]=((Hi[i+f+0]+Lo[i+f+0])/2+Hi[i+f+0])/2;
            Lim1[1]=q1[1]-Hi[i+f+1];  
            Max1[1]=MathMax(Max1[1], Lim1[1]);
            Min1[1]=MathMin(Min1[1], Lim1[1]);

double n=100000000;
if(MathAbs(Lim1[1])>n){p++;Print(Lim1[1]," = ",p,"  = ",i);}
 } 
//--- return value of prev_calculated for next call 
   return(rates_total);
  }
 
Hello ! I want to install vps from mql. i have 2 accounts with different brokers and i want to copy signals to each account from 2 different signal providers. Do I need to connect a separate vps for each account for 10$/month or can I connect one?
 
Please send me direct link to mt4. i try to download mt4 but mt5 is installed instead. Thanks in advance.
 
Aleksei Poliakov:
Please send me direct link to mt4. i am trying to download mt4 but mt5 is installed instead. Thank you in advance.
Just download it from your broker. Or another one.
 
Artyom Trishkin:


Alexey Viktorov:


Thank you, I see. How do I keep track if I close a part of an order two or three times? For example, I closed a 0.1 lot, then I closed 0.5, then I closed another 0.25. The last closed position will be equal to the open position ticket, but how should I look for a profit on a previous closed one?

 
PolarSeaman:

Thank you, I see. How do I keep track if I close a part of an order two or three times? For example, I closed a 0.1 lot, then I closed 0.5, and then I closed another 0.25. The last closed position will be equal to the open position ticket, and the profit of the previous closed one, how should I search for it?

p1 is the only one. keep your own records and history.

Another option is to use the order history of the terminal, but it has some tricky nuances.

 
Maxim Kuznetsov:

p1 and the only one. keep your own records and history.

What a twist!))

 

I found, here on the forum, a function for calculating profits from a certain date"function returns total profits in the currency of the positions closed since a certain date".

I assume this will work for me. Only how to find out what was the date when the position, which I partially close, was opened?