How do I change the code so this formula also includes short trades? What I would like is for a short position to be made when a long is closed and visa vera and then back test.
Please review the other code examples in the EFS Library - Back Testing category. The BtMovingAverage2.efs shows a simple example of how to incorporate short trades as well.
If you want to learn more about how to code back testing formulas, please review our Back Testing tutorials. These tutorials explain in detail how to code the basic back testing concepts. After studying these, try implementing some of your ideas. If you run into any problems, post your code along with details.
Jason K.
Project Manager eSignal - an Interactive Data company
Let me clarify - the code is written in such a way that when a candle closes above the MA, its candle open is the price being used. Same thing for the short. This is useless for backtesting.
It should be that the next candle open AFTER the candle which closed above the MA, is the open price used for entries and exits.
You are correct, nice catch. One solution is to change the fill bar constant, Strategy.THISBAR, in the .doLong() and .doShort() calls to Strategy.NEXTBAR.
The other alternative is to change the fill type constant, Strategy.MARKET, to Strategy.CLOSE. This will record the entry trades at the close of the current bar.
Jason K.
Project Manager eSignal - an Interactive Data company
Comment