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

 
Roni Iron:

Good Morning All!


Question: what is the easiest way to determine the high and low times of a bar?

Baropen/close time is not interesting.

On MT4.

Thank you!

did this

posted in KBhttps://www.mql5.com/ru/code/25897

 

Please tell me, in MT4 there was a predefined variable double Ask, and as I understand, inside void OnTick() without forced

RereshRates its value would NOT change.

In MT5, Ask is replaced by MqlTick last_tick; SymbolInfoTick(_Symbol,last_tick); double Ask=last_tick.ask ; its value is always updated by a new tick.

My problem is that I need to set the line coordinate by the value of Ask + X but I can't do it in MT5 because the line changes its coordinates after the value changes

Ask=last_tick.ask. What is your advice?

Документация по MQL5: Предопределенные переменные
Документация по MQL5: Предопределенные переменные
  • www.mql5.com
Для каждой выполняющейся mql5-программы поддерживается ряд предопределенных переменных, которые отражают состояние текущего ценового графика на момент запуска программы - эксперта, скрипта или пользовательского индикатора. Значение предопределенным переменным устанавливает клиентский терминал перед запуском mql5-программы на выполнение...
 
WinProject:

Please tell me, in MT4 there was a predefined variable double Ask, and as I understand, inside void OnTick() without forced

RereshRates its value would NOT change.

In MT5, Ask is replaced by MqlTick last_tick; SymbolInfoTick(_Symbol,last_tick); double Ask=last_tick.ask ; its value is always updated by a new tick.

My problem is that I need to set the line coordinate by the value of Ask + X but I can't do it in MT5 because the line changes its coordinates after the value changes

Ask=last_tick.ask. What is your advice?

How it did not change? It changed with every tick. But in the loop, it didn't change. Maybe you have got a little confused with it?

But in mql5 you can determine the current price before the loop and it won't change until you exit the loop.

 
Folks, sorry for the dumb question. In mt4 terminal it shows profit including commissions, swaps etc. In mt5 it shows "naked". I can't find it, is there any setting for mt5 to show it as mt4? Or it is not able to do so?
 

Is there any way to measure the width in pixels of the written text in OBJ_TEXT?

 
Alexey Viktorov:

How did it not change? It changed with every tick. But in the cycle, yes, it didn't. Maybe, you got a little confused with that one?

But in mql5 you can determine the current price before the loop and it will not change until you exit the loop.

Yes, thank you, my assumption turned out to be wrong, but the question is a bit different. I have a code, samefor MT4 and MT5:

 void OnTick()
              {
              string S=Symbol();
              double LastAsk= SymbolInfoDouble(S,SYMBOL_ASK);
              ObjectCreate(0,"hLine",OBJ_HLINE,0,0,LastAsk +500*Point());
              }

The question is that in MT4 the created line will be fixed at the price at which it was created, but in MT5 every time on a new tick the line will be drawn at a new value of LastAsk and its position will change along with the price. How can I avoid it in MT5?

 
WinProject:

Yes, thanks, my assumption was wrong, but the question is a bit different. There is a code,same for MT4 and MT5:

The question is that in MT4 the line created will be stationary at the price at which it was created, but in MT5 every time on a new tick the line will be drawn at a new LastAsk value and its position will change along with the price. How can I avoid it in MT5?

Check the line availability by name. If there isn't one, create one. These are the basics in general
 
Artyom Trishkin:
Check for a line by name. If there is no line, create one. This is the basics in general.

Thank you, what else can I read about these programming logic basics? It seems elementary, but it's hard to figure out from scratch.

 if(ObjectFind(0,"hLine"))

I added a condition and everything worked.

 
WinProject:

Thank you, what else can I read about these programming logic basics? It seems elementary, but it's hard to figure out from scratch.

I added a condition and everything worked.

Suddenly (as usual) ObjectGetInteger(0,objectName,OBJPROP_TYPE) works faster.

ObjectFind is a synchronous command, i.e. it waits for a complete update (and availability) of the chart objects.

If you work with your own objects (ie created in your own stock), you should not use ObjectFind - you already know in which window object was created and that it most likely exists and it is the right type.
The worst that can happen is that the user deletes the object or changes the property

 
WinProject:

Yes, thanks, my assumption turned out to be wrong, but the question is a bit different. There is code,same for MT4 and MT5:

The question is that in MT4 the line created will be stationary at the price at which it was created, but in MT5 every time on a new tick the line will be drawn at a new value of LastAsk and its position will change along with the price. How can I avoid it in MT5?

I don't remember it, I need to check it but I don't want to. Maybe, in mql4 when trying to create an object named after already existing one, an error was just returned, while in mql5 it's not an error but parameter modification, if the coordinates are different.

As Artem said - check the existence of the object

int  ObjectFind( 
   long    chart_id,     // идентификатор графика 
   string  name          // имя объекта 
   );
Reason: