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

Multi 10:4 Trader EA
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=1619
Page 15 of 160
Author:  snailbeard [ Sat Mar 16, 2013 6:00 pm ]
Post subject:  Re: Multi 10:4 Trader EA

Should this have an extra 'else' ?

Code: Select all

if ( processTrades(Pairs[y], OP_BUYSTOP) > 0 )
	ObjectSetText("signal" + 5 + y, "BUYSTOP ( "+processTrades(Pairs[y], OP_BUYSTOP)+" )", fontSize, displayfont, BullishColor);
else if ( processTrades(Pairs[y], OP_SELLSTOP) > 0  )
	ObjectSetText("signal" + 5 + y, "SELLSTOP ( "+processTrades(Pairs[y], OP_SELLSTOP)+" )", fontSize, displayfont, BearishColor);
ObjectSetText("signal" + 6 + y, "", fontSize, displayfont, Black);
Author:  snailbeard [ Sat Mar 16, 2013 7:06 pm ]
Post subject:  Re: Multi 10:4 Trader EA

Several people have reported a screen update problem on some crim's platforms.

It seems to be something to do with 'unclosed' bars or missing bars in calcCorrelation()
which causes an infinite loop

example:

Code: Select all

18:48:52 Multi_10_4_EAv1.06 AUDCAD,H4: S1: AUDCAD, S2: GBPAUD, tf: 1440, periods: 50
18:48:52 Multi_10_4_EAv1.06 AUDCAD,H4: while (symbol2.close[i] < EPSILON)...
18:48:52 Multi_10_4_EAv1.06 AUDCAD,H4: GBPAUD.close[14]=  iClose(GBPAUD, tf,14) : 0.00000
I have added '+1' ... (shift=1) to anything using iClose()

and I have made a work around in calcCorrelation.

I am also wondering if ForceLoadHistory might help as well?

Here is the hack to make it skip the calculation if finds empty values:

Code: Select all

double calcCorrelation(string symbol, string symbol2, int tf, int periods) {
	double symbol.close[];
	double symbol2.close[];
	double corr.avg1 = 0.0,
	            corr.avg2 = 0.0,
	                 corr.sum = 0.0,
	                      corr.dev1 = 0.0,
	                           corr.dev2 = 0.0,
	                                corr.ro1 = 0.0,
	                                     corr.ro2 = 0.0,
	                                          corr = 0.0;

	static bool skipcalcCorrelation = false;
	string dbgstr   = "";
	
	if( skipcalcCorrelation ==true )
		return (0.0);
		
	ArrayResize(symbol.close, periods);
	ArrayResize(symbol2.close, periods);

	ArrayInitialize(symbol.close, 0);
	ArrayInitialize(symbol2.close, 0);
	
	int shift = 1;
	
	for (int i = 0; i < periods; i++) {
		//Print("For each period...");
		while (symbol.close[i] < EPSILON) {
			symbol.close[i] = iClose(symbol, tf, i + shift);
			if( symbol.close[i] < EPSILON ) {
				dbgstr = "S1: " + symbol + ", S2: " + symbol2 +", tf: " + tf + ", periods: " + periods; 
				Print( dbgstr);
				Print("while (symbol.close[i] < EPSILON) ...");
				Print( symbol + ".close[" + i +"] =  iClose(" + symbol2 + ", tf,"+ i+") : " + DoubleToStr( iClose(symbol, tf, i + shift), 5) );
				skipcalcCorrelation = true;
			}
			break;
		}
		while (symbol2.close[i] < EPSILON) {
			symbol2.close[i] = iClose(symbol2, tf, i + shift);
			if(symbol2.close[i] < EPSILON) {
				dbgstr = "S1: " + symbol + ", S2: " + symbol2 +", tf: " + tf + ", periods: " + periods; 
				Print( dbgstr);
				Print("while (symbol2.close[i] < EPSILON)...");
				Print( symbol2 + ".close[" + i +"]=  iClose(" + symbol2 + ", tf,"+ i+") : " + DoubleToStr( iClose(symbol2, tf, i + shift), 5) );
				skipcalcCorrelation = true;
			}
			break;
		}
		corr.avg1 += symbol.close[i];
		corr.avg2 += symbol2.close[i];
	}

	corr.avg1 /= periods;
	corr.avg2 /= periods;

	for (i = 0; i < periods; i++) {
		corr.dev1 = symbol.close[i] - corr.avg1;
		corr.dev2 = symbol2.close[i] - corr.avg2;
		corr.sum += corr.dev1 * corr.dev2;
		corr.ro1 += corr.dev1 * corr.dev1;
		corr.ro2 += corr.dev2 * corr.dev2;
	}

	corr = MathSqrt(corr.ro1) * MathSqrt(corr.ro2);
	if (corr == 0)
		return(0);

	return((corr.sum / corr) * 100);
}
After making this change the screen now refreshes and CPU is no longer running hot.
Author:  MrLong [ Sat Mar 16, 2013 9:15 pm ]
Post subject:  Re: Multi 10:4 Trader EA

snailbeard wrote:Several people have reported a screen update problem on some crim's platforms.

It seems to be something to do with 'unclosed' bars or missing bars in calcCorrelation()
which causes an infinite loop

example:

Code: Select all

18:48:52 Multi_10_4_EAv1.06 AUDCAD,H4: S1: AUDCAD, S2: GBPAUD, tf: 1440, periods: 50
18:48:52 Multi_10_4_EAv1.06 AUDCAD,H4: while (symbol2.close[i] < EPSILON)...
18:48:52 Multi_10_4_EAv1.06 AUDCAD,H4: GBPAUD.close[14]=  iClose(GBPAUD, tf,14) : 0.00000
I have added '+1' ... (shift=1) to anything using iClose()

and I have made a work around in calcCorrelation.

I am also wondering if ForceLoadHistory might help as well?

Here is the hack to make it skip the calculation if finds empty values:

Code: Select all

double calcCorrelation(string symbol, string symbol2, int tf, int periods) {
	double symbol.close[];
	double symbol2.close[];
	double corr.avg1 = 0.0,
	            corr.avg2 = 0.0,
	                 corr.sum = 0.0,
	                      corr.dev1 = 0.0,
	                           corr.dev2 = 0.0,
	                                corr.ro1 = 0.0,
	                                     corr.ro2 = 0.0,
	                                          corr = 0.0;

	static bool skipcalcCorrelation = false;
	string dbgstr   = "";
	
	if( skipcalcCorrelation ==true )
		return (0.0);
		
	ArrayResize(symbol.close, periods);
	ArrayResize(symbol2.close, periods);

	ArrayInitialize(symbol.close, 0);
	ArrayInitialize(symbol2.close, 0);
	
	int shift = 1;
	
	for (int i = 0; i < periods; i++) {
		//Print("For each period...");
		while (symbol.close[i] < EPSILON) {
			symbol.close[i] = iClose(symbol, tf, i + shift);
			if( symbol.close[i] < EPSILON ) {
				dbgstr = "S1: " + symbol + ", S2: " + symbol2 +", tf: " + tf + ", periods: " + periods; 
				Print( dbgstr);
				Print("while (symbol.close[i] < EPSILON) ...");
				Print( symbol + ".close[" + i +"] =  iClose(" + symbol2 + ", tf,"+ i+") : " + DoubleToStr( iClose(symbol, tf, i + shift), 5) );
				skipcalcCorrelation = true;
			}
			break;
		}
		while (symbol2.close[i] < EPSILON) {
			symbol2.close[i] = iClose(symbol2, tf, i + shift);
			if(symbol2.close[i] < EPSILON) {
				dbgstr = "S1: " + symbol + ", S2: " + symbol2 +", tf: " + tf + ", periods: " + periods; 
				Print( dbgstr);
				Print("while (symbol2.close[i] < EPSILON)...");
				Print( symbol2 + ".close[" + i +"]=  iClose(" + symbol2 + ", tf,"+ i+") : " + DoubleToStr( iClose(symbol2, tf, i + shift), 5) );
				skipcalcCorrelation = true;
			}
			break;
		}
		corr.avg1 += symbol.close[i];
		corr.avg2 += symbol2.close[i];
	}

	corr.avg1 /= periods;
	corr.avg2 /= periods;

	for (i = 0; i < periods; i++) {
		corr.dev1 = symbol.close[i] - corr.avg1;
		corr.dev2 = symbol2.close[i] - corr.avg2;
		corr.sum += corr.dev1 * corr.dev2;
		corr.ro1 += corr.dev1 * corr.dev1;
		corr.ro2 += corr.dev2 * corr.dev2;
	}

	corr = MathSqrt(corr.ro1) * MathSqrt(corr.ro2);
	if (corr == 0)
		return(0);

	return((corr.sum / corr) * 100);
}
After making this change the screen now refreshes and CPU is no longer running hot.
Thanks SnailBeard,

Excellent.

Andy
Author:  bazze [ Sun Mar 17, 2013 11:28 am ]
Post subject:  Re: Multi 10:4 Trader EA

MrLong,will you fix this in the new version?
Author:  snailbeard [ Sun Mar 17, 2013 1:11 pm ]
Post subject:  Re: Multi 10:4 Trader EA

