FORTS Please help - page 6

 
Serj_Che:
Why do you repeat in OnCalculate what was in OnInit? Is that such a spell?)

It's simple copy/paste magic))

OK, I'll explain it to you popularly. It's not enough to check data readiness once in the inite. Since the data is generated asynchronously (so as not to slow down the main process), it is possible to get a data error at the time of checking in the init (depends on many factors).

Therefore, you should check and (or only) in calculate and not start main calculations until all required data are available - i.e. check until ready on every tick.

 
Dima_S:

It's simple copy/paste magic))

OK, I'll explain it to you popularly. It's not enough to check data readiness once in the inite. Since the data is generated asynchronously (so as not to slow down the main process), at the time of checking in the init, it is quite possible to get a data error (depends on many factors).

That's why check should be done and(or only) in calculate and not start main calculations until all the necessary data is available - i.e. check until it's ready on every tick.

That's what we are talking about, the OnInit function in the indicator is a sham, or the developers are not doing their job.

Copy/paste is a great thing, I do it myself )).

 

Shouted and called chukchi, but the problem has not been solved!

//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//
bool is_failed = false;
datetime start_time;
datetime end_time;
int mix_bars, rts_bars, si_bars;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
    start_time = StringToTime( "2015.03.17" );
    end_time = TimeCurrent();
//--- indicator buffers mapping
  mix_bars = GetBars( "MIX-6.15" , PERIOD_CURRENT, start_time, end_time ); 
  if ( mix_bars < 1 )
  {
    is_failed = true;
    Print( "Init failed. MIX-6.15 ");
  }
  rts_bars = GetBars( "RTS-6.15" , PERIOD_CURRENT, start_time, end_time ); 
  if ( rts_bars < 1 )
  {
    is_failed = true;
    Print( "Init failed. RTS-6.15 ");
  }
  si_bars = GetBars( "Si-6.15" , PERIOD_CURRENT, start_time, end_time ); 
  if ( si_bars < 1 )
  {
    is_failed = true;
    Print( "Init failed. Si-6.15 ");
  }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator Get bars function                               |
//+------------------------------------------------------------------+
int GetBars( string symbol, ENUM_TIMEFRAMES period, const datetime start_date, const datetime end_date )
{
  if ( !SymbolInfoInteger( symbol, SYMBOL_SELECT ) )
  {
    ResetLastError();
//---    
    if ( GetLastError() != ERR_MARKET_UNKNOWN_SYMBOL )
    {
      SymbolSelect( symbol, true );
    }
    else
    {
      Print( "GetBars: Неизвестный символ - ", symbol );
      return( 0 );
    }    
  }
//---  
  if ( MQL5InfoInteger( MQL5_PROGRAM_TYPE ) == PROGRAM_INDICATOR && Period() == period && Symbol() == symbol )
  {
    Print( "GetBars: Не пройдена проверка типа программы!" );
    return( 0 );
  }  
//---
  if ( SymbolIsSynchronized( symbol ) )
  {
    return( Bars( symbol, period, start_date, end_date ) );
  }
  else
  {
    long first_date = 0;
    datetime times[1];
//---    
    if ( SeriesInfoInteger( symbol, PERIOD_M1, SERIES_TERMINAL_FIRSTDATE, first_date ) )
    {
      if ( first_date > 0 )
      {
//--- force timeseries build
        CopyTime( symbol, period, datetime( first_date ) + PeriodSeconds( period ), 1, times );
//--- check date
        if ( SeriesInfoInteger( symbol, period, SERIES_FIRSTDATE, first_date ) )
//---        
        if ( first_date > 0 && first_date <= long( start_date ) )
        {
          return( Bars( symbol, period, start_date, end_date ) );
        } 
      }
    }
    Print( "Необходима загрузка истории с сервера!");
  }       
//---  
  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[])
  {
//---
   if ( is_failed )
   {
     Print( "Sorry! Get Bars failed." );
   }
   else Print( "Bingo! We done.");
//--- return value of prev_calculated for next call
   return(rates_total);
  }

I haven't written the history download yet, but the data is in the terminal, and it's NOT coming out of it the first time!

