Errors, bugs, questions - page 936

 
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input string symbol1="AUDUSD";
input string symbol2="NZDUSD";
input double mass_of_symbol1=1;
input double mass_of_symbol2=1;


int i,r1,r2,j;
double S,prs,k1,k2,d1,d2;
//--- indicator buffers
double        ind1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ind1,INDICATOR_DATA);
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| 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);ArraySetAsSeries(tick_volume,true);ArraySetAsSeries(volume,true);ArraySetAsSeries(spread,true);

   ArraySetAsSeries(ind1,true);
   MqlRates rates1[]; ArraySetAsSeries(rates1,true);
   MqlRates rates2[]; ArraySetAsSeries(rates2,true);

   if(prev_calculated<rates_total)
     {
      for(i=0;i<rates_total;i++)
     // for(i=prev_calculated-1;i<rates_total;i++)
        {
         CopyRates(symbol1,0,time[i],1,rates1);
         CopyRates(symbol2,0,time[i],1,rates2);
         ind1[i]=mass_of_symbol1*rates1[0].close-mass_of_symbol2*rates2[0].close;
        }
     }



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

Above code of indicator Spread_of_symbols ... I decided to rewrite it to make it work faster.... and the code appeared, see below ... data is not copied ... if you copy data from 1 to 0 in the code, the indicator draws very fast but an out of range error occurs ... what is wrong in the code see below ...?

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input string symbol1="AUDUSD";
input string symbol2="NZDUSD";
input double mass_of_symbol1=1;
input double mass_of_symbol2=1;


int i,r1,r2,j;
double S,prs,k1,k2,d1,d2;
//--- indicator buffers
double        ind1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ind1,INDICATOR_DATA);
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| 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);ArraySetAsSeries(tick_volume,true);ArraySetAsSeries(volume,true);ArraySetAsSeries(spread,true);

   ArraySetAsSeries(ind1,true);
   MqlRates rates1[]; ArraySetAsSeries(rates1,true);
   MqlRates rates2[]; ArraySetAsSeries(rates2,true);
   
   int to_copy;
   if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
   else
     {
      to_copy=rates_total-prev_calculated;
      if(prev_calculated>0) 
      to_copy++;   
     }
   if(CopyRates(symbol1,0,0,to_copy,rates1)<=0)
     {
      Print("Данные по первому символу не скопированы, ошибка  ",GetLastError());
      return(0);
     }
   if(CopyRates(symbol2,0,0,to_copy,rates2)<=0)
     {
      Print("Данные по второму символу не скопированы, ошибка ",GetLastError());
      return(0);
     }
   if(prev_calculated<rates_total)
     {
     int limit;
   if(prev_calculated==0)
      limit=0;
   else limit=prev_calculated-1;
   for(int i=limit;i<rates_total;i++)
        {
         ind1[i]=mass_of_symbol1*rates1[i].close-mass_of_symbol2*rates2[i].close;
        }
     }
   return(rates_total);
  }
 
 
FinEngineer: but out ofrange error comes out...what's wrong in the code see below...?
See if the values of to_copy and limit match each other.
 
In visualization mode, when trading on two symbols, after closing trades at the same time, only data from the symbol on which the Expert Advisor is running appears in the history. Data from the other symbol get to the history tab only after opening further trades. As a result, there is a period of time when data on the trade and history tabs are different.
 
JF 0 Trades 19:31:10 '***': cancel order #3694236 buy stop 1.10 AUDJPY.m at 95.679<br / translate="no">DS 0 Trades 19:31:10 '***': cancel order #3694238 buy limit 1.10 AUDJPY.m at 93.876
DH 0 Trades 19:31:10 '***': cancel order #3694237 buy stop 0.36 AUDJPY.m at 95.679
FI 0 Trades 19:31:10 '***': cancel order #3694239 buy limit 0.36 AUDJPY.m at 93.876
FP 0 Trades 19:31:10 '***': cancel order #3694236 buy stop 1.10 AUDJPY.m at 95.679 done
QE 0 Trades 19:31:11 '***': cancel order #3694238 buy limit 1.10 AUDJPY.m at 93.876 done
CG 0 Trades 19:31:11 '***': cancel order #3694237 buy stop 0.36 AUDJPY.m at 95.679 done
OL 0 Trades 19:31:11 '***': cancel order #3694239 buy limit 0.36 AUDJPY.m at 93.876 done