This is an update on the screen update issue:

Running the script ForceLoadHistoricalData did not have an effect on the undefined iClose values.

The following is an improved version of the previous hack:
a) It no longer completely turns off all correlation calculations
b) It only skips the calculation for the pairs that have missing bars
c) It logs the pairs with missing bars
d) It stops logging missing bars after it has done it 40 times (to stop the log filling the disk)

Code: Select all

double calcCorrelation(string symbol, string symbol2, int tf, int periods) {
	double symbol.close[];
	double symbol2.close[];
	double corr.avg1 = 0.0,
	            corr.avg2 = 0.0,
	                 corr.sum = 0.0,
	                      corr.dev1 = 0.0,
	                           corr.dev2 = 0.0,
	                                corr.ro1 = 0.0,
	                                     corr.ro2 = 0.0,
	                                          corr = 0.0;

	bool skipcalcCorrelation = false;
	static bool reportMissingData = true;
	static int reportCount = 0;
	static int reportMaxCount = 40;
	string dbgstr   = "";
	
	ArrayResize(symbol.close, periods);
	ArrayResize(symbol2.close, periods);

	ArrayInitialize(symbol.close, 0);
	ArrayInitialize(symbol2.close, 0);
	
	int shift = 1;
	
	for (int i = 0; i < periods; i++) {
		//Print("For each period...");
		if (symbol.close[i] < EPSILON) {
			symbol.close[i] = iClose(symbol, tf, i + shift);
			if( symbol.close[i] < EPSILON ) {
				if( reportMissingData == true) {
					dbgstr = "S1: " + symbol + ", S2: " + symbol2 +", tf: " + tf + ", periods: " + periods; 
					Print( dbgstr);
					Print("(symbol.close[i] < EPSILON) ...");
					Print( symbol + ".close[" + i +"] =  iClose(" + symbol2 + ", tf,"+ i+") : " + DoubleToStr( iClose(symbol, tf, i + shift), 5) );
					reportCount++;
					if( reportCount  >= reportMaxCount ) 
						reportMissingData = false;
				}
				skipcalcCorrelation = true;
			}
		}
		if (symbol2.close[i] < EPSILON) {
			symbol2.close[i] = iClose(symbol2, tf, i + shift);
			if(symbol2.close[i] < EPSILON) {
				if( reportMissingData == true) {
					dbgstr = "S1: " + symbol + ", S2: " + symbol2 +", tf: " + tf + ", periods: " + periods; 
					Print( dbgstr);
					Print("(symbol2.close[i] < EPSILON)...");
					Print( symbol2 + ".close[" + i +"]=  iClose(" + symbol2 + ", tf,"+ i+") : " + DoubleToStr( iClose(symbol2, tf, i + shift), 5) );
					reportCount++;
					if( reportCount  >= reportMaxCount ) 
						reportMissingData = false;
				}
				skipcalcCorrelation = true;
			}
		}

		if(skipcalcCorrelation)
			return (0.0);

		corr.avg1 += symbol.close[i];
		corr.avg2 += symbol2.close[i];
	}

	corr.avg1 /= periods;
	corr.avg2 /= periods;

	for (i = 0; i < periods; i++) {
		corr.dev1 = symbol.close[i] - corr.avg1;
		corr.dev2 = symbol2.close[i] - corr.avg2;
		corr.sum += corr.dev1 * corr.dev2;
		corr.ro1 += corr.dev1 * corr.dev1;
		corr.ro2 += corr.dev2 * corr.dev2;
	}

	corr = MathSqrt(corr.ro1) * MathSqrt(corr.ro2);
	if (corr == 0)
		return(0);

	return((corr.sum / corr) * 100);
}
Regards

Brian
Author:  MrLong [ Sun Mar 17, 2013 1:43 pm ]
Post subject:  Re: Multi 10:4 Trader EA

snailbeard wrote:This is an update on the screen update issue:

Running the script ForceLoadHistoricalData did not have an effect on the undefined iClose values.

The following is an improved version of the previous hack:
a) It no longer completely turns off all correlation calculations
b) It only skips the calculation for the pairs that have missing bars
c) It logs the pairs with missing bars
d) It stops logging missing bars after it has done it 40 times (to stop the log filling the disk)

Code: Select all

double calcCorrelation(string symbol, string symbol2, int tf, int periods) {
	double symbol.close[];
	double symbol2.close[];
	double corr.avg1 = 0.0,
	            corr.avg2 = 0.0,
	                 corr.sum = 0.0,
	                      corr.dev1 = 0.0,
	                           corr.dev2 = 0.0,
	                                corr.ro1 = 0.0,
	                                     corr.ro2 = 0.0,
	                                          corr = 0.0;

	bool skipcalcCorrelation = false;
	static bool reportMissingData = true;
	static int reportCount = 0;
	static int reportMaxCount = 40;
	string dbgstr   = "";
	
	ArrayResize(symbol.close, periods);
	ArrayResize(symbol2.close, periods);

	ArrayInitialize(symbol.close, 0);
	ArrayInitialize(symbol2.close, 0);
	
	int shift = 1;
	
	for (int i = 0; i < periods; i++) {
		//Print("For each period...");
		if (symbol.close[i] < EPSILON) {
			symbol.close[i] = iClose(symbol, tf, i + shift);
			if( symbol.close[i] < EPSILON ) {
				if( reportMissingData == true) {
					dbgstr = "S1: " + symbol + ", S2: " + symbol2 +", tf: " + tf + ", periods: " + periods; 
					Print( dbgstr);
					Print("(symbol.close[i] < EPSILON) ...");
					Print( symbol + ".close[" + i +"] =  iClose(" + symbol2 + ", tf,"+ i+") : " + DoubleToStr( iClose(symbol, tf, i + shift), 5) );
					reportCount++;
					if( reportCount  >= reportMaxCount ) 
						reportMissingData = false;
				}
				skipcalcCorrelation = true;
			}
		}
		if (symbol2.close[i] < EPSILON) {
			symbol2.close[i] = iClose(symbol2, tf, i + shift);
			if(symbol2.close[i] < EPSILON) {
				if( reportMissingData == true) {
					dbgstr = "S1: " + symbol + ", S2: " + symbol2 +", tf: " + tf + ", periods: " + periods; 
					Print( dbgstr);
					Print("(symbol2.close[i] < EPSILON)...");
					Print( symbol2 + ".close[" + i +"]=  iClose(" + symbol2 + ", tf,"+ i+") : " + DoubleToStr( iClose(symbol2, tf, i + shift), 5) );
					reportCount++;
					if( reportCount  >= reportMaxCount ) 
						reportMissingData = false;
				}
				skipcalcCorrelation = true;
			}
		}

		if(skipcalcCorrelation)
			return (0.0);

		corr.avg1 += symbol.close[i];
		corr.avg2 += symbol2.close[i];
	}

	corr.avg1 /= periods;
	corr.avg2 /= periods;

	for (i = 0; i < periods; i++) {
		corr.dev1 = symbol.close[i] - corr.avg1;
		corr.dev2 = symbol2.close[i] - corr.avg2;
		corr.sum += corr.dev1 * corr.dev2;
		corr.ro1 += corr.dev1 * corr.dev1;
		corr.ro2 += corr.dev2 * corr.dev2;
	}

	corr = MathSqrt(corr.ro1) * MathSqrt(corr.ro2);
	if (corr == 0)
		return(0);

	return((corr.sum / corr) * 100);
}
Regards

Brian

Thanks Brian, excellent work.
Author:  MrLong [ Sun Mar 17, 2013 1:45 pm ]
Post subject:  Re: Multi 10:4 Trader EA

bazze wrote:MrLong,will you fix this in the new version?
Yes, I've made quite a few changes and fixes, so I'll run the EA tomorrow and release version 1.07
if all the changes are ok.

Andy
Author:  KevinT [ Sun Mar 17, 2013 1:56 pm ]
Post subject:  Re: Multi 10:4 Trader EA

:ugeek: Amazing collective ness tug man 8-)
Author:  och [ Sun Mar 17, 2013 5:20 pm ]
Post subject:  Re: Multi 10:4 Trader EA

MrLong wrote:
bazze wrote:MrLong,will you fix this in the new version?
Yes, I've made quite a few changes and fixes, so I'll run the EA tomorrow and release version 1.07
if all the changes are ok.

Andy

NO! I am so disapointed!
On Friday you promissed a release on Sunday afternoon!
This is not professional! ;-)
I will have to wait for tomorrow...
Author:  AnotherBrian [ Sun Mar 17, 2013 5:56 pm ]
Post subject:  Re: Multi 10:4 Trader EA

och wrote:
MrLong wrote:
bazze wrote:MrLong,will you fix this in the new version?
Yes, I've made quite a few changes and fixes, so I'll run the EA tomorrow and release version 1.07
if all the changes are ok.

Andy

NO! I am so disapointed!
On Friday you promissed a release on Sunday afternoon!
This is not professional! ;-)
I will have to wait for tomorrow...
I guess you get what you paid for dude :lol:

Nice job so far, looks very encouraging.
All times are UTC Page 15 of 160