stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Multi 10:4 Trader EA
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=1619
Page 27 of 160
Author:  slipshod [ Thu Mar 21, 2013 8:20 pm ]
Post subject:  Re: Multi 10:4 Trader EA

Great work Andy, thanks!
Author:  MrLong [ Thu Mar 21, 2013 8:41 pm ]
Post subject:  Re: Multi 10:4 Trader EA

slipshod wrote:Great work Andy, thanks!

Thanks for your help also, makes life easier when we have a few of us rowing the boat.

Andy
Author:  MrLong [ Thu Mar 21, 2013 9:25 pm ]
Post subject:  Re: Multi 10:4 Trader EA

snailbeard wrote:
Wkcfx wrote:Great work guys! question; I've been testing on demo with GP, IC, Alpari and Oanda. I hope this is peculiar to my hardware but with v1.07 and about 10+ trades active I get pegged CPU and lockup no matter which broker I try? Also when I close the platform and no other apps are running the CPU stays 100% until I reboot the machine? I couldn't figure where to put Slipshod's suggestion of "Sleep()" I assume I have missed something. Any thoughts?

I'm running Win7 64 pro on a wired cat 6 lan, Intel Core2Duo 2.2GHz, 2GB, 4GB DDR2

I'll look forward to v1.08 and, if it is only my hardware, a new workstation.

thanks again!!
The DisplayGrid() screen update uses more CPU than the trading logic. I am running two copies Empty4+EA and on a 4-core machine and I get bursts of 100% CPU usage on 2 CPUs.

The simplest way of reducing the CPU load would be to reduce the rate at which the screen is updated,

depending on how you use it, this could be once per 5 seconds or once per minute, etc.

Also, MQL is heavy on string operations inside loops, I have some (untested) code to use index look-up instead of string comparisons:

Code: Select all

int allPipFactors[];

//+------------------------------------------------------------------+
//| expert Get Factor function
//+------------------------------------------------------------------+
double PFactorByName(string symbol) {
	
	for (int i = ArraySize(pipFactor) - 1; i >= 0; i--)
		if (StringFind(symbol, pipFactor[i], 0) != -1)
			return(pipFactors[i]);
	return(10000);
}


//+------------------------------------------------------------------+
//| Set up fast look-up for pip factor 
//+------------------------------------------------------------------+
void initPipFactors(string& arPairs[], int& arPipFactors[])
{

	int pairCount = ArraySize(arPairs);
	ArrayResize(arPipFactors, pairCount);

	for (int i = 0; i < pairCount; i++) {

			arPipFactors[i] = PFactorByName( arPairs[i] );
	}	
}

//+------------------------------------------------------------------+
//| Fast look-up for pip factor 
//+------------------------------------------------------------------+
int PFactor(int pairIndex ) { return (arPipFactors[pairIndex]) }

//+------------------------------------------------------------------+
//| Faster pip conversions 
//+------------------------------------------------------------------+
int doubleToPip(int symIndex, double d)
{
	return ( d * allPipFactors[symIndex] )
}

double pipToDouble(int symIndex, double pips)
{
	return ( pips / allPipFactors[symIndex])
}
Regards
Brian
Hi Brian,

Thanks for your code, I haven't tried it, but will do tomorrow.

Many Thanks
Andy
Author:  simplex [ Thu Mar 21, 2013 9:31 pm ]
Post subject:  CPU usage optimization and easier grid maintenance

Hi MrLong,

Great work! Your 1.07 EA is running for two days on one of my test accounts now - and it's really busy.

When I transferred the EA from my development machine (full HD display, quad core) to my elderly test machine (1366 pixels, weak AMD single core) the grid did not show correctly and the cpu usage was rather high. That's why I had a closer look on your code and started to work soon.

Now I have a 1.07 modification that covers the following items:
  • split your function DisplayGrid() in two functions CreateGrid() and UpdateGrid() to optimize object management and reduce cpu usage
  • replaced redundant function calls in CreateGrid() and UpdateGrid() to further optimize cpu usage
  • declared extern int GridMethod to switch between original code and simplex code (temporarily)
  • simplified positioning of columns in grid by arrays
  • simplified drawing of grid background: drawRectancle()
  • functions LabelCreate() and LabelSetText() to simplify object management
  • On my display grid columns of open trades and corr. pairs were intermingled. Fixed this.
  • changed some color settings, just a matter of personal preferences without public value
  • changed some grid coordinates to fit on my screens
NO changes were applied to trading decisions, etc. - just cpu optimization and gui stuff.

Modifying column management for the grid made it essentially easier (for me, at last) to set up the display correctly on both my machines.

Reason for the high cpu usage was that in func DisplayGrid() many calculations were done inside a double loop over the X and Y coordinates. Thus when you have e.g. 15 pairs and your display loop is running over its 10 columns all the calculations are done 150 times - without changing its input parameters. I reduced this to only one calculation and also removed some more redundancies of minor impact.

