# forex software

Create and Test Forex Strategies

forex software

Forex Software

Create and Test Forex Strategies

# Formula for R Squared?

Forex Software → Formula for R Squared?

Pages 1

## Posts: 9

#### Topic: Formula for R Squared?

Hi guys,

So I’m building the EA Studio trade copier and I need the formula for R squared that either EA Studio or MT4 Tracker uses?

Would anyone have that formula please?

#### Re: Formula for R Squared?

https://gist.github.com/PopovMP/9068c8b4d394c0ebe3555cdc7e67d8f6

#### Re: Formula for R Squared?

Here is the actual R-Squared code:

#### Re: Formula for R Squared?

Thanks guys much appreciated

#### Re: Formula for R Squared?

Popov wrote:

Here is the actual R-Squared code:

Hi Popov, is this the same R squared formula that is used in MT4 Tracker?

#### Re: Formula for R Squared?

I cannot say because I don't have access to the MT4 Tracker source code.

#### Re: Formula for R Squared?

Hi guys m, I’m wondering if anyone would be able to convert the r squared formula that we use in ea Studio to mql4 format to put in the trade copier to assess each strategy trading a fixed lot size. Ie my idea is to have all strategies trading 0.01 lot on the demo and then send strategies over to the live account that have a r squared above X.

I’m just having some trouble trying to get the calculation correct for mql4

#### Re: Formula for R Squared?

Here is pseudo-code, that may be easier to understand:

``````int fromBar = the bar from where you start the calculation;
double minBalance = find the minimal balance for the period;
double sumX  = 0;
double sumY  = 0;
double sumXX = 0;
double sumYY = 0;
double sumXY = 0;

int count = 0;
for (int i = 0; i <= count_of_orders; i++) {
if (Close a position) {
int    x = oreder[0].bar - fromBar + 1;
double y = oreder[0].balance - minBalance + 1;
sumX += x;
sumY += y;
sumXX += x * x;
sumYY += y * y;
sumXY += x * y;
count++;
}
}

if (count < 2) {
return 0;
}

double r  = (count * sumXY - sumX * sumY) / Math.sqrt(count * sumXX - sumX * sumX) / Math.sqrt(count * sumYY - sumY * sumY);
double r5 = Math.pow(r, 5);

return 100 * r5;``````

#### Re: Formula for R Squared?

Thanks Popov! Your a legend! I’ll give it a go and let you know how it ends up working.

Pages 1