Signal to enter depending on how far from the high of the day the stock is
Author: traders
Creation Date: 6/24/2008 11:11 AM
profile picture

traders

#1
I am new to Wealth Lab, and I WILL do my work and read what I have to as I use the program, but I was wondering if someone could give me some "starting" help.

I am looking to run a strategy that is pretty simple, and I have it in Excel (and I have used TS too)...I wold like to know how to get a signal to buy (or short) depending on how far from the high of the day the stock is. And I want to be able to exit the trade the next morning...intraday.

So i have to figure out how to code a % from high and an intraday exit...

Any help is greatly appreciated...

Thanks!
profile picture

Eugene

#2
Some clarification needed:

how far from the high of the day the stock is.

From the high of which day? No one knows the HOD until the day's done, so I assume it's yesterday's high?

And I want to be able to exit the trade the next morning...intraday.

So your intention here is to exit at market on open (i.e. why are you stressing the word intraday)?
profile picture

traders

#3
I mean on the daily chart how far from the high the stock closes. It is for backtesting purposes only, so I don't need it to work on live current data.


Actually, I want to be able to exit the trade at a certain pre-determined time, i.e. 12PM.
And/or to have a stop.
profile picture

Eugene

#4
Now it's clear - you mean the distance off high at the close.

Your code still needs to operate on intraday data (not necessary live streaming) because it accesses intraday data.

Here's a quick demo that uses 15-minute bars and buys today at the close if it was 3% off the daily high. Exit is done at either 5% stop or at 12:00 tomorrow.

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

traders

#5
Thank you very much... I will try that out and see if I can get started that way!!!


Sam
profile picture

abwl

#6
Hi,

From the code above, I see that the GetTime method is call from the Execute() method. I would like to know how we can group these methods (e.g. GetTime ) into a common library or package so that I can call these modules from other strategies as well. (these would improve make the components more reuseable)

Please feel free to advice. thx !
profile picture

Eugene

#7
By the way, the work on a common library of reusable methods for Wealth-Lab 5 users has started:
Community.Components
Eventually it will be distributed via the new Extension Manager for all to benefit.

