Announcement

Collapse
No announcement yet.

R-Squared

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • R-Squared

    Can anyone help a rookie? I'd like to write the backtest code for the Barbar Star article in S&C magazine but don't quite know where to start.

    Do I write the code for backtesting into the existing code or do I have to start all over from scratch?

    Any help is greatly appreciated.

  • #2
    Re: R-Squared

    tonman1
    The first thing you may want to do [assuming you are already familiar with programming in EFS] is to review the Back Testing Tutorials which are available in the Help Guides and Tutorials-> Beginner Tutorials folder in the EFS KnowledgeBase. These will provide you with all the information and examples you need to start writing a back testing strategy.
    As to the efs you are referring to would just add the back testing logic to the existing code. Assuming that you want to base your logic on R-squared (given the title of the thread) then you would use the values of the R series which is already calculated in the script. To retrieve the values from that series you would use the .getValue() method (see the link for the description and syntax). For example if you want to go long when R-squared crosses above the lower line you would write something along the lines of the sample enclosed below.
    If instead you are not familiar with programming in EFS then I would suggest that you begin by reviewing the JavaScript for EFS video series and the Core JavaScript Reference Guide. Those will provide you with a thorough introduction to programming in JavaScript which is at the foundation of EFS. Then go through the EFS KnowledgeBase and study the Help Guides and Tutorials which will provide you with the specifics of EFS.
    Hope this helps
    Alex

    PHP Code:
    //this would be in the main function of the efs just before the return statement
    if(getBarState()==BARSTATE_NEWBAR){//at every first tick of a new bar
        
    if(!Strategy.isLong()){//if the strategy is not long
            
    if(R.getValue(-2)<nLower&&R.getValue(-1)>nLower){//if Rsquared two bars back was less than nLower
                                                             //and Rsquared at the prior bar was above nLower
                
    Strategy.doLong("Long",Strategy.MARKETStrategy.THISBAR);//go long at the Open of this bar
            
    }//end condition to go long
        
    }//end check if not already long
        //rest of your strategy logic
    }//end check for new bar 

    Originally posted by tonman1
    Can anyone help a rookie? I'd like to write the backtest code for the Barbar Star article in S&C magazine but don't quite know where to start.

    Do I write the code for backtesting into the existing code or do I have to start all over from scratch?

    Any help is greatly appreciated.

    Comment


    • #3
      R-Squared

      Thanks Alex...it does help. I'll go back and review the tutorials this weekend and see what I can get to work.

      Thanks!

      Comment


      • #4
        tonman1
        You are most welcome
        Alex


        Originally posted by tonman1
        Thanks Alex...it does help. I'll go back and review the tutorials this weekend and see what I can get to work.

        Thanks!

        Comment


        • #5
          R-Squared

          Alex,

          In the December S&C article Barbara Star uses linear regression slope to confirm direction and R-Squared for strength of trend. If I wanted to combine the indicators to give a buy/short signal based on direction and strength using both indicators at once, how would I go about doing that? Can I combine both codes into one and then write the code for the alerts and/or back test? Or can I somehow reference another formula, like the linear regression slope for instance, from the code I'm writing to run the alerts?

          Help is greatly appreciated.

          Thanks

          Comment


          • #6
            Re: R-Squared

            tonman1

            ...uses linear regression slope to confirm direction and R-Squared for strength of trend. If I wanted to combine the indicators to give a buy/short signal based on direction and strength using both indicators at once, how would I go about doing that?
            In looking at the code it seems that this is already done. In this section of code of the R-squared formula
            PHP Code:
            if (xLinReg.getValue(0) != null) {
                    var 
            getSeries(xLinReg0);  // Slope
                    
            var getSeries(xLinReg1);  // y-intercept
                    
            var getSeries(xLinReg2);  // R-Squared
                

            you can see that the series for R-squared, Slope and y-intercept are already available so all you would need to do is to reference their values using the getValue() method I indicated in my previous reply to you
            For example you can retrieve the current value of the Slope by using A.getValue(0). The value at the previous bar would be A.getValue(-1) etc.
            Alex


            Originally posted by tonman1
            Alex,

            In the December S&C article Barbara Star uses linear regression slope to confirm direction and R-Squared for strength of trend. If I wanted to combine the indicators to give a buy/short signal based on direction and strength using both indicators at once, how would I go about doing that? Can I combine both codes into one and then write the code for the alerts and/or back test? Or can I somehow reference another formula, like the linear regression slope for instance, from the code I'm writing to run the alerts?

            Help is greatly appreciated.

            Thanks

            Comment

            Working...
            X