I am currently attempting to code a monthly, single position strategy using Trailing Stops (10% loss) and Stops (1% loss) as sell conditions that are based on monthly closing prices. Could you please tell/show me how to modify the following code so that these sell conditions are based on end-of-month closing prices rather than the within month prices that are lower than the the closing price.
CODE:
Please log in to see this code.
Thank you for your help.
B. Blidner
Size:
Color:
First of all, please take a moment to go through this KB article:
Introductory | Bars, Loops, and Bar + 1The strategy is using "bar" for your exits while in reality you must to use "bar+1". It's like having found the high not valid until the bar closes (i.e. month ends), calculating the retracement for the trailing stop, and exiting at the beginning of the month based on what was happening throughout the month (i.e. impossible).
Size:
Color:
Understood - peeking is not good.
Please confirm that the following addresses your input. If so, please help with modifying the code to use end of month closing prices.
CODE:
Please log in to see this code.
Thanks again.
B. Blidner
Size:
Color:
Assuming you're running the strategy on Monthly data, a trailing stop (not necessarily
-loss) based on a 10% excursion from the highest close price would be:
CODE:
Please log in to see this code.
N/A to the stop since it's based on the entry price.
Size:
Color:
It appears that this code also triggers a "sell" when prices that occur during the month that are lower than the closing price for the month. Specifically, if a purchase is made at $40 and the closing price moves up to $50 over the next few months, then the Trailing Stop should be $45 using a 10% trailing stop loss. If the price of the stock the following month has a high of $51, a low of $44 and a close of $46, the stock should not be sold because it closed at $46 (an 8% excursion). The coding provided sells the stock at $45 because it hit this value within the month - this is what I've been trying to avoid.
Thanks,
B. Blidner
Size:
Color:
The code can't do that. Only the Close price is considered.
Have you replaced your code with this and compiled?
Size:
Color:
I replaced the code (as follows) and compiled it
CODE:
Please log in to see this code.
I'm still getting the same results - sell prices below the closing price
I have output charts for this code in both .pdf and .jpg format. Unfortunately, I can't figure out how to "paste" either of these images under the IMG function.
Have I installed the correct code??
B. Blidner
Size:
Color:
*TrailingStop will exit below the closing price by design - it's a stop order.
PDF, DOC are absolutely awful for taking screenshots, BMP and JPG are slightly better, PNG is ideal. Windows Paint is built in every copy of Windows (3.0 from 199x had it), and it supports saving to PNG. Probably like on any forum in existence, a direct image link uploaded to a free image hoster is placed in between the [IMG /IMG] tag. Free image hosting services like imageshack or tinypic can be found by using search engines.
Size:
Color:
Is there some other function or code that will enable selling only if the closing monthly price hits a negative 10% excursion from the highest monthly close?
B. Blidner
Size:
Color:
You wouldn't want to post a screenshot, but want another function?
Size:
Color:
I tried to post a screenshot to help explain the problem I was seeing, however, that is not the function that prompted my initial request for assistance.
I would like to code WLP with two sell functions based on monthly closing prices. The first sell function would trigger a sell signal if the monthly closing price falls 1% below the purchase price. The second sell function would trigger a sell signal if the monthly closing price falls 10% below the highest closing price in the months following the purchase. The code that I posted on 10/11/10 at 11:12 AM does not function as I intend as it triggers sells below monthly closing prices.
I have performed multiple backtest calculations by hand and am reasonably convinced that these sell conditions will improve my results when coupled with the buy conditions I am using. I would like to be able to backtest using WLP to more rigorously determine if my current impressions are correct. I would, therefore, greatly appreciate your help in identifying how two code these sell functions.
B. Blidner
Size:
Color:
OK if you refuse to show a proof that the code isn't working like you think it should, then I give up, good luck to you.
Size:
Color:
I'm not refusing to show proof - I just couldn't figure out how to post the screenshot and didn't think it was necessary. Getting a little help from friends, here's the screenshot you want:
I would really like your assistance to resolve the coding problem I'm having.
Thanks
B. Blidner
Size:
Color:
Thank you. As they say, a picture is worth a thousand words.
Let's take your 3rd trade marked as "NO", from June 2005.
Entry at close ~$24.56
Next highest close ~$24.88
10% excursion,
AtStop order = $22.39
So why "no"? The code is working exactly like it was designed. One thing that comes to mind is, maybe you didn't want a stop? i.e.
CODE:
Please log in to see this code.
Maybe your original intention was an AtClose order triggering only if this month's close is below the 10% from the highest close? Replaces the line of code above:
CODE:
Please log in to see this code.
But that's not a stop order. What if your intention was the following?
CODE:
Please log in to see this code.
Size:
Color:
My sell intentions are 1) an AtClose order triggered only if this month's close is below the 10% from the highest close (as you've indicated above) and 2) an AtClose order triggered only if this month's close is 1% below the entry price.
Sticking with intention #1 for now, here's the code I've tried and a link to a screenshot of the output I'm getting:
CODE:
Please log in to see this code.
[IMG]
http://yfrog.com/4wsphwith10tslmod2p
[/IMG]
Thanks for your continuing help.
B. Blidner
Size:
Color:
OOPS. Here's the link.
Size:
Color:
Oh my. The "
high" was overwritten with p.EntryPrice on each bar, causing trouble. Sorry about that.
CODE:
Please log in to see this code.
Size:
Color:
Perfect.
Thank you very, very much.
B. Blidner
Size:
Color: