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

 
Alexey Viktorov:

There's nothing supernatural about it. The usual OBJ_BITMAP_LABEL and into it whatever you want as a resource. Kanvas works in OBJ_BITMAP_LABEL, too.

But your version is much easier for a novice developer.

I see your point, thank you.
 
Alexey Viktorov:

Please learn how to insert code into a message.

And for the question: Read the documentation on CopyTicksRange

#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

MqlTick Tick_Mql[];

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

//---

ulong from_msc = TimeCurrent() - 10000;
ulong to_msc = TimeCurrent();
int Ticks = CopyTicksRange(_Symbol,Tick_Mql,COPY_TICKS_ALL,from_msc,to_msc);
  }
//+------------------------------------------------------------------+
Doesn't work. Every time OnTick is called, the result of the Ticks variable is 0.
 
Boris:
It doesn't work. Every time OnTick is called, the result of the variable Ticks is 0.

Are you sure you need past ticks on entry. 10 seconds is not that long, you can wait and count the actual ticks and their number.

In general, you need 2 variables for the first second and remember how many ticks there were in 9 seconds and sum them up, then count ticks for the next second, subtract the first and add the last one. The results should be stored either in an array or in a variable.

 
Valeriy Yastremskiy:

Are you sure you need past ticks on entry. 10 seconds is not that long, you can wait and count the actual ticks and their number.

In general, you need 2 variables for the first second and remember how many ticks there were in 9 seconds and sum them up, then count ticks for the next second, subtract the first and add the last one. These results are saved either in an array or in a variable.

So, this cannot be done through the CopyTicks and CopyTicksRange functions?

Thank you.

 
Boris:
Doesn't work. Each time OnTick is called, the result of the Ticks variable is 0.

Read the documentation!!!

Or do you want all the documentation copied here piece by piece???

from_msc

[in] Date from which ticks are requested. Specified in milliseconds from 01.01.1970. If thefrom_msc parameter is not specified, then the ticks are returned from the beginning of the history. Ticks with time >= from_msc are returned.

to_msc

[in] Date, on which the ticks are requested. Specified in milliseconds from 01.01.1970. Ticks with time <= to_msc are returned. If parameterto_msc is not specified, all ticks until the end of the history are given .

 
Valeriy Yastremskiy:

Are you sure you need past ticks on entry. 10 seconds is not that long, you can wait and count the actual ticks and their number.

In general, you need 2 variables for the first second and remember how many ticks there were in 9 seconds and sum them up, then count ticks for the next second, subtract the first and add the last one. Save the results either to an array or a variable.

Why give such advice?

 
Boris:

So it can't be done through the CopyTicks and CopyTicksRange functions?

Thank you.

Yes, you can. Read documentation, and then ask what you do not understand in the documentation. This way you will get to the truth quicker).

 
Alexey Viktorov:

Why give such advice?

I do it myself. Why get into structures when you can fix short actions yourself.

 
Valeriy Yastremskiy:

I do it myself. Why get into structures when you can fix short actions yourself.

And I scratch my left ear with my right little finger... I can teach you... Do you need it? Don't teach others what you're doing through.....................

 
Valeriy Yastremskiy:

You can. Read the documentation and then ask what you don't understand in the documentation. That's the quicker way to the truth).

So... Read the documentation (again).

#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

MqlTick Tick_Mql[];
ulong ten_msc =(ulong)TimeCurrent()-10000; // 1 секунда = 1000 милисекунд
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

//---

ulong from_msc = (ulong)TimeCurrent() - 10000;
ulong to_msc = (ulong)TimeCurrent();
int Ticks = CopyTicksRange(_Symbol,Tick_Mql,COPY_TICKS_ALL,from_msc,to_msc); //(с текущего времени - 10 сек назад)
// либо CopyTicks(_Sybol,Tick_Mql,COPY_TICKS_ALL,from_msc,0); //(все тики от 10 сек назад до настоящего времени)
  }

Question. What's wrong? It does not count neither with CopyTicksRange nor with CopyTicks

Reason: