Announcement

Collapse
No announcement yet.

Backtesting problems

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

  • Backtesting problems

    The attached file has several problems I can not solve. Lots of debug points are set.
    I am trying to put some registers on the screen to run "backtesting like" values in real time on a complex chart with a simple strategy. But, not of my drawText (near bottom of Main) commands seem to put anything on the screen, even though the debugger shows actaual values for those variables as the program runs.
    Worst, after careful examination of the debug run in Formula Output Window, I noted that the "Short Trades" were accurate, but the "Long Trades" were accurate in absolute value, but never recorded a correct "minus" sign, when the long trade lost money.
    So, I cannot seem to "subtract" correctly.
    Also, I tried hard to figure out how to place all the on chart text "RELATIVETOBOTTOM", rather than relative to the cursor. but could not find sufficient documentation. The EFS Functions Library talks aboutthe cx, and cy options, but does not give a good example for RELATIVETOBOTTOM. SO, I need help there, or a good example.
    I can not seem to get cumulator variables to work either. There is a variable , nTotalDayPOints, that is supposed to simply add up the "nNetPoints" made on each trade, as the day goes along. But, it does not seem to "add". Just stays at zero.
    Am I missing something here, or do regular arithmetic and variable assignment operators simply not work, while in "backtesting" or a strategy mode" Do, I need to strip all the "stategy commands" out of this program, in order for it to function normally, or have I just made an unusually large naumber of simple programming errors.
    Would appreciate it if you would take a look. I hate having to send all these lengthy emails, when a good old fashioned phone call to tech support would have gotten me on my way two days ago, but this is how it is done these days. I am a trader, not a programmer, trying my best to made a few simple things work right.
    Will appreciate any help.
    See attached file.
    thx,
    Tilmon
    Attached Files

  • #2
    Re: Backtesting problems

    Originally posted by tilmon
    The attached file has several problems I can not solve. Lots of debug points are set.
    I am trying to put some registers on the screen to run "backtesting like" values in real time on a complex chart with a simple strategy. But, not of my drawText (near bottom of Main) commands seem to put anything on the screen, even though the debugger shows actaual values for those variables as the program runs.
    Worst, after careful examination of the debug run in Formula Output Window, I noted that the "Short Trades" were accurate, but the "Long Trades" were accurate in absolute value, but never recorded a correct "minus" sign, when the long trade lost money.
    So, I cannot seem to "subtract" correctly.
    Also, I tried hard to figure out how to place all the on chart text "RELATIVETOBOTTOM", rather than relative to the cursor. but could not find sufficient documentation. The EFS Functions Library talks aboutthe cx, and cy options, but does not give a good example for RELATIVETOBOTTOM. SO, I need help there, or a good example.
    I can not seem to get cumulator variables to work either. There is a variable , nTotalDayPOints, that is supposed to simply add up the "nNetPoints" made on each trade, as the day goes along. But, it does not seem to "add". Just stays at zero.
    Am I missing something here, or do regular arithmetic and variable assignment operators simply not work, while in "backtesting" or a strategy mode" Do, I need to strip all the "stategy commands" out of this program, in order for it to function normally, or have I just made an unusually large naumber of simple programming errors.
    Would appreciate it if you would take a look. I hate having to send all these lengthy emails, when a good old fashioned phone call to tech support would have gotten me on my way two days ago, but this is how it is done these days. I am a trader, not a programmer, trying my best to made a few simple things work right.
    Will appreciate any help.
    See attached file.
    thx,
    Tilmon
    I'm not a programmer either and hardly an expert but I will offer a few suggestions and share my experience in the hope you will find it useful in someway:

    As far as know, the strategy object, or backtester will not function in realtime. It is designed to be run on completed bars only and will not work intrabar in realtime.

    If you want to use the same EFS strategy for both backtesting and realtime, it is possible, but you need to determine in your code if you are running a backtest then execute the Strategy.xxx method, if realtime, then you have to keep track of a positions status via your own variables myPosition = 0,1,-1 or someother convention.



    Another suggestion is have is to take a look at the new backtesting tutorials. There are some excellent examples that have been designed and tested to simulate as much as possible real trading.

    The "PROFIT TARGET" template that you are using is actually several years old, and has been replaced by several sample strategies written by JasonK documented thoroughly in the Backtesting turorials which can be found there or in his fileshare.
    It is of course possible to have the template you are using produce reasonable backtesting but I actually found it more effective to use the newer templates.

    For example, you are executing a limit order to exit a position based on an EOD condition using a limit price of the close 3 bars prior close(-3). The backtester alone has no way of knowing if this price was achievable but will assume you do, and will record the price as the trade price regardless of whether it is realiztic or not.

    Without using the newer techniques elaborated on by Jason in the tutorials, where a bar range is checked first, your results will not be nearly as realistic.

    There are also other issues, MARKET-THISBAR will also give you MARKET-OPEN and depending on your conditional can also grossly inflate you profitabiltiy when backtest when entry is based on barindex(0).

    As a trader, trust me I'm feeling you pain and frustration...bigtime.....Once you get a realiable backtesting template up and running, and are confident that at least on a bar closing basis you have something worth trading and you want to validate realtime...

    You can then, replace all the strategy.xxx methods, with the Generic Broker Functions....and then run it realtime sending trades to the Esignal Paper Broker.....and/or use the tick replay facility to also send the trades to the Esignal Paper Broker....
    it will accurate calcaulate your P&L.

    Or you can just trade it realtime in a live account (been there done that.....won't do it again....)..

    Unless you are a programming wizard, to calcualte P&L on the fly realtime is very error prone, time consuming, and not really necessary IMHO...

    This may not be the response you are looking for and maybe someone else can fix up a few bugs in your code and get it up and running......but I hope it helps..

    glen
    Glen Demarco
    [email protected]

    Comment


    • #3
      Tilmon

      ...I noted that the "Short Trades" were accurate, but the "Long Trades" were accurate in absolute value, but never recorded a correct "minus" sign, when the long trade lost money.
      So, I cannot seem to "subtract" correctly.
      There are two errors that I can see. The first one is that in lines 110-115 and also at every instance in main where you assign a value to nShortEntryPrice, nShortExitPrice, nLongEntryPrice, nLongExitPrice and nNetPoints you are declaring those variables locally even though they have already been declared globally. Delete lines 110-115 and remove the var from the other instances of those variables in main.
      The second is that in lines 169 and 367 you calculate nNetPoints by subtracting nLongExitPrice from nTradeEntryPrice. This will give you an inverted result ie a negative value on winning trades and a positive value on losing ones. Invert that equation and you should see the correct results.
      As a suggestion when using several debug statements you may want to include the lines in the script to which they correspond so as to it make it easier to reference them.
      Alex

      Comment


      • #4
        Thx to Alex re:backtesting problems

        Alex,
        I was able to use your suggestions regarding duplicate definition of global variables to clear up several problems. I also inverted the formula you highlighted, and that problem cleared up. I figured out how to draw "RELATIVETOBOTTOM" from an example in the EFS Library I found, and that entire script is now running. That's for the help.
        Also, thx to "Glen" for his comments. I shall be trying out those papertrading suggestions very soon.
        thx.
        Tilmon

        Comment


        • #5
          tilmon
          You are most welcome
          Alex

          Comment

          Working...
          X