Four pending orders, according to the log, seemed to be deleted quickly. But onTradeTransaction, the responses came in about 15 seconds, ticks were coming in this period.

KH 0 prp5 (EURUSD.m,M1) 19:31:23 TS=6 cancel sl _ OnTrade PENDING id=84 m=3 b/s=SELL Err=Bid done
***

JG 0 prp5 (EURUSD.m,M1) 19:31:26 TS=6 Delete tp _ OnTrade PENDING id=85 m=3 b/s=SELL Err=Bid completed
***
RL 0 prp5 (EURUSD.m,M1) 19:31:26 TS=6 Delete sl _ OnTrade PENDING id=86 m=3 b/s=SELL Err=Bid completed
***

HK 0 prp5 (EURUSD.m,M1) 19:31:26 TS=6 Delete tp _ OnTrade PENDING id=87 m=3 b/s=SELL Err=Order executed

Although, there is something strange here too

IE 0 prp5 (EURUSD.m,M1) 19:31:26 TS=6 =O= Deal close/reverse price=95.648 m=3 b/s=SELL ... ==>Time before OrderSendAsync
ES 0 prp5 (EURUSD.m,M1) 19:31:29 TS=6 case 8(real) m=3 b/s=SELL Err=Order placed ==>After OrderSendAsync, 3 sec seems to be too long.

P.S. Looks like there were lags in execution of Expert, though I wonder how long packets for OnTradeTransaction can stay in queue.

 
fyords:

From the reference:

MQL5 Reference / Standard Library / Classes for creating panels and dialogs / CWnd / StateFlagsSet

What properties?

StateFlagsSet not properties, but state. A group method for changing the state. Just above methods of changing individual state flags.

Use separately.

 

Looked at the "data access organisation", looked at the sample script that pumps up the data and understood everything, the following questions arose:

1. Why can't I write this code in the indicator in the function OnInit, so that at start the indicator would download its own history and prepare the time series? Can I write such a check in my Expert Advisor?

2. How often do I need to do this check for: 1 for Expert Advisors and 2 for indicators? If I only once prepare the history and timeseries for copying, then in the future errors in copying will not occur? Or I have to check each time or from time to time if the history and timeseries are ready?

3. Is this check necessary only for indicators and Expert Advisors that use several timeframes and symbols, or is it desirable for all?

Документация по MQL5: Основы языка / Функции / Функции обработки событий
Документация по MQL5: Основы языка / Функции / Функции обработки событий
  • www.mql5.com
Основы языка / Функции / Функции обработки событий - Документация по MQL5
 
Swap processes are asynchronous and the indicator is not allowed to wait for data. Therefore it is possible to query in inite, by no means wait or slow down and only in oncalculate to check availability and count.

Please note - the indicator has no right to wait or loop, otherwise it will kill the calculation of subsequent indicators.
 
Renat:
Swap processes are asynchronous and the indicator is not allowed to wait for data. So you can query in the inite, by no means wait or slow down and only in the oncalculate to check availability and count.

Please note - the indicator has no right to wait or loop, otherwise it will kill the calculation of subsequent indicators.

1 So where do I paging the data then? If I want to make an indicator with a basket of currency pairs, many symbols...for each of them I need to check and swap the data...should I run a script from the indicator? Why would one indicator kill the calculations of the subsequent ones? In the next indicators, it is enough to use check of the previous indicator's calculation through BarsCalculated(indicator1_Handle), let it calculate and download the data, or am I wrong?

2 Another question, of another kind - when I declare indicator handle in the function, it starts counting? Or does it start counting before I give a command to copy it?

Reason: