Questions from Beginners MQL5 MT5 MetaTrader 5 - page 476

 
Sergei Vladimirov:
By the way, why do you declare a function as int if it returns true in your version, and always? )
Fixed it to void, changed the loop to reverse, as long as other people's orders don't touch it, thanks!
 
Can you please tell me how to make OnCalculate the indicator to be called not every tick, but only with a new bar?
 
Hexen:
Can you please tell me how to make OnCalculate indicator to be called not every tick, but only with a new bar?
This function will be called every tick, but you can make a new bar control inside the function.
 
Victor Nikolaev:
This function will be called every tick, but you can make a new bar check inside the function.

Thank you, it's more or less worked out. Comparingprev_calculated and rates_total you can see the appearance of new bars. And in EA it is more complicated with new bar - time check, etc.

 

Don't compare them, it's not a very reliable way: the variable prev_calculated can be reset under some conditions. Remember the time of current bar and check its change at next call:

// в самом начале функции OnCalculate()
bool bNewBar = false;

static datetime dtLastBarTime = time[rates_total-1];

if(time[rates_total-1] > dtLastBarTime)
{
   bNewBar = true;
   dtLastBarTime = time[rates_total-1];
}

PS. This is an example for MT5. In fours (and in fives if time[] array is made time series) replace time[rates_total-1] by time[0].

 
Hello,

I decided to create a simple Expert Advisor after reading the article "A Step-by-Step Guide to Writing
MQL5 Expert Advisor for Beginners" (https://www.mql5.com/ru/articles/100).

I have tested the Expert Advisor on history and wondered how to improve it.
The first thing that came to mind, apart from optimization
Apply trailing stop-loss. There is a good article on this subject:
"How to Create a Trailing Stop - MQL5 Articles" ().
(https://www.mql5.com/ru/articles/134). However, a
However, a problem arose, the Expert Advisor attached to the article does not work... i.e.
(my_first_ea_sartrailing.ex5) compiles but does not trade
the log says:
2015.11.28 22:54:38.973 2015.02.04 17:00:00 Alert: Sell order setup request failed - error code:4756
2015.11.28 22:54:38.973 2015.02.04 17:00:00 failed instant sell 0.10 EURUSD at 1.14051 sl: 1.17051 tp: 1.04051 [Invalid request]
Help to sort this out.
 
Sergei Vladimirov:

PS. This is an example for MT5.

Thank you!
 

Hello.

Can you please tell me what is the fastest and most correct way to delete all existing orders placed by the EA? Is it really possible to create an array with order numbers and delete each one? Is it impossible to get a list of active orders as well?

 
Антон:

Hello.

Can you please tell me what is the fastest and most correct way to delete all existing orders placed by the EA? Is it really possible to create an array with order numbers and delete each one? Can we get a list of active orders as well?

We do not need an array. What terminal?

 
Sergei Vladimirov:

You don't need an array. Which terminal?

MT5

Yes, I should have said that this needs to be implemented in an EA.

I found a script on mql4 - is it not relevant to 5? A couple of days ago somewhere I saw a line with a function something like "orderscancelbymagicnumber", but I cannot find anything in documentation... Confused.

Reason: