forex software

Create and Test Forex Strategies

forex software

Skip to forum content

Forex Software

Create and Test Forex Strategies

You are not logged in. Please login or register.


Forex Software → Technical Matters → Formula for R Squared?

Pages 1

You must login or register to post a reply

RSS topic feed

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?

maybe this will help you

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

or check this thread https://forexsb.com/forum/topic/7645/balance-line-stability-development/page/2/

Re: Formula for R Squared?

Here is the actual R-Squared code:

R-Squared.

Re: Formula for R Squared?

Thanks guys much appreciated

Re: Formula for R Squared?

Popov wrote:

Here is the actual R-Squared code:

R-Squared.

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.

Posts: 9

Pages 1

You must login or register to post a reply

Forex Software → Technical Matters → Formula for R Squared?

Similar topics in this forum