Multi 10:4 Trader EA

Post Reply
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Re: Multi 10:4 Trader EA

Post by snailbeard »

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);
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Re: Multi 10:4 Trader EA

Post by snailbeard »

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.
MrLong

Re: Multi 10:4 Trader EA

Post by MrLong »

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
bazze

Re: Multi 10:4 Trader EA

Post by bazze »

MrLong,will you fix this in the new version?
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Re: Multi 10:4 Trader EA

Post by snailbeard »

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
MrLong

Re: Multi 10:4 Trader EA

Post by MrLong »

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.
MrLong

Re: Multi 10:4 Trader EA

Post by MrLong »

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
User avatar
KevinT
Trader
Posts: 113
Joined: Fri Jan 06, 2012 4:23 am

Re: Multi 10:4 Trader EA

Post by KevinT »

:ugeek: Amazing collective ness tug man 8-)
och
Posts: 7
Joined: Fri Sep 14, 2012 8:19 am

Re: Multi 10:4 Trader EA

Post by och »

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...
AnotherBrian

Re: Multi 10:4 Trader EA

Post by AnotherBrian »

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.
Post Reply

Return to “Nanningbob 10.x”