Announcement

Collapse
No announcement yet.

Converting code

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

  • Converting code

    Hi

    I have just started to use e signal after using amibroker for a while. I have created formulas in AB for backtesting but am struggling to convert them to EFS. Could somebody please advise how to convert the following.

    Buy = LinearReg( Close , 13 ) > Ref( LinearReg( Close , 13 ) , -1 )
    AND Ref( LinearReg( Close , 13) , -1 ) > Ref( LinearReg( Close , 13 ) , -2 )

    Pretty much it says to create a buy signal at open on the next bar when the LRI has risen for the last 2 bars. Any help is appreciated.

    Thanks

    Dean

  • #2
    Just to add, the LRI that I am using is not part of the std indicators. It was downloaded from these forums and is as follows

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("Linear Regression Indicator");
    setCursorLabelName("LR", 0);
    setDefaultBarFgColor(Color.red, 0);
    setDefaultBarThickness(2, 0);

    var fp1 = new FunctionParameter("nLength", FunctionParameter.NUMBER);
    fp1.setName("Periods");
    fp1.setLowerLimit(1);
    fp1.setDefault(20);
    }

    var bInit = false;
    var xLR = null;

    function main(nLength) {
    if (bInit == false) {
    xLR = efsInternal("calcLR", nLength);
    bInit = true;
    }


    var nLR = xLR.getValue(0);

    return nLR;
    }


    function calcLR(nLen) {

    // y = Ax + B;
    // A = SUM( (x-xAVG)*(y-yAVG) ) / SUM( (x-xAVG)^2 )
    // A = slope
    // B = yAVG - (A*xAVG);

    if (close(-(nLen-1)) != null) {
    var xSum = 0;
    var ySum = 0;
    var i = 0;
    for (i = 0; i < nLen; i++) {
    xSum += i;
    ySum += close(-i);
    }
    var xAvg = xSum/nLen;
    var yAvg = ySum/nLen;
    var aSum1 = 0;
    var aSum2 = 0;
    i = 0;
    for (i = 0; i < nLen; i++) {
    aSum1 += (i-xAvg) * (close(-i)-yAvg);
    aSum2 += (i-xAvg)*(i-xAvg);
    }
    var A = (aSum1 / aSum2);
    var B = yAvg - (A*xAvg);
    }

    return B;
    }

    Comment


    • #3
      Re: Converting code

      Hi Dean,

      PHP Code:
      Buy LinearRegClose 13 ) > RefLinearRegClose 13 ) , -)
      AND 
      RefLinearRegClose 13) , -) > RefLinearRegClose 13 ) , -
      The appropriate conditional statement matching your conditional above and the example efs would be as follows:

      PHP Code:
      var Buy=((xLR.getValue(0)>xLR.getValue(-1)) && (xLR.getValue(-1)>xLR.getValue(-2)));//~ if true, Buy==boolean true 
      Hope this helps.

      Originally posted by drcdean
      Hi

      I have just started to use e signal after using amibroker for a while. I have created formulas in AB for backtesting but am struggling to convert them to EFS. Could somebody please advise how to convert the following.

      Buy = LinearReg( Close , 13 ) > Ref( LinearReg( Close , 13 ) , -1 )
      AND Ref( LinearReg( Close , 13) , -1 ) > Ref( LinearReg( Close , 13 ) , -2 )

      Pretty much it says to create a buy signal at open on the next bar when the LRI has risen for the last 2 bars. Any help is appreciated.

      Thanks

      Dean

      Comment


      • #4
        Hi Steve

        Thanks for your reply. i am having problems with errors where it says xLR has no properties. could you advise on how to fix this.

        Thanks

        Dean

        Comment


        • #5
          Dean,

          If you are getting that message with the accompanying efs you mentioned indicates that the variable xLR is undefined. The conditional I provided assumed xLR was a valid Series object.

          Is the efs you posted returning a value to the chart?

          Comment


          • #6
            The posted EFS for the LRI below does return a value on the chart i.e. it displays as it should. I think i need somebody to create the first part of the formula I am trying to reproduce that will create the long signals as I originally requested. Once I have that and see how the code is referenced back to the LRI I should be right to go on with it.

            Dean

            Comment


            • #7
              Dean,

              Based on your post that the efs had previously returned a value to the chart, I downloaded what you had posted. Then I placed the conditional I provided to you (that created the long signals as you originally requested) within the main function.

              I had expected an error based on your followup post, but the efs ran without an error as shown in this screenshot. This indicates there is an implementation issue on your end.





              If you are not comfortable working through your development issues on the forum, and it’s imperative that you get a custom formula coded for your personal trading system, eSignal does maintain a list of consultants that can provide you assistance. The listing is maintained at this link eSignal EFS Development Partners (click the imbedded link)

              I hope this helps.

              Comment


              • #8
                Hi Steve

                Again thanks for your time. Are you able to post the total EFS you created to trigger the long signals. I would rather keep trying myself than have somebody convert it for me as I think it is the best way to learn.

                Dean

                Comment


                • #9
                  Hi Dean,

                  attached is a copy of the efs you posted with the conditional added. I recommend you take a look at the links below my signature on back-testing, I've found the examples and backtest docs very helpful.

                  Originally posted by drcdean
                  Hi Steve

                  Again thanks for your time. Are you able to post the total EFS you created to trigger the long signals. I would rather keep trying myself than have somebody convert it for me as I think it is the best way to learn.

                  Dean
                  Attached Files
                  Last edited by Guest; 08-17-2008, 07:25 PM.

                  Comment


                  • #10
                    Hi Steve

                    Thanks for posting the EFS. It was actually the same as what I had done. It loads up fine but when I run the backtest there are no trades listed. I have tried with yours and I still get no trades. Any suggestions?

                    Dean

                    Comment


                    • #11
                      Dean,


                      Originally posted by drcdean


                      Hi Steve

                      Thanks for posting the EFS. It was actually the same as what I had done. It loads up fine but when I run the backtest there are no trades listed. I have tried with yours and I still get no trades. Any suggestions?

                      Dean

                      You indicated you were having issues with errors.


                      Originally posted by drcdean
                      Hi Steve

                      Thanks for your reply. i am having problems with errors where it says xLR has no properties. could you advise on how to fix this.

                      Thanks

                      Dean

                      The conditional I added was setting a variable to true, in effect a flag. To execute the strategy analyzer, you have to imbed specific commands which will direct how your trade is executed.

                      I recommend you take a look at the links below my signature on back-testing, I've found the examples and backtest docs very helpful.


                      Please read all of the reference material and take a look at the examples at the links I previously recommended below. After completing that, take excerpts from the examples and incorporate the appropriate code into wht you have started and we can proceed from there.

                      Comment

                      Working...
                      X