returns the execution policy. - page 8

 

This is how I get the current data of the moving average, is this correct?

input int      ma_period = 10;
 int ma_handle = 0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
    ma_handle = iMA(_Symbol,_Period,ma_period,0,MODE_SMA,PRICE_MEDIAN);
   if(ma_handle == INVALID_HANDLE)
     {
      Print("ma_handle == INVALID_HANDLE");
      return(INIT_FAILED);
     }

   return(INIT_SUCCEEDED);


  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  { 
  double   ma[1] ;
   if(CopyBuffer(ma_handle,0,0,1,ma)==1)
     {
     
     
     }
 }

Two questions.

1.Nothing about not associating the indicator buffer number with the indicator. Since there is one indicator, it automatically got buffer 0 and that's what I specified.

2. If I have the indicator handle in initialization, when I change the parameters that are passed to the indicator, do I need to re-fill the EA to the chart so that the initialization event comes and the new parameters are applied?

 
Ivan_Invanov:

This is how I get the current data of the moving average, is this correct?

Two questions.

1.Nothing about not associating the indicator buffer number with the indicator. Since there is one indicator, it automatically got buffer 0 and that's what I specified.

2. If I have the indicator handle in initialization, when I change the parameters that are passed to the indicator, do I need to reload the EA to the chart for the initialization event to occur and the new parameters to apply?

1. There is no "association". There never was.

Let's read the help on CopyBuffer

int  CopyBuffer(
   int       indicator_handle,     // handle индикатора
   int       buffer_num,           // номер буфера индикатора
   int       start_pos,            // откуда начнем 
   int       count,                // сколько копируем
   double    buffer[]              // массив, куда будут скопированы данные
   );

There is a function that takes indicator handle (in your case this is variablema_handle and buffer number '0' - zero, because Moving Average indicator has only one buffer).


2. If you change input parameters in your EA, it will initialize your EA again and the indicator handle will be created in OnInit with the parameters you entered.

Документация по MQL5: Доступ к таймсериям и индикаторам / CopyBuffer
Документация по MQL5: Доступ к таймсериям и индикаторам / CopyBuffer
  • www.mql5.com
Отсчет элементов копируемых данных (индикаторный буфер с индексом buffer_num) от стартовой позиции ведется от настоящего к прошлому, то есть стартовая позиция, равная 0, означает текущий бар (значение индикатора для текущего бара). При копировании заранее неизвестного количества данных в качестве массива-приемника buffer[] желательно...
 
Vladimir Karputov:

1. There is no "association". There never has been.

...

Meaning call toSetIndexBuffer()

 
Dmitry Fedoseev:

Meaning a call to SetIndexBuffer()

Yes, it's not clear what is the indicator buffer number, how these buffers are created, do they belong to a specific indicator or they have a common numbering. The documentation says to write SetIndexBuffer(), but in the Moving Average example it's written without. I've read the reference and searched additional articles, but it's still unclear. Does the preprocessor need to specify the buffers and why should the buffers be one less than in the preprocessor directive and not the same.
 
Ivan_Invanov:
Yes, I do not know what is an indicator buffer number, how these buffers are created, do they belong to a certain indicator or they have a general numbering. The documentation says to write SetIndexBuffer(), but in the Moving Average example it's written without. I've read the reference and searched additional articles, but it's still unclear. Does the preprocessor need to specify the buffers and why should the buffers be one less than in the preprocessor directive and not the same.

If you look for some metaphysical meaning... then a lot becomes incomprehensible. Otherwise, it's just a number. It belongs to a specific indicator.

The Expert Advisors don't have indicator buffers at all, therefore there cannot be a SetIndexBufer() call.

Not one less, but exactly the same. When counting from zero, the last number is 1 less than the total number.

 
Thank you.
 

If you don't mind, answer a few more questions, please.

1. I don't understand why I need to assign 0 to a declared variable if I'm going to assign something later anyway. And moreover, sometimes 0 is not assigned, sometimes it is.

And they say that you need to delete objects in deinitialization (I do not understand why), but an indicator handle is an object, but it is not usually deleted, why is that?

3.MqlTradeRequest request={0}; What does it mean? Probably, the entire structure is assigned 0, but it doesn't contain only numeric types.

4. And why is there a logical operation here?

bool  OrderSend(
   MqlTradeRequest&  request,      // структура запроса
   MqlTradeResult&   result        // структура ответа
   );
 
Ivan_Invanov:

If you don't mind, answer a few more questions, please.

1. I don't understand why I need to assign 0 to a declared variable if I'm going to assign something later anyway. And moreover, sometimes 0 is not assigned, sometimes it is.

And they say that you need to delete objects in deinitialization (I do not understand why), but an indicator handle is an object, but it is not usually deleted, why is that?

3.MqlTradeRequest request={0}; What does it mean? Probably, the entire structure is assigned 0, but it doesn't contain only numeric types.

4. Why do we need a logical operation here?

1. Out of habit.

2. it is another object. It will be unloaded by itself, but it can be accelerated by function IndicatorRelease().

3. it is cleared and that's it.

4. this is not a logical operation, but transfer of variable by reference.

 
Dmitry Fedoseev:

1. Out of habit.

2. this is a different object. It will then unload itself, but can be accelerated by IndicatorRelease().

3. it is cleared and that's it.

4. this is not a logical operation, but transfer of variable by reference.

thanks)
 
I'm confused about something. When SYMBOL_TRADE_EXECUTION_MARKET is executed . Can I do something to open orders at a certain price, like in Immediate Execution? Do I need a pending order? Please write a market request format for a pending order.
Reason: