Is it possible to programmatically determine which bars are being tested – real, OHLC M1, etc.?

# Is it possible to programmatically determine which bars are being tested – real, OHLC M1, etc.?

Share

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Our community is a completely independent place for communication between forex traders and software developers for trading platforms Metatrader 4 and Metatrader 5

Create A New Account
## iks_

Event handling functions — > > OnCalculate. As such, everything you need can be obtained by default.

The open[], high[], low[] and

close[] parameters contain arrays with the opening, maximum, minimum

, and closing prices of the current timeframe. The time[] parameter contains an

array with the values of the opening time, the spread [] parameter – an array

containing the history of spreads (if the spread is provided for this

trading instrument). The volume[] and tick_volume[] parameters contain

the history of the trading and tick volume, respectively.

To determine the direction of

indexing in the arrays time [], open [], high [], low [], close[],

tick_volume [], volume[] and spread [], you must call the ArrayGetAsSeries () function. In order not to depend on defaults, you must definitely call the ArraySetAsSeries() function for the arrays you want to work with.

The first parameter is rates_total

contains the number of bars available to the indicator for calculation and

corresponds to the number of bars available on the chart.

Note the relationship between the

value returned by OnCalculate() and the second input

parameter prev_calculated. The prev_calculated parameter when calling the function

contains the value that the OnCalculate() function returned on the previous

call. This allows you to implement economical algorithms for calculating the

custom indicator in order to avoid repeated calculations

for those bars that have not changed since the previous launch of this function.

To do this, it is usually enough to

return the value of the rates_total parameter, which contains the number of

bars at the current function call. If the price data has been changed since the last call of the

OnCalculate () function (more than

deep history or history gaps have been filled in), then the value of the

input parameter prev_calculated will be set to zero

by the terminal itself.

Note:

if the OnCalculate function returns a null value, then in the window

DataWindow of the client terminal, the indicator values are not displayed.

For a better understanding, it will be useful to run the indicator, the code of which is attached below.

## savinkins

Faced with the need to track the OHLC mode in the indicator. I also didn’t find a standard feature. I did it through a workaround. For the first 2 minutes, the indicator tries to determine whether the time is suitable for OHLC by the time of arrival of quotes.

`#property copyright "2009-2017, MetaQuotes Software Corp."`

#property link "

#property description "Test"

#property indicator_separate_window

input int Check_minutes=2; // how many minutes to observe the time of ticks

int OnInit()

{

return(INIT_SUCCEEDED);

}

`int OnCalculate(const int rates_total,const int prev_calculated,const datetime &time[],const double &open[],const double &high[],`

const double &low[],const double &close[],const long &tick_volume[],const long &volume[],const int &spread[])

{

if(prev_calculated==rates_total)

{

static bool OHLC=false;

static bool Check_OHLC=true;

if(Check_OHLC)

{

static int prev_time=0;

int real_time=TimeCurrent()%60;

static int Calk_Minute=0;

if (real_time==0 | / real_time==20 || real_time==40 || real_time==59)

{

if(real_time-prev_time==-59) // minute changed

Calk_Minute++;

if (Calk_Minute==Check_minutes)

{

OHLC=true; // the required number of minutes is the same. Most likely, it is OHLC

Print("This is OHLC");

Check_OHLC=false;

}

prev_time=real_time;

}

else

{ Check_OHLC

=false; // other number of seconds, this is normal test mode or real time

Print ("Other mode");

}

}

}

return(rates_total);

}

## andreifan

No. In order not to enter into the temptation of the 9th mortal sin – ” Cheat rating”

## dali

Thank you very much, it worked.

Well, I’ll check in OnTick.

By the way, I did not find how to put a plus in the rating. Or not here?

## fxsaber

Forum on trading, automated trading systems and testing of trading strategies

Features of the mql5 language, subtleties and techniques

fxsaber, 2017.11.23 00:21

`// Returns true only if the real tick mode is selected (in the tester)`

// Before using it, there must be at least one OnTick called by the tester

bool IsRealTicks( void )

{

MqlTick Tick;

return(SymbolInfoTick(_Symbol, Tick) && (Tick.volume || !(Tick.flags & TICK_FLAG_LAST)));

}

Usage example

`// The expert Advisor will only be tested in real tick mode`

How to do this in OnInit (without OnTick) – I do not know.void OnTick()

{

static bool IsRemove = true;

if (IsRemove)

{

IsRemove = MQLInfoInteger(MQL_TESTER) && !IsRealTicks();

if (IsRemove)

{

Print("Real ticks mode is needed!");

ExpertRemove();

return;

}

}

//........

}