Can someone please help me fix this problem?
I am trading the ASX, long, on daily bars.
I coded a strict ATR trailing stop (as the inbuilt ATR trailing exit is not strict, it can still trail down).
This works perfectly in a single chart however 'BarsSinceEntry' creates massive problems in portfolio backtester. It requires me to ensure the maxbarsback setting is as long as BarsSinceEntry, and therefore I cannot properly test the strategy over, for example 5 years, in portfolio backtester (because the maxbarsback setting needs to be set to the number of bars back that equals BarsSinceEntry).
Firstly, I have to guess what this maxbarsback/BarsSinceEntry figure might be (it could be 1000 days!). Secondly, if it is 1000 days, I cannot backtest the strategy 5 years back (ie ~1100 bars back) to see how robust it is, because this means you are only getting a portfolio backtest duration of 100 days which is almost pointless.
There must be another way to code a strict trailing exit without using the barssinceentry...?
Plllllleeaasse can someone help? Anything would be greatly appreciated.
Code: Select all
Input: TrailingATRs (4.5) ;
Input: ATRLength (10) ;
Var: ATRVal (0) ;
ATRVal = Highest (high, barssinceentry) - (AvgTrueRange(ATRLength) * TrailingATRs) ;
If MarketPosition = 1 Then Begin
If High [0] is < ATRval then
Sell ( "ATRtrail" ) next bar at ATRval stop;
End ;
Thank you in advance