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

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

Will converting F# to MQL4/5 improve CPU & Memory usage? 1 reply

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

DDE Server - Getting Market Data - High CPU Usage Issue 0 replies

Suggestions for EMA usage over Multi Time Frames 0 replies

Metatrader 4 99% CPU Usage 0 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 1
Attachments: CPU usage increasing over time
Exit Attachments
Tags: CPU usage increasing over time
Cancel

CPU usage increasing over time

  • Post #1
  • Quote
  • First Post: Edited 10:51am Jul 14, 2017 10:18am | Edited 10:51am
  •  tanwt
  • | Joined Feb 2016 | Status: Member | 76 Posts
hi all,

i did some experiment and notice that when i start using my EA, the CPU usage is low in the region of about 5%
after running for a few hours, it went up to about 15% on average

i read somewhere you need to close your terminal and restart every now and then to optimize it

due to the way my ea works, i can't allow the terminal to be closed and on again

my questions is, is there a way within an ea to somehow reset something so that the cpu is reduced? btw, i need the data within the memory intact (eg data in arrays)

Note : 1 thing i notice is, even without EA on, if there's a lot of open order, it will use quite a lot of cpu resources

thanks
  • Post #2
  • Quote
  • Jul 14, 2017 1:33pm Jul 14, 2017 1:33pm
  •  mladen
  • Joined Apr 2007 | Status: ... | 801 Posts
Quoting tanwt
Disliked
hi all, i did some experiment and notice that when i start using my EA, the CPU usage is low in the region of about 5% after running for a few hours, it went up to about 15% on average i read somewhere you need to close your terminal and restart every now and then to optimize it due to the way my ea works, i can't allow the terminal to be closed and on again my questions is, is there a way within an ea to somehow reset something so that the cpu is reduced? btw, i need the data within the memory intact (eg data in arrays) Note : 1 thing i notice...
Ignored
No. Nothing that you can do in the EA
You could try reporting that to mq service desk, but do not hope too much from that : they usually ignore anything that they don't like (and what you are describing is a classical "leaking as bucket" case which will remain ignored)
_____________________
PS: you can easily save and restore arrays to and from files. Simply use :

FileWriteArray() and
FileReadArray()

functions.
 
 
  • Post #3
  • Quote
  • Edited 2:28pm Jul 14, 2017 2:05pm | Edited 2:28pm
  •  Nicholishen
  • Joined Jul 2005 | Status: zzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzz | 1,289 Posts
Quoting tanwt
Disliked
hi all, i did some experiment and notice that when i start using my EA, the CPU usage is low in the region of about 5% after running for a few hours, it went up to about 15% on average i read somewhere you need to close your terminal and restart every now and then to optimize it due to the way my ea works, i can't allow the terminal to be closed and on again my questions is, is there a way within an ea to somehow reset something so that the cpu is reduced? btw, i need the data within the memory intact (eg data in arrays) Note : 1 thing i notice...
Ignored
Here's another solution for saving to file... I personally would use CArrayDouble from the std library instead of a C-style array, but this solves for both...

Inserted Code
//+------------------------------------------------------------------+
//|                                                  ArrayToFile.mq4 |
//|                                                      nicholishen |
//|                                   www.reddit.com/u/nicholishenFX |
//+------------------------------------------------------------------+
#property copyright "nicholishen"
#property link      "www.reddit.com/u/nicholishenFX"
#property version   "1.00"
#property strict
#include <Arrays\ArrayDouble.mqh>
#include <Files\FileBin.mqh>
 
class MyArray : public CArrayDouble
{
   public: void CopyArray(double &arr[])
   {
      ArrayResize(arr,Total());
      for(int i=0;i<Total();i++)
         arr[i] = this[i];
   }
};
 
