Registered User Joined: 3/12/2007 Posts: 10
|
Is it possible to back test a strategy that uses averaging into a position such as the example below? Note that the entry and exit conditions (1 and 5) in the example may change.
1. Buy 10% of the position at the close today. This is triggered by an entry rule.
2. If closing price is lower than previous entry any day during the position then buy another 20%.
3. If closing price is lower than previous entry price any day during the position then buy another 30%.
4. If closing price is lower than previous entry price any day during the position then buy the last 60%
5. Exit entire position at the end of 7 days
Thanks,
Giovanni
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
It is not possible to do so using the current version of BackScanner as it has no money management features. The Equity Line represents a 100% investment of all of your resources divided evenly amongst all of your positions.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
Registered User Joined: 12/31/2005 Posts: 2,499
|
QUOTE (giomorales)
Is it possible to back test a strategy that uses averaging into a position such as the example below? Note that the entry and exit conditions (1 and 5) in the example may change.
1. Buy 10% of the position at the close today. This is triggered by an entry rule.
2. If closing price is lower than previous entry any day during the position then buy another 20%.
3. If closing price is lower than previous entry price any day during the position then buy another 30%.
4. If closing price is lower than previous entry price any day during the position then buy the last 60%
5. Exit entire position at the end of 7 days
Thanks,
Giovanni
Your percentages don't add up to 100%, Assuming 60% should be 40%
Here is a sketch of a home cooked approach not using the backscanner.
‘ the idea is to plot the equity curve of each symbol, the final value
‘ being the profit or loss of all trades for that symbol
‘ Create a custom indicator average of the plot to appreciate the
‘ overall performance of the approach.
‘
‘ two function are needed, left as an exercise ;--- )
‘
‘ computeProfit – used to determine the profit upon exit of trade
‘ based on the number of position taken.
‘ using
‘ exitprice, entries, entry count
‘
‘ computeGain – used to compute the open trade gain based on how many entries
‘ have been taken
‘ using
‘ todays close, entries, entry count
'
' note: By computing the gain the plot will reflect present value during open trades.
' Also computeGain and computeProfit will need to assume some dollar value to invest.
' The simple approach is just assume a fixed amount regardless of the ongoing performance
' For example total of $10,000 for each symbol, entries ($1,000, $2,000, $3,000, $4,000)
static tradeOpen as boolean
static profit as single
static entries(5) as single ' using entrties 1 - 4
static tradeDays as integer
dim exitPrice as single
dim gain as single
if isfirstbar
tradeOpen = false
profit = 0
entries(1) = 0
entries(2) = 0
entries(3) = 0
entries(4) = 0
nextPosition = 1
tradeDays = 0
end if
if intrade = False then
if entryCondition = true then
entries(nextPosition) = price.close
nextPosition += 1
end if
else
tradeDays += 1
if tradeDays = 7 then
'
' exit trade
'
exitPrice = price.close
tradeDays = 0
profit += computeProfiit(exitPrice,entries,nextPosition)
nextPosiition = 1
else
'
' in trade,
' check for adding to position
‘
if nextPosition < 5 and price.close < entries(nextPosition -1) then
‘
‘ It is not realistic to buy as close but for now do it
‘
entries(nextPosition) = price.close
nextposition += 1
end if
'
' compute position gain
‘
gain = computeGain(price.close,entries,nextPosition – 1)
end if
plot = profit + gain
|
Registered User Joined: 12/31/2005 Posts: 2,499
|
QUOTE (jas0501) [...
Oops, I forgot to manage the inTrade boolean....
...
...
if intrade = False then
if entryCondition = true then
entries(nextPosition) = price.close
nextPosition += 1
inTrade = True
end if
else
tradeDays += 1
if tradeDays = 7 then
'
' exit trade
'
exitPrice = price.close
tradeDays = 0
profit += computeProfiit(exitPrice,entries,nextPosition)
nextPosiition = 1
inTrade = false
...
...
...
|
Registered User Joined: 12/31/2005 Posts: 2,499
|
On sleeping on it I have a couple additional comments:
1. If used as a watchlist column '# Cumulative needs to be added since the indicator is plotting a result rerived from a static variable
2. Functions computeProfit and computeGain are really the same function, unless slippage and commission are included in the profit calculation
3. Setting gain to 0 at the top of the code might be prudent.
4. The entry condition is not provided. It could be a rule condition or whatever.
5. The code is untested and uncompiled but the concept works for calculating the equity curve per symbol for a strategy.
6. This is a simple money managment approach, unlimited funds and fixed trade size, Starting with a profit based on initial equity of $10,000 and using the profit value as a parameter to calculateProfit and calculateGain would permit compounding and drawdown.
If compounding is permitted, adding logic to limit the maximum trade size would avoid unrealistic returns based on unfillable trade sizes.
Drawdown would permit going bust during the test and not show when and if the stategy is viable under some market conditions.
7. Depending on the complexity of the chart, for large watchlist you might need to get a cup of coffee, or two, while it chugs along.
8. Making the number of entries into the position, currently 4, a userinput and adjusting the code would reveal if averaging down is a viable approach. As in
a. 1 entry at 100%
b. 2 entries at 33 and 67%
c. 3 enties at 17%, 33%, 50%
d. 4 entries at 10%, 20%, 30%, 40%
Adding entryCount as a parameter to calculateProfit and calulaterGain one could ignore the entry attempt when appropriate. My guess is that it typically doesn't pay to average down.
9. Making the timed exit, currenty 7 days, a user input would be another interesting dimention to study.
10. Enhancing the exit to include trailing stop based in the initial entry and profit target would be additional enhancements worth considering.
Note this whole idea is a home brew approach to backtesting via realcode that can be taken to overcome shotcomings of the backscanner. it is not a perfect solution but this model is another tool for experimenting and confirming or disputing various strategies and approaches.
|