If you like to group your own methods, install Visual Studio Express or SharpDevelop (they're free), create a project and paste the functions into a class. After compiling and dropping the library to Wealth-Lab folder it becomes accessible just like other .NET assemblies.
profile picture

fesquet_g

#8
Hello,

Eugene, the code you give is in .NET and works for the WealthLab 5.1 version.
Where did you get this version? Because from the WealthLab website, I can't purchase it. I could only get a 30days trial version on the fidelity website...

Thank you for your help
profile picture

Eugene

#9
Please see Robert's (Cone) reply here:
Demo for 5.1 ?
Basically it will be available as soon as possible. Sorry for inconvenience.
profile picture

traders

#10
Eugene.

Thanks so much for your help, I have been able to really start using WL once I got the basic format that I needed.

I am having difficulty getting a system where I can have multiple exits...where you hold if it is a winner and put out a limit if it is a loser...I want both of them tied to time of day.
For instance, in this strategy, I am just selling the position at market at 12PM.
But how can I tell it to check on the open, if the position is a winner, then hold till 12. If it is a loser, then sell at breakeven limit (and THEN at a certain time if you don't get the limit)??

Also...I am trying to find a way to check relative volume in a strategy. I.E. only buy today if the close is less than X amount from high of day AND volume today is > avg. volume for the past 20 days.

Thanks so much!!!

CODE:
Please log in to see this code.

profile picture

Eugene

#11
QUOTE:
If it is a loser, then sell at breakeven limit (and THEN at a certain time if you don't get the limit)??


What if the position won't get to breakeven (that day or at all) at a certain time?

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

traders

#12
Eugene,

Thank you very much, this looks like it will get me on the way to multiple exits...



Sam
profile picture

traders

#13
Okay, thanks so much Eugene for all the help so far!!


I am having trouble with trying to set up a multiple exit. I want
to sell a postion at the end of the day, OR if it breaks hi/low for
the day after my entry. In this scenario, I am working on a 5 minute
chart and entering a position at 10:30 AM. Let us say a short position.
I want to exit that position at the end of the day OR if it breaks
the high for the day so far.

CODE:
Please log in to see this code.


(also, I don't know if there is a better way to tell it to short at 10:30 than the one I wrote (bar + 13).

This leads to another area I am trying to work on, is figuring out how to get the high/low for a certain amount
of time. I.E. buy when the stock breaks the high of the first hour etc.

Any help is greatly appreciated!!

Sam
profile picture

Eugene

#14
QUOTE:
(also, I don't know if there is a better way to tell it to short at 10:30 than the one I wrote (bar + 13).


Bar+value greater than 1 is not acceptable. In addition, hard-coding this way could result in an unwanted effect when a couple of bars are missed (no trading took place).

QUOTE:

This leads to another area I am trying to work on, is figuring out how to get the high/low for a certain amount
of time. I.E. buy when the stock breaks the high of the first hour etc.


Here's an example to illustrate entries when the closing price of a bar breaks the first half-hour high/low from above/below:

ID Breakout System

QUOTE:
I want to exit that position at the end of the day OR if it breaks the high for the day so far.


Please explicitly rephrase because it does not make any sense to me. You want to exit a position today @ the close if it didn't break today's high tomorrow? :-) These two events are not logically connected.
profile picture

traders

#15
QUOTE:
Bar+value greater than 1 is not acceptable. In addition, hard-coding this way could result in an unwanted effect when a couple of bars are missed (no trading took place).


So, how do I hard-code to buy at 1000 the NEXT day on an intraday chart, based on TODAYS close?

QUOTE:
Please explicitly rephrase because it does not make any sense to me. You want to exit a position today @ the close if it didn't break today's high tomorrow? :-) These two events are not logically connected.


If I am LONG at 50 at 1000 AM and the low for TODAY so far was 49, then I want to have a sellstop
order at 48.99 and an end of day exit if it does not hit the stop!

Thanks!
profile picture

Eugene

#16
QUOTE:
So, how do I hard-code to buy at 1000 the NEXT day on an intraday chart, based on TODAYS close?

+
QUOTE:
If I am LONG at 50 at 1000 AM and the low for TODAY so far was 49, then I want to have a sellstop
order at 48.99 and an end of day exit if it does not hit the stop!


Thanks, that makes it clear: sell tomorrow either at yesterday's daily low if broken down OR just bail out at the close.

Here's the code combining both your requests at once:

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

traders

#17
Actually, I am not looking for a sell tomorrow...because the ENTRY is first tomorrow.

I am buying TOMORROW at 1000AM based on how the stock closed today.
THEN I will hold until that days close. UNLESS the stocks breaks the FIRST 1/2 HOUR high or low
of the day of the entry.

So I need a way to code a stop based on the same days hi/lo AS OF the entry time.

Also, I get an error (which does NOT seem to affect the backtest) that says:

QUOTE:
Error processing symbol MOS Bar number must be 10495 or less


only when I backtest on a group. On an individual name it does not show up.


Thanks so much!!
profile picture

Eugene

#18
QUOTE:
Error processing symbol MOS Bar number must be 10495 or less

Try right-clicking the chart and selecting "Reload chart history".
What were the time frame and data range?

QUOTE:
UNLESS the stocks breaks the FIRST 1/2 HOUR high or low of the day of the entry.


How would I know that if what you were actually telling was a totally different thing:
QUOTE:
I want to exit that position at the end of the day OR if it breaks the high for the day so far.


Which to everyone looks like if you were trying to access the high of the day (undetermined until the market closes.)

So please itemize each of your rule unambiguously.
profile picture

traders

#19
QUOTE:
What were the time frame and data range?


The time frame was a 5 -minute chart and the data range was 1/1/2008 till today.



QUOTE:
How would I know that if what you were actually telling was a totally different thing:


I am sorry for the confusion.

Okay.
1) On January 2nd a stock closes 20% from its high for that day.
2) On January 3rd I want to BUY that stocks at 1000 AM.
3) The exit for the trade will be EITHER
a)The low of January 3rd from 930 AM until 1000 AM (the entry time) as a STOP(loss).
b)If no new low is made after 1000 AM then exit at the end of the day (1600 January 3rd).

Sorry again for the confusion!!

profile picture

Eugene

#20
Good, that makes it clear. The code below requires 30-minute bars for simplicity.

CODE:
Please log in to see this code.