• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 8:42pm
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 8:42pm
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

Metatrader is running slow. Taking 50%CPU 25 replies

MetaTrader is running slow: Taking 100% of CPU 6 replies

Metatrader using 40% of the CPU all the time when using EA 6 replies

while loop in EA causes 100% CPU 15 replies

Metatrader 4 99% CPU Usage 0 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
Tags: EA is using 100% CPU in MetaTrader 4
Cancel

EA is using 100% CPU in MetaTrader 4

  • Post #1
  • Quote
  • First Post: Jan 28, 2013 4:11am Jan 28, 2013 4:11am
  •  Jasus
  • | Joined Jun 2010 | Status: Portuguese Escudo Trader | 303 Posts
I imagine it must be because it doesn't get out a loop for some reason. So I put this code in every loop, so that the EA finishes forcefully if it's on a loop for more than 14 minutes:

Inserted Code
if ( isHigherThan(TimeCurrent() - last_time_sr, 840) ) 
{ 
   kill_ea = true; 
   Alert(Symbol()," finish");
   return; 
}

And the line

Inserted Code
datetime last_time_sr = TimeCurrent();

in the beginning of every function. If kill_ea is true, start will always return 0 in the beginning.

What's possibly wrong with the EA to get 100% CPU usage?
  • Post #2
  • Quote
  • Jan 28, 2013 1:56pm Jan 28, 2013 1:56pm
  •  Ralome
  • Joined Nov 2011 | Status: Ups and downs | 289 Posts
Quoting Jasus
Disliked
if ( isHigherThan(TimeCurrent() - last_time_sr, 840) )
Ignored
Why not TimeCurrent()-last_time_sr>840? :-)

Quoting Jasus
Disliked
Inserted Code
datetime last_time_sr = TimeCurrent();
in the beginning of every function.
Ignored
Your variable is declared locally, but checking line is most probably in the main part of your code, so last_time_sr will always be empty.

But it still doesn't solve the stuck-in-the-loop situation. But you may have to show more/all of your code to find the problem.
Even if you fall on your face, you're still moving forward.
 
 
  • Post #3
  • Quote
  • Jan 29, 2013 2:43am Jan 29, 2013 2:43am
  •  MaxDoom
  • | Commercial Member | Joined Feb 2010 | 13,255 Posts
Quoting Jasus
Disliked
I imagine it must be because it doesn't get out a loop for some reason. So I put this code in every loop, so that the EA finishes forcefully if it's on a loop for more than 14 minutes:

Inserted Code
if ( isHigherThan(TimeCurrent() - last_time_sr, 840) ) 
{ 
   kill_ea = true; 
   Alert(Symbol()," finish");
   return; 
}

And the line

Inserted Code
datetime last_time_sr = TimeCurrent();

in the beginning of every function. If kill_ea is true, start will always return 0 in the beginning.

What's possibly wrong with the EA to...
Ignored

do one of two things.....


1. put interactive information on the screen or in the log file as the ea is looping to show where it is at and how long each loop is taking, then you will know where the problem is.

2. put you complete code on here and hope somebody else will do it for you
 
 
  • Post #4
  • Quote
  • Jan 29, 2013 4:17am Jan 29, 2013 4:17am
  •  Jasus
  • | Joined Jun 2010 | Status: Portuguese Escudo Trader | 303 Posts
I found that the problem was using the EA on a specific pair. Once I removed it from that pair, the problem was gone. This isn't the first time that it happens, what's wrong with that pair to make the EA go crazy?
 
 
  • Post #5
  • Quote
  • Jan 29, 2013 4:31am Jan 29, 2013 4:31am
  •  fxtr51
  • Joined Jan 2010 | Status: Member | 1,163 Posts
Quoting Jasus
Disliked
I found that the problem was using the EA on a specific pair. Once I removed it from that pair, the problem was gone. This isn't the first time that it happens, what's wrong with that pair to make the EA go crazy?
Ignored
There is nothing wrong with a pair, the problem is your code.

Asking questions without providing information is like asking the following question:
"Hello Jasus, do you know what the unknown man in that unknown country said to the other
unknown woman at midnight ? "

Now try to answer that question correctly if you can.
 
 
  • Post #6
  • Quote
  • Jan 29, 2013 5:07am Jan 29, 2013 5:07am
  •  Ralome
  • Joined Nov 2011 | Status: Ups and downs | 289 Posts
