how to count Bars from the trading execution ?

 

Hey,

I want to count the number of bars it has been since the last MA crossover. Example chart below, which would have the answer of 12 bars including the current bar.

is there anybody help me ?

Documentation on MQL5: Timeseries and Indicators Access / Bars
Documentation on MQL5: Timeseries and Indicators Access / Bars
  • www.mql5.com
If the start_time and stop_time parameters are defined, the function returns the number of bars in the specified time interval, otherwise it returns the total number of bars. If data for the timeseries with specified parameters are not formed in the terminal by the time of the Bars() function call, or data of the timeseries are not synchronized...
Files:
 
Mohammad Hoseini: I want to count …
Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
          No free help

Or pay someone. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum

 
William Roeder:
Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
          No free help

Or pay someone. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum

i need some help and my ask is pretty clear.if u can help me God bless you.if you cant i'm sure that there is some good ppl to help me.
 
Mohammad Hoseini :

Hey,

I want to count the number of bars it has been since the last MA crossover. Example chart below, which would have the answer of 12 bars including the current bar.

is there anybody help me ?

You can use the following algorithm:

in the "header" of the adviser we set up a variable in which we store the opening time of the bar at which the intersection is detected. Then (when searching for a signal) we use the CopyBuffer function - option 3 ' Call by the start and end dates of a required time interval'

 int    CopyBuffer (
   int        indicator_handle,     // indicator handle
   int        buffer_num,           // indicator buffer number
   datetime   start_time,           // start date and time
   datetime   stop_time,            // end date and time
   double     buffer[]              // target array to copy
   );

We make a tour (in a loop) of the copied values and check if there is a new intersection? If there is a new intersection, we write the time the bar opens in the variable.

Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
  • www.mql5.com
Counting of elements of copied data (indicator buffer with the index buffer_num) from the starting position is performed from the present to the past, i.e., starting position of 0 means the current bar (indicator value for the current bar). When copying the yet unknown amount of data, it is recommended to use a dynamic array as a buffer[]...
 
Mohammad Hoseini :

Hey,

I want to count the number of bars it has been since the last MA crossover. Example chart below, which would have the answer of 12 bars including the current bar.

is there anybody help me ?

Today I will post training material: how to calculate the number of bars after the last crossing.

 
How to start with MQL5
How to start with MQL5
  • 2020.04.09
  • www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...
Reason: