Code correlation

Viewing 10 posts - 1 through 10 (of 10 total)
  • #14174

    Hi,

    I wonder how i could code the correlation between an indicator and price? I hope you can help me, and if so please add a concrete example.

    For example, RSI correlation with price, how should i code this?

    I want to use this with my own personal indicators.

    Thanks in advance.

    #14180

    There is no built in correlation function I think. Here is how I calculate the relevance of an indicator:

    To measure for example RSI impact on future price movements, you need to divide these movements into two categories, negative and positives. For each bar, look at the price ten bars ago (close[10]), and the RSI value ten bars ago. Calculate how the price has changed. This is either a positive or a negative number. If positive add this change times the RSI value to a sum variable.  This will weight the collected RSI value based on how big of a price impact it precedes. It can also be weighted for time/trade number to reflect changing market conditions, if you want to.

    You will also have another variable called PositiveNumber, which is the total number of posititive instances. The same for negative instances. So for each you have a sum, which is the sum of all respective positive or negative price changes times the RSI indicator values, divided by the total number of instances. This way, you will see the average of the RSI before a positive change and a negative. You can use these values in your trading system, or to see the indicator’s importance. Take the difference between the negative and positive average divided values, which could be around 15 units let’s say. Divide this difference, with the difference between the high[800] and low[800] for RSI, and you will have a value for the indicators prediction strength. To fully utilize it, you need to compare RSI prediction strength with strength of other indicators.

    I have a system based on this, but I don’t want to share the code.

    In here maybe there is a working example: http://www.prorealcode.com/topic/correlation-coefficient/

    1 user thanked author for this post.
    #14229

    Thank you very much Wing for great answer! So this code will show if indicator Y correlates with Price X? So i could just use different indicators in “Y” if they act like a line that could be compared with price movements?

    I think this is a very strong tool that i would like to learn more about. I have really been missing a code to test my indicators relevance. Correlation vs relevance ought to be much the same?

    Is this code accurate and the same as you described in your post? if not, could you show how to code what you described?

    And so if i have a indicator that i want to compare to price i type that indicator in “Y”?

    Thanks in advance, keep up the good work.

     

    #14236

    Regarding the code i posted above, how do i incorporate it and understand it? If “0” then indicator and price is balanced and correlated? and otherwise it’s not? What about horizontal movements in the indicator, seems like it’s in balance then, or will this (if working) want to reach 0 again?

    How does a high “Period” affect the result in the indicator, lagging or something? Or just reflecting a bigger period of correlation?

    I wish for so much information as possible so i can learn how to code this.

    Thanks in advance!

    #14291

    What I described is not really a correlation with price, it is a correlation between the indicator and price CHANGE. Yes, I think that is the relevance.

    I have not used the code example you are talking about, I just found it by searching. If you want to do what I do you must code what I describe in the first post. My code is based on what I described, but I have added additional weighting factors on it, so the whole system is many hundreds lines of code. It would be a big hassle to show the simple version. Note that most of the code for a system like this will be in an indicator, because it can check price history before you start trading. The indicator is then used by a trading system. It returns two variables to the system for each indicator being compared to price change: The indicator value when prices will go down, and the indicator value when price will go up. The system can then check if the current value is below/above these values and place trades.

    It is the best system I have created so far, and I am only 50 % done with it, so you are right that it is a very interesting approach. This is because the program looks at price history and learns the behaviour of price compared to indicators.

    If you are new to programming or PRT this can be hard, but until you are able to program it yourself I’m afraid you will not be able to utilize it in a good way. If you want to learn more about these methods, look up “Machine learning” and “Regression analysis”. PRT is not powerful enough to do machine learning like ‘real’ programming languages but methods like the one I describe can be done.

    #14388

    I see!
    I wish it will work out for you and you’ll manage to create something great.
    Been coding abit, but mostly know the fundamentals, but i’m making progress, often easier to understand already created codes than to create them by myself tho. But i understand, keep up the great work.

    Thanks for the tips, will look into it!

    Is it possible to code correlation between different instruments? If so, do you know how?

    #14406

    Correlation between different instruments is available in a few built-in indicators in PRT, but none of these are accessible when coding. Why they have limited this function I don’t know, but right now you can’t make any system based on several instruments.

    #14407

    Okey i see, that’s to bad.

    So i have made som coding and would love some input if you can spare the time! I have not yet implented everything that you described, etc what you described as weight, got some problems with that, and the last part.

    My ability has taken me here.

    I tried some with *RSI and so on, and to use a count to divide the number of instances but as i’m not truly sure what i should do i took away that.

    Thanks in advance

     

    #14412

    I did not specify exactly how I did, so at last I have a small example for you to try on for example the DAX 30 min timeframe. Note that this one does not check every ten bars, it checks between two times. In this example ADX is used, not RSI. I also did not mention, that not only is the indicator muliplied, the price change is squared. Some time weighting is included here, which you can try. Comparing the two returned values to the maximum/minmum over past periods to see relevance is not included here. In addition to this, you probably need to do this with several indicators for a good system. Enjoy.

    2 users thanked author for this post.
    #14438

    Thanks alot Wing! Will look into this and try to learn from the code.

     

Viewing 10 posts - 1 through 10 (of 10 total)

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