Errors, bugs, questions - page 1030

 
Al_key:

And I've also been getting barshift using the composter library. Aren't there any built-in tools in the Metatrader?

Actually iBarShift() in MT4 probably works the same way as in the compiler library, but it would be better to have it built-in - it would work faster (because it's in C++).
 
MetaDriver:

Your case is treated with a small slip.

Mine is worse. (By the way, your case without a Slip used to work, stopped a few weeks ago.)

Same scheme stopped working without creepy slips on other (not current) charts:

Code from here: https://www.mql5.com/ru/code/224

Installed owls, see.

On current one I throw standard. AMA on chart, poke recalculation (at Sleep from 0 to 2350) - I drop to M1 and never come back. After a few seconds. AMA appears, and that's it.

I try to use flags (should I store two flags, current and m1? If I have already been using current one (flag) and now I am using m1 (flag 2), then...).

but i doubt it... Monday's ticks will come before I go back to the current one :)

upd yes, I have a hundred objects on the chart, and plus AMA, i.e., it's so heavy.

 
MetaDriver:

"We have to, Fedya. We have to."

(c) Shurik.

--

Such an error occurs, for example, if memory for the dynamic buffer is not allocated (in this case, under ActualBuffer). This code fragment doesn't make it clear.

Here.

And how to allocate memory for dynamic buffer?

I guess, when I find out, the question will disappear.

Here's all the code

#include <TimeSeries.mqh>

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   3
//--- plot Actual
#property  indicator_label1  "Actual"
#property  indicator_type1   DRAW_LINE
#property  indicator_color1  clrLime
#property  indicator_style1  STYLE_SOLID
#property  indicator_width1  1
//--- plot Consensus
#property  indicator_label2  "Consensus"
#property  indicator_type2   DRAW_LINE
#property  indicator_color2  clrPeachPuff
#property  indicator_style2  STYLE_SOLID
#property  indicator_width2  1
//--- plot Previous
#property  indicator_label3  "Previous"
#property  indicator_type3   DRAW_LINE
#property  indicator_color3  clrLightCyan
#property  indicator_style3  STYLE_SOLID
#property  indicator_width3  1
//--- indicator buffers
double         ActualBuffer[];
double         ConsensusBuffer[];
double         PreviousBuffer[];
//--- indicator vars
string sDatetime;
string sActual;
string sConsensus;
string sPrevious;
int file_handle;
int barshift;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ActualBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ConsensusBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,PreviousBuffer,INDICATOR_DATA);
   file_handle = FileOpen("CSV - макроэкономика и госкорпстат/Existing Home Sales Change.csv",FILE_READ|FILE_CSV|FILE_ANSI,',');
   while(!FileIsEnding(file_handle))
        {
         sDatetime  = FileReadString(file_handle);
         sActual    = FileReadString(file_handle);
         sConsensus = FileReadString(file_handle);
         sPrevious  = FileReadString(file_handle);
         
         barshift = iBarShift(Symbol(), Period(), datetime(formatdatetime(sDatetime)), false);
         if(StringToDouble(formatstring(sActual)) > 0 && StringToDouble(formatstring(sActual)) < 10000) ActualBuffer[barshift] = StringToDouble(formatstring(sActual));
         Print(formatdatetime(sDatetime));
         Print("iBarShift = ", barshift, " Datetime = ", formatstring(sDatetime), " sActual = ", sActual, " sConsensus = ", sConsensus, " sPrevious = ", sPrevious);
        }
    
//---
   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[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| TradeTransaction function                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction& trans,
                        const MqlTradeRequest& request,
                        const MqlTradeResult& result)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   
  }
//+------------------------------------------------------------------+
//--- Функции форматирования
string formatstring(string strparam)
   {
      string result = StringSubstr(strparam,1, StringLen(strparam) - 2);
      return(result);
   }
string formatdatetime(string strparam)
   {
      string result = StringSubstr(strparam, 1, 4) + "." + StringSubstr(strparam, 5, 2) + "." + StringSubstr(strparam, 7, 11);
      
      return(result);
   }
 
Al_key:

Here.

How do you allocate memory for a dynamic buffer?

I guess once I find out, the question will disappear.

Here is all the code

Ps.

I read about Array Resize there...here is a copy