Runtime optimization lead to a significant drop of cpu usage - see screenshots bofore and after. The outcome was, that both machines' fans that were buzzing like hell when the original version ran are quiet now. I love my machines being quite while I'm working ;) .

Now I noticed you just released v 1.08. What I can offer to you and the community is to integrate my modifications in v 1.08 and send the file to you. The mods mainly consist of several new functions and an external variable to switch back and forth between your version and mine - just for testing purpose. Can be deleted after final integration.

I can easily do this over the weekend, maybe earlier.

If you're interested just drop me a line on where to deliver my code to.

Cheers to all, Jürgen
Author:  MrLong [ Thu Mar 21, 2013 9:42 pm ]
Post subject:  Re: CPU usage optimization and easier grid maintenance

simplex wrote:Hi MrLong,

Great work! Your 1.07 EA is running for two days on one of my test accounts now - and it's really busy.

When I transferred the EA from my development machine (full HD display, quad core) to my elderly test machine (1366 pixels, weak AMD single core) the grid did not show correctly and the cpu usage was rather high. That's why I had a closer look on your code and started to work soon.

Now I have a 1.07 modification that covers the following items:
  • split your function DisplayGrid() in two functions CreateGrid() and UpdateGrid() to optimize object management and reduce cpu usage
  • replaced redundant function calls in CreateGrid() and UpdateGrid() to further optimize cpu usage
  • declared extern int GridMethod to switch between original code and simplex code (temporarily)
  • simplified positioning of columns in grid by arrays
  • simplified drawing of grid background: drawRectancle()
  • functions LabelCreate() and LabelSetText() to simplify object management
  • On my display grid columns of open trades and corr. pairs were intermingled. Fixed this.
  • changed some color settings, just a matter of personal preferences without public value
  • changed some grid coordinates to fit on my screens
NO changes were applied to trading decisions, etc. - just cpu optimization and gui stuff.

Modifying column management for the grid made it essentially easier (for me, at last) to set up the display correctly on both my machines.

Reason for the high cpu usage was that in func DisplayGrid() many calculations were done inside a double loop over the X and Y coordinates. Thus when you have e.g. 15 pairs and your display loop is running over its 10 columns all the calculations are done 150 times - without changing its input parameters. I reduced this to only one calculation and also removed some more redundancies of minor impact.

Runtime optimization lead to a significant drop of cpu usage - see screenshots bofore and after. The outcome was, that both machines' fans that were buzzing like hell when the original version ran are quiet now. I love my machines being quite while I'm working ;) .

Now I noticed you just released v 1.08. What I can offer to you and the community is to integrate my modifications in v 1.08 and send the file to you. The mods mainly consist of several new functions and an external variable to switch back and forth between your version and mine - just for testing purpose. Can be deleted after final integration.

I can easily do this over the weekend, maybe earlier.

If you're interested just drop me a line on where to deliver my code to.

Cheers to all, Jürgen
Hi Jürgen,

That would be excellent, you can either post the code or just PM me.

Many Thanks

Andy
Author:  slipshod [ Thu Mar 21, 2013 9:43 pm ]
Post subject:  Re: Multi 10:4 Trader EA

Jürgen, sounds like a great enhancement - I think it goes without saying that everyone would be more than interested in what you've done here :)
Author:  Sojourner [ Thu Mar 21, 2013 9:57 pm ]
Post subject:  Re: Multi 10:4 Trader EA

FYI: For some reason 1.08 locked up on me so i shut down the teminal and deleted all the log files and restarted. Works fine now.
Author:  MrLong [ Thu Mar 21, 2013 10:07 pm ]
Post subject:  Re: Multi 10:4 Trader EA

Sojourner wrote:FYI: For some reason 1.08 locked up on me so i shut down the teminal and deleted all the log files and restarted. Works fine now.
Did you restart MT after installing, NT TMATrue SlopeHisto MTF and 10.4 RSI2_on_NT_TMA?

Andy
Author:  Sojourner [ Thu Mar 21, 2013 11:00 pm ]
Post subject:  Re: Multi 10:4 Trader EA

MrLong wrote:
Sojourner wrote:FYI: For some reason 1.08 locked up on me so i shut down the teminal and deleted all the log files and restarted. Works fine now.
Did you restart MT after installing, NT TMATrue SlopeHisto MTF and 10.4 RSI2_on_NT_TMA?

Andy

Had to. You can't get the Expert in the navigator unless you restart. ;-)
Author:  McNish [ Fri Mar 22, 2013 12:04 am ]
Post subject:  Re: Multi 10:4 Trader EA

Sojourner wrote:Had to. You can't get the Expert in the navigator unless you restart. ;-)
I'm so glad when ever I get a chance to give tips to F.T's. But here at SHF, in the midst of Brains Trust, :D

Go to the relevant Empty4, F4, compile, terminal. Check navigator ! :o

Waiting for the next version of optimized code already. :lol:

;)
All times are UTC Page 27 of 160