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

 

I don't want to make a new topic, I just don't understand how the EA works, maybe my elders can tell me something.

I have several indicators used in my Expert Advisor.

But in the log I can see that one of them is constantly loaded by EA, then unloaded. I don't understand this behavior.

It says uninit reason 1, what does it mean ? Other indicators are not unloaded because

2017.03.21 12:12:25.316 MTF_WPR USDRUR,H4: uninit reason 1
2017.03.21 12:09:06.551 MTF_WPR USDRUR,H4: initialized
2017.03.21 12:09:06.551 Custom indicator MTF_WPR USDRUR,H4: loaded successfully
2017.03.21 12:07:15.316 Custom indicator MTF_WPR USDRUR,H4: removed
2017.03.21 12:07:15.316 MTF_WPR USDRUR,H4: uninit reason 1
2017.03.21 12:04:12.957 MTF_WPR USDRUR,H4: initialized
2017.03.21 12:04:12.957 Custom indicator MTF_WPR USDRUR,H4: loaded successfully
2017.03.21 11:43:29.316 Custom indicator MTF_WPR USDRUR,H4: removed
2017.03.21 11:43:29.316 MTF_WPR USDRUR,H4: uninit reason 1
2017.03.21 11:38:04.097 MTF_WPR USDRUR,H4: initialized
2017.03.21 11:38:04.097 Custom indicator MTF_WPR USDRUR,H4: loaded successfully
2017.03.21 11:36:15.316 Custom indicator MTF_WPR USDRUR,H4: removed
2017.03.21 11:36:15.316 MTF_WPR USDRUR,H4: uninit reason 1
2017.03.21 11:30:11.582 MTF_WPR USDRUR,H4: initialized
2017.03.21 11:30:11.582 Custom indicator MTF_WPR USDRUR,H4: loaded successfully
2017.03.21 11:06:17.316 Custom indicator MTF_WPR USDRUR,H4: removed
2017.03.21 11:06:17.316 MTF_WPR USDRUR,H4: uninit reason 1
 
harbor:

I don't want to make a new topic, I just don't understand how the EA works, maybe my elders can tell me something.

I have several indicators used in my Expert Advisor.

But in the log I can see that one of them is constantly loaded by EA, then unloaded. I don't understand this behavior.

It says uninit reason 1, what does it mean ? Other indicators are not unloaded because

Incorrectly set indicator parameters in iCustom()
 
Thank you, I think so.
 
Artyom Trishkin:

In this thread I want to begin to help those who really want to understand and learn programming in the new MQL4 and want to easily switch to MQL5 - the languages are very similar.

This will be a good place to discuss tasks, algorithms of their solution and any other questions, anyway, related to MT programming.

I hope that other experienced members of our forum will join us and the thread will be of interest to all.


Hello


I have such a question. How to write a code in MQL4m? For example, I need to sum up the prices and divide by the number of these prices. Consider this: 1,05000+1,06000+1,07000+1,08000:4= 1,06500



Thank you very much!

 
isiklik:


Hello

I have a question. How do I write code in MQL4? For example, I need to sum up the prices and divide by the number of these prices. For example: 1,05000+1,06000+1,07000+1,08000:4= 1,06500.

Thank you very much!

double res=(1.05+1.06+1.07+1.08)/4.0;
 
Artyom Trishkin:

Thank you very much, Artyom!


Old age is not a joy! I forgot to tell you about the most important thing.

Let's say I have a N number of trades opened in MT4 in one direction with different prices.

How to write a code, MT4 would take these prices from a chart, add them up, divide by the number of open trades in one direction. Then add 200 pips.

The price obtained would prescribe these deals in TakeProfit.

Now I hope that's all. :)


Thank you very much!

 
isiklik:

Thank you very much, Artyom!


Old age is not a joy! I forgot to tell you about the most important thing.

Let's say I have a N number of trades opened in MT4 in one direction with different prices.

How to write a code, MT4 would take these prices from a chart, add them up, divide by the number of open trades in one direction. Then add 200 pips.

The price obtained would prescribe these deals in TakeProfit.

Now I hope that's all. :)


Thank you very much!

You need to calculate the breakeven price, and add / subtract to it N-number of pips. Look it up, or see how to calculate breakeven
 
Vitaly Muzichenko:
You need to calculate the breakeven price and add or subtract N number of points to it. Look it up, or see how to calculate breakeven

No, I do not. Why do I need to breakeven? I need to calculate the amount of open orders to give them a total Take.
 
Maxim Kuznetsov:

you can calculate "in how many bars there will be a crossover" (just school geometry)

and the date can only be approximated from this, the bars are only formed when the market is open, i.e. they are different for each instrument.

Simplified, if you know the calendar in advance:

  • add 24 hours to the current day, if it turns out to be Saturday/Sunday you skip it, if it's a general calendar holiday you skip it, if it's a bank holiday you skip it.
  • for W1 and higher you should take into account that the weekly bar starts from Saturday to Sunday, M1 - as by calendar
  • For a TF less than a day, you also have to take into account the opening/closing time of the market and the schedule of your DC
  • when you change the dates (in the morning, at the first ticks) you have to redo all previous calculations

that is so messy, that it is a big problem in MT :-)


If you have a week week you should take it into account.

 
isiklik:

Thank you very much, Artyom!


Getting old is not a joy! I forgot to tell you about the most important thing.

Let's say I have a N number of trades opened in MT4 in one direction with different prices.

How to write a code, MT4 would take these prices from a chart, add them up, divide by the number of open trades in one direction. Then add 200 pips.

The price obtained would prescribe these deals in TakeProfit.

Now I hope that's all. :)


Thank you very much!

You loop through all open positions in your account and filter them by magic number and type.
If you get the right type of position, you increase by 1 the size of time array and enter into it the opening price of this position.
When the loop is complete, then you will have an array with opening prices of all necessary positions.
In the loop, add up all of the values in the array, and at the end of the loop, divide the resulting value by the size of the array.
That is it - you have a calculated price. Now add the required number of points*Point() to it.
And the next interesting thing - if the obtained price turns out to be lower than the opening price of the position (Buy), it will not be a Take Profit, but a Stop Loss