Download MetaTrader 5

EA acting haywire after computers hibernates for a while

To add comments, please log in or register
Hoangvodich
35
Hoangvodich  

My EA is a simple one based on moving average (just checking for crosses between slow and fast EMA) and it was supposed to put the buy order at the red dot. What happened was that my computer had been hibernating way before the red dot, so when I turned it back on the EA was feeding on information from the point right before the computer hibernated. Thus the EA instead put a buy order at the purple dot which does not make sense at all. So is there a general way to fix this problem especially when the computer hibernates (or internet connection is lost) while metatrader and EA are still running? Btw my slow EMA is yellow and fast EMA is white

Thanks

whroeder1
15727
whroeder1  
diatrochoi: fix this problem especially when the computer hibernates (or internet connection is lost)
You FIX your code. Why is your EA looking at the old bars? Why did you decide to open at the red dot when the current price is way beyond the trigger?
Hoangvodich
35
Hoangvodich  
I use shift=1 for the calculation of EMA. But in this case I just want to know how do you reset the EA (so that it's like you remove it and attach it to the graph again) when the computer is disconnected from Internet or hibernates (metatrader is still running) without me having to be there doing so manually
whroeder1
15727
whroeder1  
diatrochoi: I use shift=1 for the calculation of EMA.

There is nothing to reset. You test if the trigger condition is currently true. The red dot is 40 bars away. If you are using shift=1 then the red dot is irrelevant. Your code is BROKEN.

HaraldSchurr
67
HaraldSchurr  

Hi diatrochoi,

why don't you switch off hibernation?

Do you know how to switch hibernation off?

Hoangvodich
35
Hoangvodich  
I mean my computer runs out of battery. I just want to know if there is any coding that can counter this problem just in case it happens again
whroeder1
15727
whroeder1  
diatrochoi: any coding that can counter this problem

You can't prevent events like battery, power failure, OS crash, accidental click on the mt4 close button etc. There isn't a VPS that will guarantee 100% uptime.

You can code the EA to recover when it gets the new tick.

Hoangvodich
35
Hoangvodich  
Could you give me some general and basic idea on how to do that? Just some pseudocode would do. Here my problem is that my EA opens position based on the outcome of 2 consecutive bars, let's say bar in period N and bar in period N+1. However, computer hibernated in the middle of bar period N and metatrader wasn't closed. When the computer was back on, it was already bar period 40. Immediately the EA then took into account the info of 2 consecutive bars that it had (bar period N and bar period N+40) and open a position, which I don't want it to.
Michele Lazzarini
477
Michele Lazzarini  
diatrochoi:
Could you give me some general and basic idea on how to do that?

easy idea:
you could make the EA check when was the last tick, and to disable trading if it was more than X minutes ago (that is abnormal)
and maybe send you a warning via email or "push notification"

whroeder1
15727
whroeder1  
diatrochoi: 2 consecutive bars that it had (bar period N and bar period N+40
  1. You could test the times of those bars and make sure they are consecutive (Won't trade the first bar of the new week)
  2. I think it isn't necessary. When it reconnects, it redownloads all bars that are missing, so test #1 will do nothing.
  3. I still think your code is BROKEN.
Hoangvodich
35
Hoangvodich  
I get the idea now. Thank you all guys.
To add comments, please log in or register