Announcement

Collapse
No announcement yet.

Help with simple backtesting code

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

  • Help with simple backtesting code

    Can anyone please post the code for a simple backtesting strategy for buying when price closes above a moving average, and then reverses when it closes below a moving average? (to be more specific, I'm looking at displaced moving averages, like a 10 period moving average displaced 5 bars over.)

    (Not just painting the bars green or red, but the code to where I can produce the actual backtesting report.)

    I'm trying hard to understand how EFS works, but I just can't connect all the pieces together. I've read a huge portion of esignal central and I just can't find it. Maybe if I can see an entire code, then I can start to piece it together. I've read the beginner's guide to EFS, the backtesting help, the TS Support file, etc etc etc, and I just can't put all the pieces together.

    Much appreciated,
    thanks
    ehsuhuang

  • #2
    ehsuhuang

    The attached efs executes a strategy as per your specifications.
    It goes Long if the close is above the 10(5)MA and short if the close is below.
    Trades are executed at the open of the bar following the one that provides the signal.
    The bars are painted blue when the strategy is Long and red when Short.



    FYI I have elected to paint the first bar that closes above or below the MA in the same color of the prior trade so as to provide a fair graphical representation. For example you would still be short until a bar actually closes above the MA and only go Long at the bar following that hence the first bar closing above the MA is still red.

    The efs was created using only the Formula Wizard which can be used to view and/or edit it.

    Hope this helps

    Alex
    Attached Files

    Comment


    • #3
      Thanks - and another question

      Hi Alex,

      Thanks for the efs you posted. This helps a lot!
      If I wanted to use this to backtest the system, wouldn't I also need to enter commands to close out the present trade before reversing to the other direction?

      For example, would I need to add another set of criteria:

      If strategyislong = true
      AND
      Close < MA study

      THEN
      strategydosell


      (And then another set to correspond to closing out the short trades?)

      Is this correct?


      Many thanks for your prompt help!
      eugene

      Comment


      • #4
        Eugene
        If a Long or Short position is held calling the opposite strategy will close the open position and enter the new trade.
        The strategy I set up for you is ready to backtest as is.
        Alex

        Comment


        • #5
          Thanks Alex!

          eugene

          Comment

          Working...
          X