Questions from Beginners MQL5 MT5 MetaTrader 5 - page 986

 
Artyom Trishkin:

In OnInit() call the time series of the symbol: iTime(Symbol,Timeframe,1);

At the very beginning of OnTick(), ask for the needed bar of the needed timeseries via the corresponding iFunc(), or if( iTime(Symbol,Timeframe,10)==0) return;

In this case, the Expert Advisor will not detect a new bar and will wait for the next tick.

In OnInit() we have requested the time series data, thereby activating data paging.

In OnTick() we check if the minimally required history is available to the EA and if it is not yet available, we wait for the next tick.

And until all of the data required by the Expert Advisor is received, it will wait for the next tick.

As soon as all the necessary data is pumped and obtained, the Expert Advisor will start to work with the new bar and the required history.

To keep the serial data up to date, be sure to access it at least once every two minutes. Make a second timer for about a minute and a half (90 seconds) and in it, simply access any timeseries of the desired symbol, for example iTime(Symbol,Timeframe,1); Without checking the received data - just "move" the history. Then all data on the symbol will always be up to date.

Of course, I will try to check the new bar using all TFs but is it not synchronous, this is not MT4. The problem is not with the bar but with non-performance of indicators that are called from the indicator, which in turn is called from the Expert Advisor.

I work on minutes, so the history should always be up to date.

And, all these checks are done for the test and they will just slow down the work on a real account, because everything works slower there than in the tester's stationary conditions, I repeat that on a real account the indicator works correctly.

 

So far I have solved the problem by checking the readiness of indicators, which have failed, before the start of the main code

//При появлении нового бара проверяем корректность расчета индикаторов
      if(isNewBar_Predv_Calc_Ind()==true)Predv_Calc_Ind=true;
      if(Predv_Calc_Ind==true)
      {
      double arr_DonUp=ZZ_Vibor(0,2,0);
      double arr_DonDown=ZZ_Vibor(0,3,0);
      double arr_DonUp_m2=ZZ_Vibor(1,2,0);
      double arr_DonDown_m2=ZZ_Vibor(1,3,0);
      double arr_DonUp_m5=ZZ_Vibor(2,2,0);
      double arr_DonDown_m5=ZZ_Vibor(2,3,0);
      double arr_DonUp_m15=ZZ_Vibor(3,2,0);
      double arr_DonDown_m15=ZZ_Vibor(3,3,0);
      if (arr_DonUp<1     || arr_DonDown<1    ||
          arr_DonUp_m2<1  || arr_DonDown_m2<1 ||
          arr_DonUp_m5<1  || arr_DonDown_m5<1 ||
          arr_DonUp_m15<1 || arr_DonDown_m15<1
         )return;
      else{Predv_Calc_Ind=false;}      
      }
//Операции выполняются только при появлении следующего бара   
   if(!isNewBar()) return;

But this approach is not universal, because you need to list all the indicators, is there another, more universal method to make the tester environment work correctly?

 
Artyom Trishkin:

In OnTick() we check if the minimally required history is available to the Expert Advisor, and if it is not available yet - we wait for the next tick.

And until all of the data required by the EA is obtained, it will wait for the next tick.

As soon as all the necessary data is pumped and obtained, the Expert Advisor will begin to work with the new bar and the required history.

How do you propose to check the availability of the history, I don't understand...

 
fxsaber:

Add this line before the MQL4 function

and it will work in MT5.

That is genius. Thank you very much!

 
Hello, I am a young retiree who would like to make such buttons in MT5.

Can you tell MT5 can implement such buttons, maybe already have one, share the code ...


The button "Start " and the button "Close all orders". MT5, all pairs, all timeframes, 4/5 signs. Initial lot 0.01 including cents.
Provide for slippage and requotes.

Functions for the "Start" button
Once you have manually unwrapped the Fibo, you should open 1 to 11 orders at once in BAY or SELL at the current price.
If you have previously selected in the settings how many and which orders (1, 2, 5, 7 or all 11) should be opened in the direction of the unfolded Fibo.
In the settings it was possible to specify the manual lot size for each order, or dynamically increase/decrease it.

