I apologise for duplicate entries, I used the incorrect heading for the previous question.
I am trying to implement a time stop that is based on performance. So that if a stock gets to 30 days for example and the performance is less than 5% return it will exit.
When I try and run this I have coded the following under an N-bar stop:
perf(close, 20) < 0.05
This however does not seem to be working even when I change the percentage. Is there a better way to code this sort of time based performance stop?
The trading system formula is evaluated to get signals. At that time, it doesn't know and cannot use variables such Number of bars held.
So using perf(close, 20) will always calculate the performance of the last 20 bars even the next day the stock was bought.
What you are trying to do require a money management script. Here is an example available in the sharing server that you can use and edit to meet your requirements.
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.