2015.03.26 20:49:01.641 Test (MIX-6.15,M1)      Необходима загрузка истории с сервера!
2015.03.26 20:49:01.641 Test (MIX-6.15,M1)      Init failed. RTS-6.15 
2015.03.26 20:49:01.641 Test (MIX-6.15,M1)      Необходима загрузка истории с сервера!
2015.03.26 20:49:01.641 Test (MIX-6.15,M1)      Init failed. Si-6.15 
2015.03.26 20:49:01.641 Test (MIX-6.15,M1)      Sorry! Get Bars failed.
 
Serj_Che:

OK, interesting!

Indicators work in their own thread, EAs in their own thread. Unless of course it's a single core stone.

Everything happens exactly as it is written in the documentation. :)

I sketched an indicator and EA for testing + the result in the video.

1) First I plot an Expert Advisor on a chart with the OnTick function running for 20 seconds.

The result is that the chart continues working and displays everything as it should be. The chart also works as expected.

2) Then we apply to the chart the indicator that has theOnCalculate function for 20 seconds.

The result - the chat hangs. At the same time the next chat window with the same symbol, where a different period is set, hangs too. Glass continues to work as it should. After the function has worked everything goes back to normal.

3) The video does not have it - but if you throw the indicator on one chat (set 60 sec), and the expert on the other - the expert does not start working until the indicator on the other chat glitches!

I have attached the video separately - it's slow in my browser.

 
MigVRN:

Everything happens exactly as it says in the documentation. :)

Sketched an indicator and an Expert Advisor for checking + the result on the video.

1) First I cast it to the chart of the Expert Advisor that has the OnTick function inside it that works for 20 seconds.

The result is that the chart continues working and displays everything as it should be. The chart also works as expected.

2) Then we apply to the chart the indicator that has theOnCalculate function for 20 seconds.

The result - the chat hangs. At the same time the next chat with the same symbol that has a different period is also suspended. Glass continues to work as it should. After the function has worked everything goes back to normal.

3) The video does not show it - but if you cast an indicator on one chat (set 60 sec), and an EA on the other - the EA does not start working until the indicator malfunctions on another chat!

Attached the video separately - my browser is slow.

Thanks, I can't get a video to watch, I'll look into it.

 

If you are trying to get data from the trading environment when working from the indicator, do not even try to set queries in OnInit(). Make queries and check the response in OnCalculate(). When receiving data from another symbol or from another timeframe it is almost guaranteed that even in OnCalculate you will not succeed to receive data from the first time. That is why you should check the return of the values. If no values are obtained, try to obtain data on the next tick in OnCalculate().


Also already interesting to see the response from servicedesk - the code that was provided.

Forum on trading, automated trading systems and strategy testing

FORTS Please help

alexvd, 2015.03.26 15:48

You have been given the source code by servisdesk. Try putting your last code into the Test() function.

Already sporting interest - the author keeps writing his own code and ignores the servicedesk code?

 
barabashkakvn:

If you are trying to get data from the trading environment when working from the indicator, do not even try to set queries in OnInit(). Make queries and check the response in OnCalculate(). When receiving data from another symbol or from another timeframe it is almost guaranteed that even in OnCalculate you will not succeed to receive data from the first time. That's why you need to check if the values are returned. If no values are received, try to receive data on the next tick in OnCalculate().

+++ and so on. I.e. if there's no data - return;
 
MigVRN:
+++ and so on to the end. I.e. if there is no data, return;
It depends on what you want to query. And how many queries to make depends entirely on preferences of the code writer.
 
barabashkakvn:
It depends on what to query. And how many queries - it entirely depends on the preferences of the code writer.

You understand that

If there is data in the terminal, then the function

SeriesInfoInteger( symbol, PERIOD_M1, SERIES_TERMINAL_FIRSTDATE, first_date )

should not return FALSE?

P/S the SD code also doesn't work from the first time!

 

ONCE AGAIN.

from the help:

SeriesInfoInteger

Returns information about the state of historical data. There are 2 variants of the function.

Second variant:

bool  SeriesInfoInteger(
   string                     symbol_name,     // имя символа
   ENUM_TIMEFRAMES            timeframe,       // период
   ENUM_SERIES_INFO_INTEGER   prop_id,         // идентификатор свойства
   long&                      long_var         // переменная для получения информации
   );

SERIES_TERMINAL_FIRSTDATE.

First date in the history according to the symbol in the client terminal regardless of period

datetime

THE FUNCTION SHOULD NOT RETURN FALSE IF THERE IS DATA IN THE TERMINAL!!!

No matter where you call it from!

Reason: