ATR exit
Author: SimhaD04
Creation Date: 8/30/2012 3:58 PM
profile picture

SimhaD04

#1
Hi,

I had a working strategy with a fixed percent exit ("percloss") based on the entry price. I wanted to replace that with an exit based on the following two conditions:

Exit at market if:

1. The closing price falls below: entry price - ATR * ATRxEntry, where ATR is the aver. true range and ATRxEntry is the parameter to be specified in the program, e.g. 1.

OR

2. The closing price falls below: highest price over a 50 day period - ATR * ATRxTrail, where ATRxTrail is the parameter to be specified in the program, e.g. 1.

The code as shown below, is incorrect: it exits the next day after a position is established. One obvious error, which I am unsure how to fix is due to the function Highest.Series( High, 50 )[bar], which on entry looks back 50 days. In reality it should gradually build up to 50 starting from 0.

Here's the trading loop of the program:

CODE:
Please log in to see this code.


Questions:

Can you suggest a function instead of Highest.Series( High, 50 )[bar] to fix the problem?
What debugging tools can be used in WL-Pro? something like write/print would help.

Thanks.
profile picture

Eugene

#2
QUOTE:
What debugging tools can be used in WL-Pro? something like write/print would help.

Whatever facility .NET provides. Built-in PrintDebug method (see the QuickRef), MessageBox.Show, write to file or trace log, finally, there are two dedicated articles on debugging using an external IDE in the Knowledge Base (Wiki).
profile picture

Eugene

#3
CODE:
Please log in to see this code.
profile picture

SimhaD04

#4
thanks, Eugene!
profile picture

Eugene

#5
SimhaD04 writes:

A few days ago I posted a question/code (the post has been apparently removed), asking for suggestions on fixing the problem with my implementation of trailing exits. In response, Eugene posted the following code:

CODE:
Please log in to see this code.


The proposed solution is apparently incorrect in the same way as my original code: it continuously carries the trailing stop, so that when you buy on a dip, the code kicks you out the very next day on a trailing stop.

The correct solution would be to have trail initialized every time a new trade is entered and ATR period has to vary up until it gets to the specified "steady state" value. That is, if the specified ATR period is 10 days, upon entering a new trade ATR is reset to 0 and say, on day 3 after the ATR period has to be 2 days, on day 4 after - 3 days, till day 11 when it is set to its steady value, which stays constant until the position is closed.

Any suggestions as to how to code it will be appreciated.

Also, I am curious whether declaring the paramATRxTrail parameter as private has any significance in the above code.

Thanks.
profile picture

Eugene

#6
QUOTE:
A few days ago I posted a question/code (the post has been apparently removed),

"Bookmark this Topic" in "Topic Options" allows one to memorize and track threads of interest. Also, searching for your own username in Forum Search will get all threads where you posted.
profile picture

Eugene

#7
QUOTE:
The correct solution would be to have trail initialized every time a new trade is entered and ATR period has to vary up until it gets to the specified "steady state" value. That is, if the specified ATR period is 10 days, upon entering a new trade ATR is reset to 0 and say, on day 3 after the ATR period has to be 2 days, on day 4 after - 3 days, till day 11 when it is set to its steady value, which stays constant until the position is closed.

I don't think it's the correct solution, if you understand what the ATR is about. ATR period can't be reset to 0.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).