"After linking, a dynamic array buffer[]will be indexed as in regular arrays, even if the array to be linked is pre-set to be indexed as in timeseries. If you want to change the order of access to the elements of the indicator array, you should apply the ArraySetAsSeries() function after binding the array using the SetIndexBuffer() function. One should keep in mind that dynamic arrays that have been assigned as indicator buffers by the SetIndexBuffer() function should not be resized. For indicator buffers, all resizing operations are performed by the terminal's executing subsystem."

I'm confused.

 
Silent:
Save configured profile to default File - Profiles - Default
Kind of default, still no data to load. The first time in a couple of hours it all went down.
 
Al_key:

Here.

How do you allocate memory for a dynamic buffer?

I guess once I find out, the question will disappear.

Here is the whole code

INDICATOR_DATA is the data to be drawn. This buffer (size) is monitored by the terminal (by rates_total, as I understand it).

Add buffers for intermediate calculations (INDICATOR_CALCULATIONS). For them set the size.

PS I have #include <TimeSeries.mqh> can "t open for some reason, does not compile.

Upd Monday must wait, something is wrong here.

 
Silent:

INDICATOR_DATA is the data to be drawn. This buffer (size) is monitored by the terminal (by rates_total, as I understand).

Add buffers for intermediate calculations (INDICATOR_CALCULATIONS). For them set the size.

PS I have #include <TimeSeries.mqh> can "t open for some reason, doesn't compile.

Upd Monday must wait, something is wrong here.

Already tried to change, still the same error. I will try to at least put values in a regular array, maybe something will work.
 
Al_key:
I tried to change it, still got the same error. I will try to at least put values into a regular array, maybe something will work out.

Here is a simple one that works. In INDICATOR_DATA we write from INDICATOR_CALCULATIONS.

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   1
//--- plot Label1
#property  indicator_label1  "Label1"
#property  indicator_type1   DRAW_LINE
#property  indicator_color1  clrOrangeRed
#property  indicator_style1  STYLE_SOLID
#property  indicator_width1  1
//--- input parameters
input string   s="EURUSD";
input ENUM_TIMEFRAMES      tf;          // D1
input int      countBars=100;          // count
//--- put parameters
int   copied,i;
//--- indicator buffers
double         Label1Buffer[];
//--- buffers
double         p_Symbol[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);
   SetIndexBuffer(1,p_Symbol,INDICATOR_CALCULATIONS);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
//---
   if(prev_calculated==0)
     {
      ArrayInitialize(Label1Buffer,EMPTY_VALUE);
      ArrayInitialize(p_Symbol,EMPTY_VALUE);
      ArraySetAsSeries(Label1Buffer,true);
      ArraySetAsSeries(p_Symbol,true);
      ArraySetAsSeries(price,true);
     };
   ArrayCopy(p_Symbol,price,0,0,countBars);
   if(_LastError!=0) {Print(_LastError); return(prev_calculated);};
   if(_LastError==0)
     {
      for(i=countBars;i>0;i--)
        {
         Label1Buffer[i]=p_Symbol[i];
         Print("limitBars i = "+IntegerToString(i));
        };
     };
//--- return value of prev_calculated for next call
   return(rates_total);
  }
 
Silent:

INDICATOR_DATA is the data to be drawn. This buffer (size) is monitored by the terminal (by rates_total, as I understand).

Add buffers for intermediate calculations (INDICATOR_CALCULATIONS). For them set the size.

PS I have #include <TimeSeries.mqh> can "t open for some reason, does not compile.

Upd Monday must wait, something is not right here.

Take here: https://www.mql5.com/ru/code/1008

I just found it, that's why I haven't felt the code yet. And it won't work yet - the public here is driving me to shop.

I think that everything will work, if the problem code will be moved from OnInit() to OnCalculate(). For a long time I've known feature of Five - not any code in OnInit works fine. It is likely that the real autodistribution of buffers registered through SetIndexBuffer() is guaranteed to end only after exit from OnInit(), because it must happen in the background (it is automatic, right?).

TimeSeries - Библиотека функций для работы с таймсериями
TimeSeries - Библиотека функций для работы с таймсериями
  • votes: 12
  • 2012.08.24
  • Andrey Khatimlianskii
  • www.mql5.com
Библиотека функций для работы с таймсериями: iBars, iTime, iOpen, iHigh, iLow, iClose, iVolume, iHighest, iLowest, iBarshift. Для всех функций доступен краткий вариант вызова (с символом и периодом текущего графика).
 

I've noticed that only 3 agents out of 8 can run at the same time when receiving tasks from the cloud.
Although if you run your test in parallel, the other agents are also enabled.

Is this the way it should be?