I'm using the following script in the Simulator to buy ILF when its close> its sma(200)*1.035 and sell ILF when its close< its sma(200)*0.965. I want to short and cpver with ^GSPC in the opposite direction;i.e.; short ^GSPC when ILF is sold and cover when it is bought. The simulator is run from 3/1/2004 through 12/18/2010. I'm getting some strange short trades that are inconsistent with the logic of the script as I understand the logic. I expect long ILF trades followed by short ^GSPC trades, followed by long ILF trades, so on. I'm reproducing the script for you to test.
//
ilfp=ticker("ILF",close,LastDate);
brule=ilfp>sma(ilfp,200)*1.035;
srule=ilfp<sma(ilfp,200)*0.965;
//Long Rules
buy=brule and StringEqual(name(),"ilf");
sell=srule and StringEqual(name(),"ilf");
//Short Rules
short=srule and StringEqual(name(),"^GSPC");
cover=brule and StringEqual(name(),"^GSPC");
//
Your help in deciphering what is happening is appreciated.
The formula is working; here are my results: (I have used A instead of ILF)
Symbol Trade Entry Exit
A (open) Long 30/09/2010 00:00 09/12/2010 00:00
^GSPC Short 30/06/2010 00:00 29/09/2010 00:00
A Long 29/06/2009 00:00 01/07/2010 00:00
^GSPC Short 05/09/2008 00:00 26/06/2009 00:00
A Long 21/05/2008 00:00 08/09/2008 00:00
^GSPC Short 19/12/2007 00:00 20/05/2008 00:00
A Long 30/11/2007 00:00 20/12/2007 00:00
^GSPC Short 12/11/2007 00:00 29/11/2007 00:00
A Long 06/09/2007 00:00 13/11/2007 00:00
^GSPC Short 16/08/2007 00:00 05/09/2007 00:00
A Long 22/12/2006 00:00 17/08/2007 00:00
- Note that in the first line you should use "LastData" instead of "LastDate".
- In the symbols list, you should add ILF and ^GSPC.
- Please check that your trading system has no money management script that modifies the simulation logic.
Thanks. I tried it again, it worked correctly once and then it started to act strangely again with unexpected short trades as well as short trades that start one day too soon, see picture using url below. Also note 3 consecutive short trades: one on 5/10/2010, one on 5/19/2010, and the last on 5/21/2010. I have no MM script on this Simulation, and have selected ILF and ^gspc with start date as 3/1/2004.
There is a small optimization we have added in the previous version that caused this problem. The problem occurs only when using the "ticker" function with the simulator. We have already fixed this and the fix should be available in the next release.
In the meantime, you can create the same strategy using the MM:
Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.