void OnStart()
{
   CFileBin       file;
   MyArray        arr;
   double         any_data[];
   int            handle;
   string         file_name = "my_array.bin";
   CopyClose(Symbol(),Period(),0,10,any_data);
 
   //--- write array to file
   arr.AssignArray(any_data);
   handle = file.Open(file_name,FILE_WRITE);
   arr.Save(handle);
   file.Close();
  
   //!--- OH NO! We lost data!
   arr.Clear();
   ArrayFree(any_data);
   //---
  
   //---Read array from file and copy back to C style array[]
   handle = file.Open(file_name,FILE_READ);
   arr.Load(handle);
   arr.CopyArray(any_data);
   file.Close();
  
   for(int i=0;i<ArraySize(any_data);i++)
      Print("From file to Array [",i,"]= ",any_data[i]);
  
}
//+------------------------------------------------------------------+
Attached File(s)
File Type: mq4 ArrayToFile.mq4   2 KB | 157 downloads
 
 
  • Post #4
  • Quote
  • Jul 14, 2017 5:07pm Jul 14, 2017 5:07pm
  •  machine25
  • | Joined Aug 2015 | Status: Member | 137 Posts
Quoting tanwt
Disliked
hi all, i did some experiment and notice that when i start using my EA, the CPU usage is low in the region of about 5% after running for a few hours, it went up to about 15% on average i read somewhere you need to close your terminal and restart every now and then to optimize it due to the way my ea works, i can't allow the terminal to be closed and on again my questions is, is there a way within an ea to somehow reset something so that the cpu is reduced? btw, i need the data within the memory intact (eg data in arrays) Note : 1 thing i notice...
Ignored
depending if your EA is reading indicators properly coded or not;

depending if your EA is reading an history orders increasing with time

or many open orders in your case

depending if the EA is on each tick mode

it will use more or less CPU

or even the EA can register and read a lot of serie data
 
 
  • Post #5
  • Quote
  • Jul 14, 2017 11:00pm Jul 14, 2017 11:00pm
  •  tanwt
  • | Joined Feb 2016 | Status: Member | 76 Posts
tq for all the feedback

i have managed to reduce the cpu resources by 80% by optimizing my EA code

basically what i did was to change checking open order every tick to every new candle
 
 
  • Post #6
  • Quote
  • Edited 6:52am Jul 15, 2017 6:22am | Edited 6:52am
  •  mladen
  • Joined Apr 2007 | Status: ... | 801 Posts
Quoting tanwt
Disliked
tq for all the feedback i have managed to reduce the cpu resources by 80% by optimizing my EA code basically what i did was to change checking open order every tick to every new candle
Ignored
That ("optimizing" EA code to check open order on new candle instead on every tick) is not going to prevent "after running for a few hours, it went up to about 15% on average" issue. It will only delay it.

Oh well : happy coding
 
1
  • Post #7
  • Quote
  • Jul 15, 2017 9:41pm Jul 15, 2017 9:41pm
  •  tanwt
  • | Joined Feb 2016 | Status: Member | 76 Posts
Quoting mladen
Disliked
{quote} That ("optimizing" EA code to check open order on new candle instead on every tick) is not going to prevent "after running for a few hours, it went up to about 15% on average" issue. It will only delay it. Oh well : happy coding
Ignored
hi

i believe the issue is as time goes by, more open orders are available. this cause the loop to get bigger

i already monitor the optimized code for many many hours and i purposely allow the terminal to have many more open orders than normal (just to create worst case condition) and the CPU resources still stays at around 5%

where as in my old code, it went up to 15% within a matter of 2 or 3 hours
 
 
  • Post #8
  • Quote
  • Last Post: Jul 16, 2017 6:34am Jul 16, 2017 6:34am
  •  tanwt
  • | Joined Feb 2016 | Status: Member | 76 Posts
Quoting Nicholishen
Disliked
{quote} Here's another solution for saving to file... I personally would use CArrayDouble from the std library instead of a C-style array, but this solves for both... //+------------------------------------------------------------------+ //| ArrayToFile.mq4 | //| nicholishen | //| www.reddit.com/u/nicholishenFX | //+------------------------------------------------------------------+ #property copyright "nicholishen" #property link "www.reddit.com/u/nicholishenFX" #property version "1.00" #property strict #include <Arrays\ArrayDouble.mqh> #include...
Ignored
Hi

do you mind to advice, if i want to use this for 2 dimensional array, what should be changed?
 
 
  • Platform Tech
  • /
  • CPU usage increasing over time
  • 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