Correlation Coefficient

Forums ProRealTime English forum ProBuilder support Correlation Coefficient

Tagged: 

Viewing 15 posts - 1 through 15 (of 17 total)
  • #11148

    Dear ProRealCode,
    I was wondering if it’s possible to code a correlation coefficient between volume and price?
    My first thought was to code some kind of loop for getting (x[i]-avereage[n](x)).

    Unfortunately I keep getting wrong result in relation to my own manual work.

    Can somebody please help me with what I think is a relative simple code. 🙂

    #11184

    Hi Lars,

    Yes it’s possible, but quite difficult to find how if you don’t already have made a formula for it. Since Volume and price don’t share the same “scale”.. Are you talking about Pearson R Correlation?

    #11205

    Hi Nicolas,

    It was exactly what I was having in mind. My first thought was to take development in price correlated with development in volume. It could be % increase/ decrease in price correlated with % increase/decrease in volume.

    #11207

    I think you are looking for things that already exist. You should have a look at indicators already made that use volumes in their own calculations: OBV, volume ROC, etc..

    #11382

    For me there is a difference between those indicators  you mention. ROC behave in a similar way but doesn’t take volume into consideration. I will be grateful if you can help me code the Pearson correlation coefficient! 🙂

    #11389

    Well, this is 2 very different time series. Price never reset to zero as Volume do each day. So I assume the best way to do would be to reckon up price as long as volumes, average these 2 values and then doing comparison with a pseudo correlation coefficient formula. IMO,  I don’t believe we are going somewhere, but we could give it a try.

    #11398

    I tried it on Tradingview, and my simple code seems to work. Their platform have the function correlation built-in so it was easy relative to PRT which doesn’t have it.

    x = close/close[1]-1
    y = volume/volume[1]-1

    The interpretation of the correlation between x and y:

    Positive correlation – sign of stregnth
    Negative correlation – sign of weakness

    It was my first thought of this indicator.

    #11468

    Hi Lars,

    I’ll do my best to make a function for correlation calculation. That way it would be helpful to re-use it for future purposes. It involved a lot of work and I’m actually very busy with my prog services customers. I’ll get back to you ASAP.

    #11536

    Hi,

    Maybe something like this would do the trick. It’s far from a direct calculation though..

    Please not that you need to change the period of lookback for calculation of the correlation coefficient at the beginning of the code (50 periods by default).

     

    #11554

    Actually I have coded something similar but as you correctly stated it is not the correct way of calculation. It gives some lagging signals compared to the indicator in Tradingview.

    After your post I got the idea to rewrite the Pearson correlation equation and I might have come up with the correct way of calculation. Can you confirm my assertion?

     

    #11569

    I don’t think you make it the correct way. It needs standard deviation calculation (a and b variables from my formula). I also don’t understand why you are using average instead of summation of the whole datas?

    Well, I’ll try differently later, I’m done for today 🙂

    #11570

    My formula is based on the attached image but I don’t know if I have put it together the right way.

    Looking forward to hear from you 🙂

    #11603

    I think I finally got it right now. Seems that TV has a wrong formula explanation in its own documentation.. Well here is the code:

     

    Do you have any example for comparing with the TV result on the same instrument/timeframe?

     

    1 user thanked author for this post.
    #12665

    Sorry for the late answer which is caused by my vacation. The way you calculate the correlation does not provide my with the correct result compared to me manual calculation. The way I ended up with gives me almost the correct result despite from some decimals.

    #42729

    Hi Nicholas, I’m Domenico. The Pearson R Correlation  is a measure of the linear correlation between two variables Xand Y. It has a value between +1 and −1, where 1 is total positive linear correlation, 0 is no linear correlation, and −1 is total negative linear correlation. But I have tryed your code and it has values greater than 1. Can you help me, please?

Viewing 15 posts - 1 through 15 (of 17 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login