TP - Take Profit is set in ascending order from 1 to 11 orders at the Fibo levels of 61.8; 78.6; 100.0;
161.8; 185.4; 200.0; 261.8; 285.0; 423.6; 561,8; 685.4

SL - Stop Loss in size of - 2 spreads (calculated automatically) from the zero line of the fibo.

TS - Trailing Stop pulls all orders behind it.
1. Trailing Stop moves SL of all orders to the 38.2 + 2 spreads if price has reached the 61.8 level,
2. Trailing Stop moves SL of all remaining orders to the 50.0 level + 2 spreads if the price reaches the 100.0 level,
3. trailing SL of all remaining orders to 78.6+2 spreads if price reaches the 161.8 level,
4. trailing SL of all remaining orders to the 100.0+2 spread level when the price reaches the 261.8 level. 5.
5. trailing SL of all remaining orders to the 200.0+2 spread level when the price reaches the 423.6 level,
6. trailing moves SL of all remaining orders to the 423.6+2 spread level if the price has reached 561.8;

Thefunction of the button "Close all orders" is to forcefully close all orders.
 

Hello, if the Ask and Bid prices from the CSymbolInfo class are more or less clear, how to get for example SessionInterest or SessionBuyOrdersVolume or SessionPriceLimitMin, It gives out zeros, I can't understand why...

 
Александр Юрин:

Hello, if the Ask and Bid prices from CSymbolInfo class is more or less clear, how to get e.g. SessionInterest or SessionBuyOrdersVolume or SessionPriceLimitMin, it gives out zeros, I can't understand why...

If the trading server broadcasts this information, you will receive it.

As a rule, this information is broadcasted by Brokers for stock symbols (do not confuse Brokers and dealing centres).

 
Vladimir Karputov:

If a trading server broadcasts this information, you will receive it.

This information is usually broadcast by Brokers for exchange symbols (don't confuse Brokers and dealing centres).

Broker Otkritie, the RTS Index Futures, I assume must broadcast at least SessionPriceLimitMin and SessionPriceLimitMax (because they are as far as I understand the opening prices used in market orders). Doesn't the opening translate... I prescribe for example:

Print(m_symbol.Ask()," ",m_symbol.SessionBuyOrdersVolume()); - from your EA

I get only Ask prices in the log

Files:
y2a4cgbfjw.png  63 kb
 

Please help in writing a piece of code that would correctly determine the date of the last bar with any shift in any TF, accurate to the current TF.

int              N_bar=iBarShift(Symbol(),PERIOD_CURRENT,iTime(Symbol(),PERIOD_H1,0));//номер текущего бара
datetime         StopDt=iTime(Symbol(),PERIOD_CURRENT,N_bar+1);//только для минуток и то может быть не корректно!

Print("StopDt_Shift=",TimeToString(StopDt,TIME_DATE|TIME_MINUTES));

This code generally works, but only if the start time of the current bar coincides with the actual (rounded to the minute) bar, as my current chart is M1. And if it doesn't coincide, then various mishaps occur, depending on different TFs. For example, I need to know the start date of the latest M1 bar in the last hour, if it was 12 o'clock no problem, the time will be 12:59, but if it was 13 o'clock it will be 13:58 because the hourly bar opened at 14:05 and not at 14:00 and theiBarShift function returned the nearest bar to 14:00, i.e. 13:59.

Added: made this, it seems to work

datetime         StopDt=iTime(Symbol(),PERIOD_CURRENT,Bars(Symbol(),PERIOD_CURRENT,iTime(Symbol(),TF_iDeltaP,_Shift-1),iTime(Symbol(),PERIOD_CURRENT,0)));
 
Александр Юрин:

Otkritie broker, RTS index futures, I assume it should broadcast at least SessionPriceLimitMin and SessionPriceLimitMax (as I understand they are used in market orders by opening prices ). Doesn't the opening translate... I prescribe for example:

Print(m_symbol.Ask()," ",m_symbol.SessionBuyOrdersVolume()); - from your EA

I get only Ask prices in the log

Is the server real or a demo?