Without infos my only idea is that your loop gets stuck due to a miscalculation of pips. Eg. you attach the EA to a JPY pair, and you have some line using 0.0001 as pip value (or vice versa, 0.01 for USD pairs etc.). Fxtr51 said it right, it can't be the pair itself
Even if you fall on your face, you're still moving forward.
 
 
  • Post #7
  • Quote
  • Jan 29, 2013 1:33pm Jan 29, 2013 1:33pm
  •  Jasus
  • | Joined Jun 2010 | Status: Portuguese Escudo Trader | 303 Posts
Quote
Disliked
There is nothing wrong with a pair, the problem is your code.

Asking questions without providing information is like asking the following question:
"Hello Jasus, do you know what the unknown man in that unknown country said to the other
unknown woman at midnight ? "

Now try to answer that question correctly if you can.
I can't give any more information, unless you want me to post a code with 2k+ lines here... You may not know the answer, but there may be people who had this problem before and they may know what's the problem.
 
 
  • Post #8
  • Quote
  • Edited 1:57pm Jan 29, 2013 1:37pm | Edited 1:57pm
  •  fxtr51
  • Joined Jan 2010 | Status: Member | 1,163 Posts
Quoting Jasus
Disliked
I can't give any more information, unless you want me to post a code with 2k+ lines here... You may not know the answer, but there may be people who had this problem before and they may know what's the problem.
Ignored
Well, good luck then. You need it.

MaxDoom mentioned how to find the bug yourself.

If an EA doesn´t find the way out of a loop, the condition for leaving the loop is not met.
If you debug, you have to know the values of the variables to find the reason.
7bit has published a nice debug method which is better than the Print statement of mql.

http://www.forexfactory.com/showthread.php?t=245303
 
 
  • Post #9
  • Quote
  • Feb 1, 2013 8:36am Feb 1, 2013 8:36am
  •  Jasus
  • | Joined Jun 2010 | Status: Portuguese Escudo Trader | 303 Posts
Quoting fxtr51
Disliked
If an EA doesn´t find the way out of a loop, the condition for leaving the loop is not met.
If you debug, you have to know the values of the variables to find the reason.
7bit has published a nice debug method which is better than the Print statement of mql.

http://www.forexfactory.com/showthread.php?t=245303
Ignored
The condition must be met, maybe it gets stuck in other thing. I'm kind of lost, because what variables do I need to look for? Besides, there's a strange thing. If I put the EA running in 20 pairs for example, 1 by 1, this problem doesn't appear. But if I start Metatrader with the EA already in those 20 pairs, it goes to 100% CPU usage until I close MT.
 
 
  • Post #10
  • Quote
  • Feb 1, 2013 1:57pm Feb 1, 2013 1:57pm
  •  Ralome
  • Joined Nov 2011 | Status: Ups and downs | 289 Posts
Quoting Jasus
Disliked
The condition must be met, maybe it gets stuck in other thing. I'm kind of lost, because what variables do I need to look for? Besides, there's a strange thing. If I put the EA running in 20 pairs for example, 1 by 1, this problem doesn't appear. But if I start Metatrader with the EA already in those 20 pairs, it goes to 100% CPU usage until I close MT.
Ignored
I made an indicator that alerts the result of IndicatorCounted(). I attached it and closed MT4. When I restarted it, this happened:

19:46:16 MT4_Start_Test EURUSD,M1: Alert: 0
19:46:17 MT4_Start_Test EURUSD,M1: Alert: 8999
19:46:18 MT4_Start_Test EURUSD,M1: Alert: 8999
19:46:18 MT4_Start_Test EURUSD,M1: Alert: 0
19:46:19 MT4_Start_Test EURUSD,M1: Alert: 8999
19:46:19 MT4_Start_Test EURUSD,M1: Alert: 8999
19:46:19 MT4_Start_Test EURUSD,M1: Alert: 8999
19:46:26 MT4_Start_Test EURUSD,M1: Alert: 8999

So IC jumped back to zero. But this lovely feature of MT4 can happen later too, not just at the beginning. I believe it has to do with MT4 writing into the history file.

Maybe this helps.
Even if you fall on your face, you're still moving forward.
 
 
  • Post #11
  • Quote
  • Last Post: Feb 3, 2013 11:09am Feb 3, 2013 11:09am
  •  Jasus
  • | Joined Jun 2010 | Status: Portuguese Escudo Trader | 303 Posts
I made the EA run with a 10 seconds interval between pairs, in the beginning, and it's fine now
 
 
  • Platform Tech
  • /
  • EA is using 100% CPU in MetaTrader 4
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023