Announcement

Collapse
No announcement yet.

Need help debugging a logic error.

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

  • Need help debugging a logic error.

    This EFS is part of a system I'm working and the purpose is to simply plot a trailing stop based on ATR.

    For the sake of simplicity this is a stripped down version of the code with alot of comments removed temporarily as I wanted to post this within the text of this post.(it's still too long)..this is a mangled version of some code provided graciously by Steve Hare to correct a indicator drifting problem. The error I'm having is unrelated to the code Steve provided.


    I'm having difficulty finding the logic error which is occurring where the value plots correctly for a period of time and then it basically plots off the scale incorrectly.

    Debugging is difficult enough when you can set breakpoints and use a debugger to display values, but I'm way over my head using debugprintln alone and would appreciate any help as I give up.
    Attached Files
    Last edited by demarcog; 10-23-2006, 11:11 AM.
    Glen Demarco
    [email protected]

  • #2
    demarcog
    I ran your script in real time on a 1 minute bar chart (both in Tick Replay and live) and as far as I can see it seems to be working correctly ie it is flipping the stop correctly and coloring both the bar and the plot accordingly.
    You may need to post some images that illustrate the problem you are seeing.
    Alex

    Comment


    • #3
      Alexis,


      Thanks very much for working on it, I was hoping you would have the time to take a look.

      I ran it on a 1 minute chart of the OIH and as you mentioned it does start out ok but then for some reason starts to plot incorrectly. Sorry for not mentioning that earlier.

      I will attach a screen shot with the incorrect values specified with this reply and then an earlier screen shot with the more correct looking plots with another reply as I can only attach one image per post.

      Thanks so much..
      Attached Files
      Last edited by demarcog; 10-23-2006, 02:14 PM.
      Glen Demarco
      [email protected]

      Comment


      • #4
        Alexis,

        Here is the image which appears to start out plotting correctly.

        I hope you can follow and apologize for the horrible code, this is actually part of a larger strategy that I'm testing realtime and alot of code and comments were removed as I was trying to keep it brief for simplicity and ...

        I'm also very hesistent to post complete strategies before I've actually traded them for some length of time to validate that the backtested results are accurate. I don't want anyone loosing money based on a quick backtest of something I post which can actually be highly inaccurate based on the coding logic. If I can PM you I'll send you the whole strategy with the settings and symbols etc, but until I'm sure of the validity of the results I don't want to post it pubicly.

        thanks again, I've been anxiously awaiting your most valued expertise as this bug is causing me alot of grief lately...
        Attached Files
        Last edited by demarcog; 10-23-2006, 02:27 PM.
        Glen Demarco
        [email protected]

        Comment


        • #5
          demarcog
          From what I see in your script the trailing stop (ie StopPriceR) will flip only in real time when the variables Realtime and loadFlag are both set to true
          Realtime is set to true on barIndex -1 by the conditions in lines 40-41 at which point the script calls the function driftcheck() This in turn will set loadFlag to true only on the last bar of the chart.
          Up to that point the sections of code in lines 47-53 and 56-63 which set the variable bias to 1 or -1 will not be evaluated since they require Realtime and loadFlag to be both true.
          So, while the script is loading the variable bias remains in its initial state of 1 and the trailing stop only adjusts its value based on a "long" trade ie upwards.
          In order for your study to adjust the stop price for both long and short conditions while it is loading, the logic that sets bias to +/- 1 needs to be allowed to occur also on historical bars. Currently, the logic for Realtime and loadFlag are preventing this from occurring.
          Having said this the script is working correctly in real time ie the stop switches once the bar closes above/below it and the bars and plot are painted accordingly.
          Alex

          Comment


          • #6
            Originally posted by Alexis C. Montenegro
            demarcog
            From what I see in your script the trailing stop (ie StopPriceR) will flip only in real time when the variables Realtime and loadFlag are both set to true
            Realtime is set to true on barIndex -1 by the conditions in lines 40-41 at which point the script calls the function driftcheck() This in turn will set loadFlag to true only on the last bar of the chart.
            Up to that point the sections of code in lines 47-53 and 56-63 which set the variable bias to 1 or -1 will not be evaluated since they require Realtime and loadFlag to be both true.
            So, while the script is loading the variable bias remains in its initial state of 1 and the trailing stop only adjusts its value based on a "long" trade ie upwards.
            In order for your study to adjust the stop price for both long and short conditions while it is loading, the logic that sets bias to +/- 1 needs to be allowed to occur also on historical bars. Currently, the logic for Realtime and loadFlag are preventing this from occurring.
            Having said this the script is working correctly in real time ie the stop switches once the bar closes above/below it and the bars and plot are painted accordingly.
            Alex
            Alex,

            Thanks very much for your help.

            I added the test for LoadFlag==true because without it when I loaded the study I was seeing a large number of trades being sent to the Paper Broker which I was trying to elimate from happening.

            The process of converting a strategy from invoking the strategy object to realtime using the generic broker in preparation for live trading is a little more challenging then I origionally anticipated.

            I'll have to think about this and try a few things to see if I can achieve the desired results, thanks again.
            Glen Demarco
            [email protected]

            Comment


            • #7
              demarcog,

              I cannot think of anything more than the recommendations I had posted in this thread http://forum.esignalcentral.com/show...283#post92283.

              Comment


              • #8
                Steve,

                OK I deleted my prior post asking for further suggestions based on your comments asking for help with my Renko drift.

                Maybe I missed something when I incorporated your code into my strategy.

                So basically you are saying that when you incorporate your code into a strategy on a given symbol say OIH, 5min .05 and run it realtime you are not seeing any drifting?

                That would be great news to me and I would love to see the EFS and try it myself...
                Last edited by demarcog; 10-27-2006, 09:06 PM.
                Glen Demarco
                [email protected]

                Comment

                Working...
                X