Announcement

Collapse
No announcement yet.

Why does plotted line end before last bar?

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

  • Why does plotted line end before last bar?

    See attachment for images

    Why does the plotted line goe to the last bar when output1=high(-1) but ends before the last bar when output1=low(-1) ?
    -----------------------------------------------
    setStudyTitle("forum question");
    var output1_dm2=null;
    var output1_dm1=null;
    var output1=null;
    function preMain()
    {setPriceStudy(true);}
    function main()
    {
    output1_dm2=output1_dm1;
    output1_dm1=output1;
    output1=high(-1); // this output1 value plots study line all the way to last bar
    //output1=low(-1); // this output1 value quits plotting 5 bars before last bar ????
    if(output1-output1_dm1>=0)
    {
    Strategy.doLong("long", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, output1);
    Strategy.doSell("long", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT,0);
    }
    else
    {
    Strategy.doShort("short", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, output1);
    Strategy.doCover("short", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
    }
    return output1;
    }
    Attached Files

  • #2
    Re: Why does plotted line end before last bar?

    jcm21,


    I ran the efs you posted and did not have any issues like you described on my end. See my screen-shots below your screen-shots in the image below.

    I enclosed a portion of your efs with a try/catch loop to capture any potential errors that may have been causing the lack of output. There were no issues identified using this on my end. The modification I made is included at the bottom of the image I attached.

    Try running this version of your code (I assume you had run the efs you posted as-is). If there are any errors that were not caught on your end resulting in the lack of output, this may help identify the problem.

    Hope this helps.


    Originally posted by jcm21
    See attachment for images

    Why does the plotted line goe to the last bar when output1=high(-1) but ends before the last bar when output1=low(-1) ?
    -----------------------------------------------
    setStudyTitle("forum question");
    var output1_dm2=null;
    var output1_dm1=null;
    var output1=null;
    function preMain()
    {setPriceStudy(true);}
    function main()
    {
    output1_dm2=output1_dm1;
    output1_dm1=output1;
    output1=high(-1); // this output1 value plots study line all the way to last bar
    //output1=low(-1); // this output1 value quits plotting 5 bars before last bar ????
    if(output1-output1_dm1>=0)
    {
    Strategy.doLong("long", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, output1);
    Strategy.doSell("long", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT,0);
    }
    else
    {
    Strategy.doShort("short", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, output1);
    Strategy.doCover("short", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
    }
    return output1;
    }

    Comment


    • #3
      Hi Steve,

      I have not changed any of the code throughout this discussion.

      I applied the formula to $INDU and results were same as yours [ie] line plots went to the last bar in both the cases of high(-1) and low(-1).

      I tried it again on my chart and got the same results again [ie] plotted line stops 5 bars before last bar when using low(-1).
      My chart is for the Forex pair EUROdollar-USdollar [EUR A0-FX] daily 66 bars. See new attachment in this reply for a full image of the chart.

      I will try your debugging coding suggestion and will then respond with results.

      I love this Forum. First one I have ever been on. You guys sure make life easier.
      Attached Files

      Comment


      • #4
        Hi jcm21,

        Good to hear you are enjoying the forum, I share your sentiments.

        It seems that entering and exiting positions on the same bar with your command constructs are at the root of your problem. The troubleshooting I performed showed several problems while the historical data was loading. In each case, there was no output to the chart. This is kind of hidden since the lack of output is somewhat hidden as the points before and after the lack of output are connected by straight lines. This is not the case if the errors occur in the last bars of the chart, thus explaining what you are seeing.


        While I believe eSignal will support same-bar entries and exits with the Strategy object, I am not sure your constructs are correct (see the debug output). btw, as far as I know, eSignal does not support simultaneous long and short positions in the Strategy Analyzer.

        FWIW, I attached the code I used to pinpoint the problems, along with some of the Debug Output. I hope you find it helpful.


        Originally posted by jcm21
        Hi Steve,

        I have not changed any of the code throughout this discussion.

        I applied the formula to $INDU and results were same as yours [ie] line plots went to the last bar in both the cases of high(-1) and low(-1).

        I tried it again on my chart and got the same results again [ie] plotted line stops 5 bars before last bar when using low(-1).
        My chart is for the Forex pair EUROdollar-USdollar [EUR A0-FX] daily 66 bars. See new attachment in this reply for a full image of the chart.

        I will try your debugging coding suggestion and will then respond with results.

        I love this Forum. First one I have ever been on. You guys sure make life easier.
        PHP Code:
        var counter=2;
        setStudyTitle("forum question");
        var 
        output1_dm2=null;
        var 
        output1_dm1=null;
        var 
        output1=null;
        function 
        preMain()
        {
        setPriceStudy(true);}
        function 
        main()
        {
         
        output1_dm2=output1_dm1;
         
        output1_dm1=output1;
         
        output1=high(-1); // this output1 value plots study line all the way to last bar
         
        output1=low(-1); // this output1 value quits plotting 5 bars before last bar ????
         
        if(getCurrentBarCount()!=counter){myError();}
         try{ 
          if(
        output1-output1_dm1>=0)
          {
           
        debugPrintln("18: doLong Condition, step 1, bar = "+getCurrentBarCount());
           
        Strategy.doLong("long"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, output1);
           
        debugPrintln("22: doLong Condition, step 2, bar = "+getCurrentBarCount());
           
        Strategy.doSell("long"Strategy.CLOSEStrategy.THISBARStrategy.DEFAULT,0);
           
        debugPrintln("22: doLong Condition, step 3, bar = "+getCurrentBarCount());
          }
          else
          {
           
        debugPrintln("26: else Condition, step 1, bar = "+getCurrentBarCount());
           
        Strategy.doShort("short"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, output1);
           
        debugPrintln("28: else Condition, step 2, bar = "+getCurrentBarCount());
           
        Strategy.doCover("short"Strategy.CLOSEStrategy.THISBARStrategy.DEFAULT,0);
           
        debugPrintln("30: else Condition, step 3, bar = "+getCurrentBarCount());
          }
         }
         catch(
        e){
          
        debugPrintln("34: error = "+e);
         }
         if(
        getBarState()==BARSTATE_NEWBAR){counter++;}
         
        debugPrintln("34: step before output statement, bar = "+getCurrentBarCount());
         return 
        output1;
        }

        function 
        myError(){
        debugPrintln("ERROR LAST BAR, CURRENT BAR = "+getCurrentBarCount()+", ERROR OCCURED ON BAR NUMBER "+counter);
        countergetCurrentBarCount();

        here is a sample of some of the Debug Output...

        34: step before output statement, bar = 278
        26: else Condition, step 1, bar = 279
        28: else Condition, step 2, bar = 279
        30: else Condition, step 3, bar = 279
        34: step before output statement, bar = 279
        26: else Condition, step 1, bar = 280
        28: else Condition, step 2, bar = 280
        30: else Condition, step 3, bar = 280
        34: step before output statement, bar = 280
        18: doLong Condition, step 1, bar = 281
        22: doLong Condition, step 2, bar = 281
        22: doLong Condition, step 3, bar = 281
        34: step before output statement, bar = 281
        18: doLong Condition, step 1, bar = 282
        22: doLong Condition, step 2, bar = 282
        ERROR LAST BAR, CURRENT BAR = 283, ERROR OCCURED ON BAR NUMBER 282
        18: doLong Condition, step 1, bar = 283
        22: doLong Condition, step 2, bar = 283
        ERROR LAST BAR, CURRENT BAR = 284, ERROR OCCURED ON BAR NUMBER 283
        18: doLong Condition, step 1, bar = 284
        22: doLong Condition, step 2, bar = 284
        ERROR LAST BAR, CURRENT BAR = 285, ERROR OCCURED ON BAR NUMBER 284
        18: doLong Condition, step 1, bar = 285
        22: doLong Condition, step 2, bar = 285

        Comment


        • #5
          Thanks - that was interesting

          Hi Steve,

          Sounds to me like everything works ok except sometimes the plot is missing a short segment in the last few days and I will just have to live with it. Trade history presented by the backtester, even on the final days, looks ok to me. So for now, unless I can be of use in any way I will drop this and move on. Like everyone else, I have a lot to do and a short time to do it.

          I wonder why it works for high(-1) and not low(-1)?

          Your in-depth help has been invaluable.

          Joe Miller

          Comment


          • #6
            Re: Thanks - that was interesting

            Hi Joe,

            You are most welcome for the help.

            As to why it works for high(-1) and not low(-1), it does not work without errors for either. I saw a similar number of errors for both, it only is readily visible (today) when run using your daily chart, and the low(-1) on the Forex pair EUROdollar-USdollar [EUR A0-FX] daily. Even though things may appear fine, these are actually serious errors where execution of main stops at the point of the error. If you had critical steps subsequent to the error, they would not be executed then. The main function is only executed again when it is called by the next bar or tick.

            I can only recommend that you understand the error such that you can prevent it later. I attached a text file showing the output of the efs run using both inputs.

            Good luck on your progress.



            Originally posted by jcm21
            Hi Steve,

            Sounds to me like everything works ok except sometimes the plot is missing a short segment in the last few days and I will just have to live with it. Trade history presented by the backtester, even on the final days, looks ok to me. So for now, unless I can be of use in any way I will drop this and move on. Like everyone else, I have a lot to do and a short time to do it.

            I wonder why it works for high(-1) and not low(-1)?

            Your in-depth help has been invaluable.

            Joe Miller

            Comment


            • #7
              Hi Steve,
              I will check my backtester trade history results against your text file output.
              I am seriously concerned because I was planning to constuct far more complicated if-then-else combinations.
              I now feel an intellectual obligation to alert the rest of the user community to this possible flaw (I mean really spread the word). Even if the program is overall a valuable useful tool, this is serious if backtester results are unreliable. This is now a high priority issue with me instead of "dropping this and moving on" as I previously said.
              Please let me know what you think. Am I over-reacting, etc? Give it to me straight between the eyes. You will be doing me no favor to pull any punches.
              Joe

              Comment


              • #8
                Please send me the formula

                Please send me the exact formula you used to generate the text file you created for your previous response. I could try to do that myself but it might take me forever to get everything right.

                What I want to do is check my Backtester trade results - especially for the bars indicated in your text file to be in possible error. Maybe the Backtester results are valid in this case. I think you said in a previous reply that sometimes the results could be valid, sometimes not [ie] "If you had critical steps subsequent to the error, they would not be executed then."

                It appears that there were 285 total bars in your test.

                Alex Montenegro [I think it was he] suggested using
                if(getBarState()==BARSTATE_NEWBAR) but I suspect that was only for other than daily bars?

                Comment


                • #9
                  Re: Please send me the formula

                  Hi Joe,

                  Not sure where to start, but there are some limitations on my availability with the new year.


                  Originally posted by jcm21
                  Please send me the exact formula you used to generate the text file you created for your previous response. I could try to do that myself but it might take me forever to get everything right.
                  I have already posted the formula in a previous post below. To grab this from the previous post, move your mouse over the the code and depress and hold down your left mouse key. Move it down and select the code steps, then once you have the code selected, right click the selection and left click the copy command to capture your selection to the clipboard. Once you have it on the clipboard, you can past it into the efs editor and save it as an efs file.

                  As for the text file, since the output goes to the debug window (I assume you know about this), it is available. Any output to the debug Window is saved in the C:\Program Files\eSignal folder in the formulaoutput.log file (Assuming you have the default configuration).



                  What I want to do is check my Backtester trade results - especially for the bars indicated in your text file to be in possible error. Maybe the Backtester results are valid in this case. I think you said in a previous reply that sometimes the results could be valid, sometimes not [ie] "If you had critical steps subsequent to the error, they would not be executed then."

                  It appears that there were 285 total bars in your test.

                  Alex Montenegro [I think it was he] suggested using
                  if(getBarState()==BARSTATE_NEWBAR) but I suspect that was only for other than daily bars?

                  ...

                  I am seriously concerned because I was planning to constuct far more complicated if-then-else combinations.
                  I now feel an intellectual obligation to alert the rest of the user community to this possible flaw (I mean really spread the word). Even if the program is overall a valuable useful tool, this is serious if backtester results are unreliable. This is now a high priority issue with me instead of "dropping this and moving on" as I previously said.
                  Please let me know what you think. Am I over-reacting, etc? Give it to me straight between the eyes. You will be doing me no favor to pull any punches.


                  I will have to beg off on this one, as I have other commitments. Perhaps someone else can step in here.

                  Comment


                  • #10
                    Thanks. I will keep you posted on results

                    Thanks Steve.
                    I will run with it. Will keep you posted on results.
                    Joe

                    Comment


                    • #11
                      jcm21
                      The errors you are seeing are due to a flaw in the logic that you are using to execute the trade entries.
                      When entering a trade you are using a limit order at the price of output1. However you are not checking if the bar that executes the trade is actually breaching the limit price with the result that some trades are invalid [on the long or short side depending on which line of code you are using to calculate output1] thereby causing the errors. Keep in mind that the formula engine and the Strategy Analyzer do not check for logic errors.
                      When you use stop or limit orders you need to enclose the strategy commands to enter or exit trades inside conditional statements that check if the bars that execute the trades actually breach the stop or limit prices. This way the commands to enter or exit the trades are executed only if the prices are valid. When they do not breach the stop or limit prices then you need to use some other valid price to execute your trades. Additionally the conditions to enter trades should also check that the strategy is not already long (or short) if you don't want to generate multiple entries in the same direction. As to the exit trades you should also add the conditions to check if you are in a long or short trade.
                      FWIW all this logic is explained in detail (together with examples) in the Back Testing Tutorials which are provided in the EFS KnowledgeBase and that I would suggest you review so as to acquire a better understanding of the Strategy Object and how to implement it correctly.
                      Alex


                      Originally posted by jcm21
                      Hi Steve,
                      I will check my backtester trade history results against your text file output.
                      I am seriously concerned because I was planning to constuct far more complicated if-then-else combinations.
                      I now feel an intellectual obligation to alert the rest of the user community to this possible flaw (I mean really spread the word). Even if the program is overall a valuable useful tool, this is serious if backtester results are unreliable. This is now a high priority issue with me instead of "dropping this and moving on" as I previously said.
                      Please let me know what you think. Am I over-reacting, etc? Give it to me straight between the eyes. You will be doing me no favor to pull any punches.
                      Joe

                      Comment


                      • #12
                        Thanks a lot Alex

                        Thanks a lot Alex. Great news to know my problems are generated by me and not the Backtester. I will work on this. Should keep me busy for a while. Happy New Year and all that jazz to you and Steve.

                        Comment


                        • #13
                          jcm21
                          You are most welcome
                          Alex


                          Originally posted by jcm21
                          Thanks a lot Alex. Great news to know my problems are generated by me and not the Backtester. I will work on this. Should keep me busy for a while. Happy New Year and all that jazz to you and Steve.

                          Comment


                          • #14
                            how to create debug file?

                            Please tell me how to create a file like the following which Steve created and pointed me to in a reply. The info does not appear in my formula output window or my formulaoutput.log file? I am trying to get the bar number info.

                            18: doLong Condition, step 1, bar = 2
                            22: doLong Condition, step 2, bar = 2
                            22: doLong Condition, step 3, bar = 2
                            34: step before output statement, bar = 2
                            18: doLong Condition, step 1, bar = 3
                            22: doLong Condition, step 2, bar = 3
                            ERROR LAST BAR, CURRENT BAR = 4, ERROR OCCURED ON BAR NUMBER 3
                            18: doLong Condition, step 1, bar = 4
                            22: doLong Condition, step 2, bar = 4
                            ERROR LAST BAR, CURRENT BAR = 5, ERROR OCCURED ON BAR NUMBER 4

                            Comment


                            • #15
                              Please ignore my previous post

                              Please ignore my previous post. I see where Steve did it in his script [eg] debugPrintln("18: doLong Condition, step 1, bar = "+getCurrentBarCount());

                              Comment

                              Working...
                              X