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

 

Can someone kindly tell me how to write the following thing.

I made a training indicator, which counts iVolume for each tick: iVolume is positive for those that moved up, and negative iVolume for those that moved down. To make a curve, all iVolume (positive and negative) I add increasing total from bar to bar. A curve is obtained. However, I encountered two problems:

1) the line turns out very broken;

2) it is impossible to test the Expert Advisor, because the obtained iVolume chart has only a real life.

Question:

1) how to describe the code that allows to build a chart based on averaged data that I write in the buffer?

2) Is it possible to write the data of this indicator (that is received in the real mode) to a certain file, so that later, referring to this file, we could build the indicator on the historical data, applying the already collected tick volumes to them? If possible, how to describe it programmatically? Or is there another solution that does not require writing current iVolume information to a file?

#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_label1  "Вверх"
#property indicator_type1   DRAW_LINE
#property indicator_color1  Salmon
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2

#property indicator_label2  "Вниз"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrDarkTurquoise
#property indicator_style2  STYLE_SOLID
#property indicator_width2  2

datetime Время=0;   // Время прошлого бара
double Bid1;
double   Buf_1[];
long V1; // объем для текущего тика вверх
long V2; // накопленный объем для всех тиков вверх текущего бара
long V3; // объем текущего тика вниз
long V4; // накопленный объем для всех тиков вниз для текущего бара
long V5;  // отрицательные и положительные iVolume нарастающим итогом

void OnInit()
{
   IndicatorDigits(0);
   SetIndexBuffer(0,Buf_1);
   //SetIndexBuffer(1,Buf_2);
   Bid1=Bid;
   V5 = 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[])
{
   datetime Вр=Time[0];   // Время текущего бара
   if(Вр>Время)           // Если новый бар
   {
      Время=Вр;           // Запомнить
//      Buf_1[0]=0;         // и обнулить последний элемент буфера
   }
   
      
   if(Bid >= Bid1) 
{
   if(Bid > Bid1) 
{   
   V1 = iVolume(NULL, 0, 0); // если повышающий цену тик
   V2 = V1 + V2;
}
  else
{
   V1 = 0;                // если Bid1 = Bid2, т.е. изменение цены = 0, то iVolume этого тика присваиваем 0;
   V2 = V1 + V2;      
}               
}              
   else 
{
   V3 = iVolume(NULL, 0, 0); // если понижающий цену тик 
   V4 = V3 + V4;
}
  
   V5 = V2-V4;
   Bid1=Bid;
   Buf_1[0]= V5; // в буфер сгружаем 
  
   
  return(rates_total);
}
 

Maybe add at the end of the code:

double macurrent=iMAOnArray(Buf_1[0],0,5,0,MODE_LWMA,0);

Eh, no! The compiler generates the error saying there is no array.


 
Hello, can you tell me what the exclamation marks in the strategy toaster mean?
 

Anyone....., can you help? My dead end for me is set out here:https://www.mql5.com/ru/forum/160683/page378#comment_6053255

 
YarTrade: is it possible to write the data of this indicator (which is obtained in real mode) to a file, so that later, referring to this file, it would be possible to build an indicator on historical data, applying to it the already collected tick volumes? If possible, how to describe it programmatically? Or there is another solution that does not require writing the current iVolume information to the file?

Indicator based on data from file - entered this line in search and found

 

Some kind of nightmare, I don't understand why it gives out like this:
Code section :


line[0]=MathFloor(Low[1]*MathPow(10,D-1));
Print("Var ",DoubleToStr(line[0],D));
Print("Code ",DoubleToStr(MathFloor(Low[1]*MathPow(10,D-1)),D));

Output :

EURUSD,M15: Var 0.00000
EURUSD,M15: Code 11754.00000


What happens to the value after assignment?

 
LuckySith:   Code section :

line[0]=MathFloor(Low[1]*MathPow(10,D-1));
Print("Var ",DoubleToStr(line[0],D));
Print("Code ",DoubleToStr(MathFloor(Low[1]*MathPow(10,D-1)),D));

Print :

EURUSD,M15: Var 0.00000
EURUSD,M15: Code 11754.00000

What happens to the value after assignment?

Print the value of the variables after the assignment and the value of variable D. Use your calculator to do the math.

 

Hello all. Folks, could you please give us a little help? Could someone please set a line in the indicator where you can specify the name of the sound file, so that the line is displayed in the indicator settings.

Files:
Awesome-33.ex4  16 kb
 
STARIJ:

Print out the values of the variables after assignment and the value of variable D. Let's calculate it on a calculator...


So I print out the value of the variable after the assignment. So the code is basically the following:


a=b;

Print (a);

Print (b);

But a equals zero and b is printed correctly

 
LuckySith:

This is how I output the value being assigned. So the code is essentially as follows:


a=b;

Print (a);

Print (b);

But a equals zero while b is printed correctly


I do not see zero, you have made a mistake somewhere

   int D=5;
   double a=MathFloor(Low[1]*MathPow(10,D-1)); 
   Print("Var ",DoubleToStr(a,D)); 
   Print("Code ",DoubleToStr(MathFloor(Low[1]*MathPow(10,D-1)),D)); 
Reason: