Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 349

 
artmedia70:
And here we should clarify that GV are terminal variables, not EA variables.

I've started to read and study. Now I know that global variables and Global Variables are different things.

By the way, about error 129, which I asked you about so often. The thing is that I have a 5-digit DC,

My Expert Advisor is a slipage 2, that's probably why it has been unable to keep up with the price. Now I set it to 15 pips.

 
artmedia70:
And here it should be made clear that GVs are terminal variables, not EA variables.


Well I mean that the EA can work with them, just to save values during initialisation (among other things).
 
Forexman77:
What if I just switch my computer off or the server crashes on which the EA is running?


Here's where it gets interesting. Global Variables are stored in cache and under some circumstances are written to file. It looks like after some time or during deinitialization. Sometimes I used to lose gvariables.dat (Global Variables values) during reboot. This must be taken into account. Or they simply didn't have time to copy it to disk from cache. It means that we have no guarantee that they are already on disk and not in cache. Correct me if I am wrong.


Forexman77:

I started to read and study. I know now that global variables and Global Variables are different things.

By the way, by the way, about error 129 I was so often asked about. The thing is that I have a five-digit DC,

My Expert Advisor is a slipage 2, that's probably why it has been unable to keep up with the price. I would set it to 15 pips.


I don't think that's why. I have a 3 on my five digits. Everything opens normally. As far as I remember, brokers have agreed that a point is still a basic point, universally accepted (the 4th digit after zero) and a fractional point is a fractional point. So that when you enter 6,7 and 8 digits, you don't have to change the meaning of "point" every time.
 
Pyro:

Here's where it gets interesting. Global Variables are stored in a cache and under some circumstances are written to a file. It's kind of like after a certain period of time. There were cases when during real operation the gvariables.dat (the file where Global Variables values were stored) was simply lost during abrupt computer reboot. This must be taken into account. Or they simply didn't have time to copy it to disk from cache. It means that we have no guarantee that they are already on disk and not in cache. Correct me if I'm wrong.
Maybe you could try writing it, then shutting down the computer. And when you turn it on, try Alert to see if it's there. Although I won't lie, so far I only use static variables and flags and can't say anything for sure about Global Variables.
 
Forexman77:
Maybe you could try recording it, then switch the computer off. And when you turn it on, try to call Alert to see if it's there. Although I won't lie, I only use static variables and flags so far and can't say anything for sure about Global Variables.


You can just look in menu -> Tools -> Global Variables. There's a list there. Or use GlobalVariableCheck. My experience shows that it's better to save everything to a physical file, though.
 
Hello!
Please find errors in my reasoning.

This is the second day that I have been struggling with the creation of the indicator, namely the display of the line on the additional window that is attached to the main window. In my opinion, it is necessary to make calculations over the uncalculated bars and give the values of the results of the calculations to the buffer. This time, I use more complex code for the example (I enjoy working with relatively huge codes). Here's the "clearing of creativity" :

//+--------------------------------------------+
#property indicator_separate_window
#property indicator_minimum -10
#property indicator_maximum 10
#property indicator_buffers 1
#property  indicator_color1 Blue
extern double N = 1;
//+--------------------------------------------+
//Deklaration                                  |
//+--------------------------------------------+
double A; double C;       
double M; double D;
double L; double I;
double B; double F;
double K; double Buf_0[];
double G; 
//+--------------------------------------------+
int init(){
SetIndexBuffer(0,Buf_0);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
return; }
//+--------------------------------------------+
int start() {
//Level 1
A = iRSI(Symbol(),0,10,0,0);
M = iRSI(Symbol(),0,20,0,0);
L = iRSI(Symbol(),0,15,0,0);
B = iStochastic(Symbol(),0,10,6,6,0,0,0,0);
K = iStochastic(Symbol(),0,10,6,6,0,0,1,0);
C = iADX(Symbol(),0,10,0,0,0);
D = iADX(Symbol(),0,10,0,1,0);
I = iADX(Symbol(),0,10,0,2,0);
F = iRVI(Symbol(),0,10,0,0);
  //Level 2
  Buf_0[0] = N *(((B + F) / K) - ((D + I) / C) + ((A + M) / L));
  return; } 
//+-------------------------------------------+ 

.

You can clearly see that "in this clearing" buffer value is "0", i.e. this indicator will draw the line only from the moment of trade platform start. And I need historical data in addition to actual data.

I used the information described in this code (taken from MQ4 tutorial):

//--------------------------------------------------------------------
// separatewindow.mq4 
// Предназначен для использования в качестве примера в учебнике MQL4.
//--------------------------------------------------------------------
#property indicator_separate_window // Отображение в отдельном окне
#property indicator_buffers 1       // Количество буферов
#property  indicator_color1 Blue     // Цвет первой линии
#property  indicator_color2 Red      // Цвет второй линии
 
extern int History  =50;            // Колич.баров в расчётной истории
extern int Aver_Bars=5;             // Количество баров для расчёта
 
double Buf_0[];                     // Объявление индикаторного массива
//--------------------------------------------------------------------
int init()                          // Специальная функция init()
  {
   SetIndexBuffer(0,Buf_0);         // Назначение массива буферу
   SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2);// Стиль линии
   return;                          // Выход из спец. ф-ии init()
  }
//--------------------------------------------------------------------
int start()                         // Специальная функция start()
  {
   int i,                           // Индекс бара
   n,                               // Формальный параметр
   Counted_bars;                    // Количество просчитанных баров 
   double
   Sum_H,                           // Сумма значений High за период
   Sum_L;                           // Сумма значений Low  за период
//--------------------------------------------------------------------
   Counted_bars=IndicatorCounted(); // Количество просчитанных баров 
   i=Bars-Counted_bars-1;           // Индекс первого непосчитанного
   if (i>History-1)                 // Если много баров то ..
      i=History-1;                  // ..рассчитывать заданное колич.
   while(i>=0)                      // Цикл по непосчитанным барам
     {
      Sum_H=0;                      // Обнуление в начале цикла
      Sum_L=0;                      // Обнуление в начале цикла
      for(n=i;n<=i+Aver_Bars-1;n++) // Цикл суммирования значений 
        {
         Sum_H=Sum_H + High[n];     // Накопление суммы макс.значений
         Sum_L=Sum_L + Low[n];      // Накопление суммы мин. значений
        }
      Buf_0[i]=(Sum_H-Sum_L)/Aver_Bars;// Знач. 0 буфера на i-ом баре
      i--;                          // Расчёт индекса следующего бара
     }
//--------------------------------------------------------------------
   return;                          // Выход из спец. ф-ии start()
  }
//--------------------------------------------------------------------
I'll pick out what I need and I'll get it...
extern int History  =50;            // Колич.баров в расчётной истории
extern int Aver_Bars=5;             // Количество баров для расчёта
double Buf_0[];                     // Объявление индикаторного массива
int start()                         // Специальная функция start()
  {
   int i,                           // Индекс бара
   n,                               // Формальный параметр
   Counted_bars;                    // Количество просчитанных баров 
   Counted_bars=IndicatorCounted(); // Количество просчитанных баров 
   i=Bars-Counted_bars-1;           // Индекс первого непосчитанного
   if (i>History-1)                 // Если много баров то ..
      i=History-1;                  // ..рассчитывать заданное колич.
      Buf_0[i]=(Sum_H-Sum_L)/Aver_Bars;// Знач. 0 буфера на i-ом баре
      i--;  

Then, bringing it to a "parade view" by removing the comments and dividing logically, I get:

//|+--------------------------------------+
//|Inputs                                 |
//|+--------------------------------------+
extern int History  =50;
//|+--------------------------------------+
//|Declaration                            |
//|+--------------------------------------+
double Buf_0[];
int i;
int n;
int Counted_bars;
//|+--------------------------------------+
//| Start?                                |
//| Yes, babe!                            |
//|+--------------------------------------+
int start(){
//+-----------+
//Level 1 
//+-----------+
Counted_bars=IndicatorCounted();
i=Bars-Counted_bars-1;
  //+-----------+
  //Level 2
  //+-----------+
  if (i>History-1) i=History-1;
    //+------------+
    //Level 3 
    //+------------+
    Buf_0[i]= 
    i--;  
//+---------------------------------------+

Here I'm left with objects that need to be synthesized with the "main" code. After performing the fusion, I get the following code:

//+--------------------------------------------+
#property indicator_separate_window
#property indicator_minimum -10
#property indicator_maximum 10
#property indicator_buffers 1
#property  indicator_color1 Blue
//|+--------------------------------------------+
//|Inputs                                       |
//|+--------------------------------------------+
extern double N = 1;
extern int History  =50;
//|+--------------------------------------------+
//|Deklaration                                  |
//|+--------------------------------------------+
double A; double C;       int i;
double M; double D;
double L; double I;       int Counted_bars;
double B; double F;
double K; double Buf_0[];
double G; 
//|+--------------------------------------------+
int init(){
SetIndexBuffer(0,Buf_0);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
return; }
//|+--------------------------------------------+
int start() {
       //|+-----------+
       //|Level 1     |
       //|+-----------+
       A = iRSI(Symbol(),0,10,0,0);
       M = iRSI(Symbol(),0,20,0,0);
       L = iRSI(Symbol(),0,15,0,0);
B = iStochastic(Symbol(),0,10,6,6,0,0,0,0);
K = iStochastic(Symbol(),0,10,6,6,0,0,1,0);
       C = iADX(Symbol(),0,10,0,0,0);
       D = iADX(Symbol(),0,10,0,1,0);
       I = iADX(Symbol(),0,10,0,2,0);
       F = iRVI(Symbol(),0,10,0,0);
   Counted_bars=IndicatorCounted();
              i=Bars-Counted_bars-1;
         //+-----------+
         //Level 2     |
         //+-----------+
         if (i>History-1) i=History-1;
         Buf_0[i] = N *(((B + F) / K) - ((D + I) / C) + ((A + M) / L));
         return; } 
//+-------------------------------------------+
During programming, I decoratively changed the "main" code and removed some values from the "appendage" code. Having run the code, I noticed the horizontal line, which indicated an error in my reasoning, because the technical indicators used in the custom indicator cannot give, over a long period of time, the values that build the graph of the function " y = x ".

Synopsis.
My name is John (Eugene, but in American way).

I'm 15 years old, I've been trading for 5 days and I feel a huge progress in learning the areas of currency dealing, namely indicator analysis and graphical analysis (in short, t.a. :) ).
I feel that "manual trading" is becoming less and less promising, so I decided to go straight to "automated trading".

"PICK ON" ALL INADEQUATE JUDGEMENTS! I want to know more and your comments will help me.

 
Link_x:
Hello!
Please find errors in my reasoning.

Here ends the second day as I struggle with the creation of the indicator, namely the display of the line on an additional window that is attached to the main one. My opinion, it is necessary to make calculations over the uncalculated bars and give the results of calculations to the buffer. This time, I use more complex code for the example (I enjoy working with relatively huge codes). Here is the "clearing of creativity" :

.

You can clearly see that "in this glade" the buffer value is "0", i.e. this indicator will draw a line only from the moment the trading platform is launched. And I need historical data in addition to actual data.

I used the information described in this code (taken from the MQ4 tutorial):

I'll isolate what I need and I'll get...

Then, bringing it to a "parade view" by removing the comments and dividing logically, I get:

Here I'm left with objects that need to be synthesized with the "main" code. Having performed the fusion, I get this code:

During the programming, I have decoratively changed the "main" code and removed some values from the "appendage" code. Having started the code, I noticed the horizontal line, which indicated an error in my reasoning, as the technical indicators used in the custom indicator cannot give, during a long time, the values that build the graph of the function " y = x ".

Synopsis.
My name is John (Eugene, but in American way).

I am 15 years old, I am dealing with trading for 5 days and I feel that I am making a great progress in studying the fields of currency dealing, namely indicator analysis and chart analysis (in short, t.a. :) ).
I feel that "manual trading" becomes less and less promising, so I decided to go straight to "automated trading".

"PICK ON" ALL INADEQUATE JUDGEMENT! I want to know more and your comments will help me.

The beginning is a good one.

Pay attention to the History variable, try substituting a different value.

//                Джон(Евгений).mq4 

//+--------------------------------------------+
#property indicator_separate_window
//#property indicator_minimum -10
//#property indicator_maximum 10
#property indicator_buffers 1
#property  indicator_color1 Blue
//|+--------------------------------------------+
//|Inputs                                       |
//|+--------------------------------------------+
extern double N = 1;
extern int History  =50;
//|+--------------------------------------------+
//|Deklaration                                  |
//|+--------------------------------------------+
double A; double C;       int i;
double M; double D;
double L; double I;       int Counted_bars;
double B; double F;
double K; double Buf_0[];
double G; 
//|+--------------------------------------------+
int init(){
SetIndexBuffer(0,Buf_0);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
return; }
//|+--------------------------------------------+
int start()
{
       //|+-----------+
       //|Level 1     |
       //|+-----------+
 for( i=0; i<History; i++)
    {    
       A = iRSI(Symbol(),0,10,0,i);
       M = iRSI(Symbol(),0,20,0,i);
       L = iRSI(Symbol(),0,15,0,0);
       B = iStochastic(Symbol(),0,10,6,6,0,0,0,i);
       K = iStochastic(Symbol(),0,10,6,6,0,0,1,i);
       C = iADX(Symbol(),0,10,0,0,i);
       D = iADX(Symbol(),0,10,0,1,i);
       I = iADX(Symbol(),0,10,0,2,i);
       F = iRVI(Symbol(),0,10,0,i);
    Buf_0[i] = N *(((B + F) / K) - ((D + I) / C) + ((A + M) / L));
   }
 return;
} 
//+-------------------------------------------+
 
Link_x:
Hello!
Please find errors in my reasoning.

The second day of development of the indicator is coming to an end, I am struggling with displaying the line on the additional window attached to the main one. In my opinion, it is necessary to make calculations over the uncalculated bars and give values to the results of calculations to the buffer. This time, I use more complex code for the example (I enjoy working with relatively huge codes). Here is the "clearing of creativity" :

.

You can clearly see that "in this glade" the buffer value is "0", i.e. this indicator will draw a line only from the moment the trading platform is launched. And I need historical data in addition to actual data.

I used the information described in this code (taken from the MQ4 tutorial):

I'll isolate what I need and I'll get...

Then, bringing it to a "parade view" by removing the comments and dividing logically, I get:

Here I'm left with objects that need to be synthesized with the "main" code. Having performed the fusion, I get this code:

During the programming, I have decoratively changed the "main" code and removed some values from the "appendage" code. Having started the code, I noticed the horizontal line, which indicated an error in my reasoning, as the technical indicators used in the custom indicator cannot give, during a long time, the values that build the graph of the function " y = x ".

Synopsis.
My name is John (Eugene, but in American way).

I am 15 years old, I am dealing with trading for 5 days and I feel that I am making a great progress in studying the fields of currency dealing, namely indicator analysis and chart analysis (in short, t.a. :) ).
I feel that "manual trading" becomes less and less promising, so I decided to go straight to "automated trading".

"PICK ON" ALL INADEQUATE JUDGEMENT! I want to know more and your comments will help me.


Start digging towards loops (for, wile, while do) as to why you need it at all )))


If you need values on historical data - you can't do it without enumeration of this very data in a loop ;)

Above you gave an example with History, which sets the number of bars of history, which will be processed by the indicator, and that's how you should proceed.

 


In the picture, I have marked with an arrow where the output should be. I don't understand what the problem is. We go in, remember the time,

Then exit when the time is longer than the entry with an offset by one period and the price is below the 3-day MA min.

The code is as follows:

signal =   MA_6_t - iClose(Symbol(),Period(),0);
MA_2_t=iMA(NULL,0,3,0,MODE_EMA,PRICE_LOW,0); 
static datetime t;

if  (signal > 0.006) 
          {                                          
          Opn_S=true; 
          t=Time[0];                      
          }
if  (Bid <= MA_2_t)
      {
       if (Time[1]>t)
          {                                      
          Cls_S=true;         
          }
      }
What do you think?
 
Forexman77:

In the picture, I have marked with an arrow where the output should be. I don't understand what the problem is. We go in, remember the time,

Then exit when the time is longer than the entry with an offset by one period and the price is below the 3-day MA min.

The code is as follows:

What do you suggest?

Sell close on the Ascus! It is higher! Ask-Bid=spread;

Correct this line of the code:

if  (Bid <= MA_2_t)

// на

if  (Ask <= MA_2_t)

Then it will close as desired, but it may reverse at any time. We have to be content with little!

Reason: