[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 309
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Exactly. The global variable Reason gets a value, but it does not get it in deinit(), but in init() so that when running init(), you can see the reason for the last deinitialization and perform a certain action based on the value. But it does not work as it should.
You have been told how to do it. It is in deinit() that we find out the reason for the last deinitialisation and pass it through a variable declared globally. In init() you check the value of the variable and find out the reason for the last deinitialisation. It works!!!
PS Apparently not everyone realises that init()/deinit() do not change the values of globally declared variables unless explicitly stated in statements within functions.
Actually, it's better not to close orders in init(). There, MarketInfo() often does not work as expected.
You have been told how to do it. It is in deinit() that we find out the reason for the last deinitialisation and pass it through a variable declared globally. In init() you check the value of the variable and find out the reason for the last deinitialisation. It works!!!
This suggested what you would do with this feature. A feature like this is usually run through history.
I can't even imagine running the function in a loop...
I can't imagine that the function would run in a loop...
You're welcome:
I realized that Artem has a problem with switching from M5 TF. There is an error there. I would like to check if it is so. Maybe it is a bug of MT4.
No, it's not a bug. Here's the EA. Changed timeframes from M1 to H1
19:20:02 111 CADJPY,M15: initialized19:20:09 111 CADJPY,M15: DeinitReason 3
19:20:09 111 CADJPY,M15: deinitialized
19:20:09 111 CADJPY,M15: uninit reason 3
19:20:09 Supertrend[1] CADJPY,M15: deinitialized
19:20:09 Supertrend[1] CADJPY,M15: uninit reason 3
19:20:09 HLC CADJPY,M15: deinitialized
19:20:09 HLC CADJPY,M15: uninit reason 3
19:20:09 AMA optimized1 CADJPY,M15: deinitialized
19:20:09 AMA optimized1 CADJPY,M15: uninit reason 3
19:20:09 AMA optimized1 CADJPY,M15: deinitialized
19:20:09 AMA optimized1 CADJPY,M15: uninit reason 3
19:20:09 Supertrend[1] CADJPY,H1: initialized
19:20:09 HLC CADJPY,H1: initialized
19:20:09 AMA optimized1 CADJPY,H1: initialized
19:20:09 AMA optimized1 CADJPY,H1: initialized
19:20:09 111 CADJPY,H1: initialized
No, it's not a bug. Here's the EA. Changed timeframes from M1 to H1
That's good! I also have a lot of reasons for deinitialization.
Actually, it's better not to close orders in init(). There MarketInfo() often does not work as expected.
I can't even imagine that this function would run in a loop...
That's good! Because I too have a lot tied up in the reasons for deinitialisation.
Yes. You cannot. It is written in the help. It's a common thing.Here is the final variant to check. The previous one was not very successful, because init()/deinit() sometimes do not make friends with print()
I wondered how to write a function. The idea is that when N candles roll back in a certain direction, it should calculate the number of candles. BUT. For this there are several conditions, or more precisely will be a list of them over time.
Let's say the trend, for example, is directed downwards,... ...a pullback goes up. I want, if 5 candlesticks went up, and each candlestick was bullish, and, for example, the size of each candlestick was larger thani_sizeOfCurrBar, and some other conditions, then output the number of continuously bullish bars, and return some result from the function.
What is the best way to write it? At the moment I've started to write, and I understand that I should run it through a loop by bars, and somehow I should limit the view in the depth of history not by a fixed number of bars, but by bars, with those parameters, which we are interested in by conditions.
Here's what I have, got:
At the moment we are just going from the penultimate bar to the bar with index 6, i.e. 5 bars in a row. But I want my Expert Advisor to search only for the bars that are bullish and not for all of them in a row. How to implement it adequately?
I have sort of correctly filtered by size.
And when everything is already written, the counter will calculate the number of continuous bars with nht,etvsvb parameters and if there are enough of such bars, some value of the function will be returned.
You have been told how to do it. It is in deinit() that we find out the reason for the last deinitialisation and pass it through a variable declared globally. In init() you check the value of the variable and find out the reason for the last deinitialisation. It works!!!
PS Apparently not everyone realises that init()/deinit() do not change the values of globally declared variables unless explicitly stated in statements within functions.
Actually, it's better not to close orders in init(). There MarketInfo() often does not work as expected.