Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1311

 
Sprut 185:

Thank you for your participation.

Unfortunately the ObjectSet*** function was not suitable for my task.

I solved the problem myself using the OnDeinit() function.

Now everything works as it should.

But in your question there are such words

Sprut 185:

Please help me with one problem!

I am just learning to write code and in this connection I ask you to be lenient to my illiteracy.

I want to help you understand theOnChartEvent function that when you change timeframe, or change settings in the indicator menu, it will update the graphical objects in the chart.

I understand that you have to delete the graphical objects first and then create them again. Butif the objects were deleted, there's no access to its properties and then how to re-create these objects....... Or maybe I don't understand it? Or maybe there is another way - updating graphical objects on the chart?

Please write an example with comments on how to do it.

And in order not to delete, just change the required object property by one of the ObjectSet*** functions .

As for deleting all objects........., you should be very careful when deleting all objects indiscriminately... Among objects on the chart, there may be objects created manually or by another Expert Advisor/indicator. If you like deleting objects, you should pay attention to removal by prefix. True, you have to create with the prefix. It is not difficult.

 
What is the result of

iSpread ?


I see that it is roughly similar to the spread value if you query for bars in Symbols/Bars in the terminal.

Of course these values do not correspond to the real values given by SYMBOL_SPREAD.

Why such a difference? And what is such an unreal spread shown usingiSpread?

 
Aleksei Skrypnev:
What result does the function show

iSpread ?


I see that it is roughly similar to the spread value if you query for bars in Symbols/Bars in the terminal.

Of course these values do not correspond to the real values given by SYMBOL_SPREAD.

Why such a difference? And what is such an unreal spread shown usingiSpread?

Minimum spread per bar.

I added a buffer for checking - it takes data from the indicator array spread[] and displays a comment for the current bar - the result of iSpread


How to do it here:Spread Control

Spread Control
Spread Control
  • www.mql5.com
Просмотр спреда
Files:
 

Greetings!

Can you tell me why variable "ATR14" doesn't change and how can I see it changing?

void OnTick()
{

double ATR14=iATR(NULL,PERIOD_CURRENT,14);

Comment(
 
      "ATR14==: ",ATR14,"\n");
}
 
Alexey Belyakov:

Greetings!

Can you tell me why the variable "ATR14" does not change? How can I see it changing?

Because in MQL5 the indicator handle (by the way, it has the int type) is created ONE time and it is done in OnInit.

And for data reception from the indicator the CopyBuffer is used.

 
Vladimir Karputov:

Because in MQL5 the indicator handle (and it has the int type, by the way) is created ONE time and it is done in OnInit.

And for data reception from the indicator the CopyBuffer is used.

Ok, let's suppose.

double  ATR14m[];   

int ATR14;

int OnInit()
  {
ATR14=iATR(NULL,PERIOD_CURRENT,14);
  return(0);   
  }
  
  
void OnDeinit(const int reason)
  {
//---  
  }


void OnTick()
{
CopyBuffer(ATR14,0,0,3,ATR14m);



Comment(

      "ATR14==: ",ATR14,"\n");

}



Nothing has changed.

 
Alexey Belyakov:

Greetings!

Can you tell me why variable "ATR14" does not change? And how can I see it change?

here's an exampleһttp://www.mql5.com/ru/docs/indicators/iatr

Документация по MQL5: Технические индикаторы / iATR
Документация по MQL5: Технические индикаторы / iATR
  • www.mql5.com
iATR - Технические индикаторы - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Alexey Belyakov:

Well, let's just say

Nothing's changed.

You've almost got it. I recommend calling the array 'array_atr' instead of 'ATR14m'. Then you'll see your error in calling'Comment' sooner.

 
Vladimir Karputov:

You've almost got it right. I recommend calling the array 'array_atr' instead of 'ATR14m'. Then you will see your error in the'Comment' call sooner.

double  array_atr[];   

int ATR14;

int OnInit()
  {
ATR14=iATR(NULL,PERIOD_CURRENT,14);
  return(0);   
  }
   
void OnDeinit(const int reason)
  {
//---  
  }

void OnTick()
{


CopyBuffer(ATR14,0,0,3,array_atr);

Comment(

      "ATR14==: ",array_atr,"\n");

}

Changed it and get error: " 'array_atr' - invalid array access "


 
Vladimir Karputov:

You've almost got it right. I recommend calling the array 'array_atr' instead of 'ATR14m'. Then you'll see your error in calling'Comment' sooner.

Do you think that naming a child's potty a night vase will change anything?

There's such a misunderstanding there that I daren't even try to suggest something... You have to read the documentation 50 times to understand it...

Reason: