Announcement

Collapse
No announcement yet.

Problem with Backtesting.

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

  • Problem with Backtesting.

    Hi I have made the folowing efs (PriceRelative.efs):
    See attached.

    I'm trying to call(load) it from a backtest.
    For some reason the parameters passed to it is wrong.
    I have tried with all versions of efs().
    Any ideas ???
    Thanks
    JR

    File:AlertTest.efs
    =============================================
    var vMACD = null;
    var vRelStrInd = null;

    /**
    * This function is called only once, before any of the bars are loaded.
    * Place any study or EFS configuration commands here.
    */
    function preMain()
    {
    setPriceStudy(true);
    }

    /**
    * The main() function is called once per bar on all previous bars, once per
    * each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
    * in your preMain(), it is also called on every tick.
    */
    function main()
    {
    //var vRelStrInd = efs("PriceRelative.efs", 0, sym(getSymbol())), "$SPX", 20);
    // var vRelStrInd = efs("\Wizards\PriceRelative.efs");
    // if(vRelStrInd == null) {vRelStrInd = efs("Wizard\\PriceRelative.efs", 0, sym(getSymbol()), "$SPX", 20);}
    if(vRelStrInd == null) {vRelStrInd = efs("Wizard\\PriceRelative.efs", 0, sym(getSymbol()));}
    if(vMACD == null) {vMACD = new macd(12, 26, 9, "Close");}

    debugPrintln("SDI_Alert_Test(" +getSymbol()+ ")=> vRelStrInd=" + vRelStrInd + ", vMACD=>"+vMACD);

    }
    =============================================



    File:PriceRelative.efs
    =============================================
    //
    // This formula was originally generated by the Alert Wizard
    //
    var vLastAlert = -1;

    function preMain() {
    var fp1 = new FunctionParameter("compareTo", FunctionParameter.STRING);
    fp1.setName("compareTo");
    fp1.addOption("$SPX");
    fp1.setDefault("$SPX"); //Edit this value to set a new default
    var fp2 = new FunctionParameter("MA_Periods", FunctionParameter.NUMBER);
    fp2.setLowerLimit(1);
    fp2.setDefault(20); //Edit this value to set a new default
    /**
    * This function is called only once, before any of the bars are loaded.
    * Place any study or EFS configuration commands here.
    */
    setPriceStudy(false);
    setStudyTitle("PriceRelative");
    setCursorLabelName("Strength", 0);
    setCursorLabelName("MA", 1);
    setDefaultBarStyle(PS_SOLID, 0);
    setDefaultBarStyle(PS_SOLID, 1);
    setDefaultBarFgColor(Color.red, 0);
    setDefaultBarFgColor(Color.green, 1);
    setDefaultBarThickness(2, 0);
    setDefaultBarThickness(2, 1);
    setPlotType(PLOTTYPE_LINE, 0);
    setPlotType(PLOTTYPE_LINE, 1);

    }

    function main(compareTo, MA_Periods) {
    var vCurridx = getCurrentBarIndex();
    var vMyClose = close(vCurridx);
    var vTRelClose = close(vCurridx, 1, sym(compareTo));
    debugPrintln(getSymbol()+".PriceRelative([" + vCurridx + "] compareTo="+compareTo+", MA_Periods="+ MA_Periods +"/"+compareTo+")=>" + vMyCurrVal + "/"+vMAret+", vSum="+vSum+", nLength="+nLength+", vValue="+vValue);
    if(vTRelClose == 0.0)
    { return Array(null, null);}
    var vMAret = null;
    var vMyCurrVal = (vMyClose / vTRelClose);
    //if(vCurridx == 0) debugPrintln("PriceRelative(" + vCurridx + ","+getSymbol()+ "/"+compareTo+")=>" + vTRelClose + ", vMyClose="+vMyClose);
    /**
    * The main() function is called once per bar on all previous bars, once per
    * each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
    * in your preMain(), it is also called on every tick.
    */

    var vSum = 0.0;
    var vValue = null;
    var nLength = MA_Periods;
    debugPrintln("PriceRelative(" + vCurridx + ","+getSymbol()+ "/"+compareTo+")=>" + vMyCurrVal + "/"+vMAret+", vSum="+vSum+", nLength="+nLength+", vValue="+vValue);
    vValue = ref(-nLength, nLength);
    // vSum += vMyCurrVal;
    if(vValue != null && vValue.length >= nLength)
    {
    for(i = 0; i < nLength; i++)
    {
    if(vValue[i] != null)
    { vSum += vValue[i][0]; }
    else
    { break;}
    }
    if(i >= nLength)
    { vMAret = (vSum / MA_Periods);}
    }
    // debugPrintln("PriceRelative(" + vCurridx + ","+getSymbol()+ "/"+compareTo+")=>" + vMyCurrVal + "/"+vMAret+", vSum="+vSum+", nLength="+getNumBars());
    return Array(vMyCurrVal, vMAret);

    }

    function postMain() {
    /**
    * The postMain() function is called only once, when the EFS is no longer used for
    * the current symbol (ie, symbol change, chart closing, or application shutdown).
    */
    }

    =============================================

  • #2
    I guess I should have said what the params were...
    They should be :
    compareTo => "$SPX", MA_Periods => 20
    But what is passed is:
    compareTo => 39.35, MA_Periods => 39.35
    ( I guess some prices...)
    Thanks
    JR

    Comment


    • #3
      JR
      With regards to the PriceRelative.efs if I understand correctly what you are trying to do that would be to compute the ratio between two symbols (one being charted and one passed as a variable) and then to calculate a simple moving average of that ratio.
      If that is the case then you may want to take full advantage of the EFS2 syntax and functions and you could write the same efs as follows

      PHP Code:
      function preMain(){
          
      setPriceStudy(false);
          
      setStudyTitle("PriceRelative");
          
      setCursorLabelName("Strength"0);
          
      setCursorLabelName("MA"1);
          
      setDefaultBarStyle(PS_SOLID0);
          
      setDefaultBarStyle(PS_SOLID1);
          
      setDefaultBarFgColor(Color.red0);
          
      setDefaultBarFgColor(Color.green1);
          
      setDefaultBarThickness(20);
          
      setDefaultBarThickness(21);
          
          var 
      fp1 = new FunctionParameter("compareTo"FunctionParameter.STRING);
          
      fp1.addOption("$SPX");
          
      fp1.setDefault("$SPX");
          
          var 
      fp2 = new FunctionParameter("MA_Periods"FunctionParameter.NUMBER);
          
      fp2.setLowerLimit(1); 
          
      fp2.setDefault(20);
      }

      function 
      main(compareTo,MA_Periods){

          var 
      vMyCurrVal efsInternal("calcRelStrength",getSymbol(),compareTo);
          var 
      vMAret     sma(MA_Periods,vMyCurrVal);

          return new Array (
      vMyCurrVal,vMAret);
      }

      function 
      calcRelStrength(symbol1,symbol2){

          return 
      close(0,sym(symbol1))/close(0,sym(symbol2));

      As to the AlertTest.efs I am not sure as to what you are trying to accomplish since you mention back testing but have no strategy functions in the script. Anyhow with regards to the efs() function you need to pass both parameters not just the symbol.

      PHP Code:
      var vMACD null;
      var 
      vRelStrInd  null;

      function 
      preMain(){
          
      setPriceStudy(true);
      }


      function 
      main(){

          if(
      vRelStrInd == nullvRelStrInd efs("PriceRelative.efs"0"$SPX",20);
          if(
      vMACD == nullvMACD  macd(12269);

          
      debugPrintln("SDI_Alert_Test(" +getSymbol()+ ")=> vRelStrInd=" vRelStrInd.getValue(0) +
                      
      ", vMACD=>"+vMACD.getValue(0));

      Again though I am unclear as to what you are trying to do. Perhaps you may want to provide more details.
      Also when posting code please try to enclose the script with the [ php ] [/php ] or [ code ] [/code ] tags (without spaces in the tags) so that it is properly aligned.
      Alex

      Comment


      • #4
        Howdy...
        Thanks for relying.
        The new version of the price-relative seams to work just dandy.
        The problem with the study is still there.
        The parameters that reach the PriceRelative funtion is as follows:
        compareTo=39.9
        MA_Periods="$SPX"
        It seams as the parameters are shifted.
        the docs state:
        efs(pathToEFS,[,seriesIndex][,params...])
        If I take out the seriesIndex param, it seams to get the correct params.

        Now the Series (PriceRelative and MACD is null..
        Ideas ??
        Thanks
        JR

        Code:
        var vMACD = null;
        var vRelStrInd  = null;
        // ----------------------------
        function preMain()  {}
        // ----------------------------
        function main() 
        {
        //  if(vRelStrInd == null) {vRelStrInd = efs("Wizard\\PriceRelative.efs", 0, sym(getSymbol()), "$SPX", 20);}
            if(vRelStrInd == null) {vRelStrInd = efs("Wizard\\PriceRelative.efs", sym(getSymbol()), "$SPX", 20);}
            if(vMACD == null)      {vMACD      = new macd(12, 26, 9, "Close");}
        
        //    if( isPlayBackMode( $PLAYBACK getSymbol() ))
            if(Strategy != null)
            {
                
                if(!Strategy.isInTrade())
                {
                    if(currmacd[0] > currmacd[1])
                    {   Strategy.doLong("MACD&Rel$SPX", Strategy.Market, Strategy.THISBAR);
                    }
                }
            }
            else
            {
                if((currmacd[0] > currmacd[1]))
                {   Alert.addToList(getSymbol(), "MACD&Rel$SPX, Open Long", Color.black, Color.green);    }
            }
        }

        Comment


        • #5
          JR
          First of all you may want to go through my revision of the AlertTest.efs and review all the changes I made to both the efs() and macd() functions.
          With regards to the efs() function what the docs state is correct ie efs("path to efs", seriesindex [,parameters,...]). Note that seriesindex is not an optional parameter and is required even if the called efs returns one item only. That aside in your case you are trying to pass 3 parameters ie getSymbol(), "$SPX" and 20 while the efs you are calling is set up only for two variables ie compareTo and MA_Periods.
          In addition there are various other errors in your script such as variables not being declared and the use of [0] and [1] to retrieve current or prior values. For those you should use the syntax I included in my revision of
          AlertTest.efs.
          With regards to the strategy I would suggest that before proceeding with this efs you go through the Guide to Developing eSignal Strategies. You may also want to read through the other Help Guides available in the EFS KnowledgeBase
          Alex

          Comment


          • #6
            Hi..
            OK, I'll go through it ...
            But, I can't find it, where should I look ??.

            You're right, I did pass too many Vars, didn't I....

            The script was incomplete to save on space, I guess I axed too much.
            The source of my problem was that I keep getting nulls for the MACD and PriceRelative studies
            var currmacd = vMACD.ref();
            var currRelStr = vRelStrInd.ref();

            Where:
            currmacd[0] = MACD
            currmacd[1] = MACDSig
            Right ??
            JR

            Comment


            • #7
              JR

              But, I can't find it, where should I look ??

              If you go through my prior reply you will see that I provided the links to the Guide and to the KnowledgeBase.

              var currmacd = vMACD.ref();
              var currRelStr = vRelStrInd.ref();


              I am not sure I understand why you insist on wanting to use the ref() function.
              If you look at my revision of AlertTest.efs you will see that I use macd.getValue(0) and vRelStrInd.getValue(0) to retrieve the current values of macd and vRelStrInd. If you run that version of the efs you will also see that you will not get any nulls in the Formula Output Window

              Where:
              currmacd[0] = MACD
              currmacd[1] = MACDSig
              Right ??


              That is not correct. For the syntax of macd see this article in the EFS2 Function Reference of the EFS KnowledgeBase
              Alex

              Comment

              Working...
              X