Buy when Open >= previous close and price exceeds the high of the 1st bar
Author: dwm
Creation Date: 3/17/2010 7:39 PM
profile picture

dwm

#1
Please help me to create a trade stratgy for wealth-lab pro 5 per the following conditions.

Buy:
If today's open is >= previous day's close.
then buy @ market, when price exceed's the high of the 1st 5min bar by $.05.

Sell @ market:
1. trailing stop of 2%.
or
2. after close of the 1st 5min bar, that closes below the 7ema.

Also would not want to begin any new positions/trades after 9:50 am

Any help in this would be appreciated. Thanks
profile picture

Eugene

#2
There you are:
CODE:
Please log in to see this code.


Also, take a look at this Wiki article:

System Building | Creating an Intraday trading strategy
profile picture

dwm

#3
Thanks Eugene, really apreciate any help. I'm pretty new to this programing language, it's completely different from the fortran/basic language that I learned in school, a long, long time ago.

1) I took what you did and tryed to reverse the logic for short sells and came up with the code listed below. Which seems to work somewhat, but doesn't calculate the trailing stop correctly. I'm not sure if I'm applying the MAEAsOfBar script correctly.

2) Also what code would satisfy the criteria that today's open is <= previous day's close. Not sure what script from your example was used to establish that today's open is >= previous day's close. On line 38, the condBuy of your example, what does the "Date[bar].Date == Date[firstBar].Date" signify?

3) Also, on the last line of code (your above example) "if( condBuy )" then "BuyAtMarket(bar + 1);" was changed to "BuyAtMarket(bar);", which seems to buy as the price is exceeding the high of the 1st 5min bar, instead of waiting until that current bar closes. Will this cause any problems?

Again, thanks for the help.


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

Cone

#4
dwm, please use the CODE button right about the edit box and paste your code between the Code tags when posting code (I just did it for you).

Re: Fortran, BASIC - I remember that too! Programming has come a long way since there ;)

QUOTE:
today's open is <= previous day's close
if (Open[bar] <= Close[bar - 1] )

QUOTE:
what does the "Date[bar].Date == Date[firstBar].Date" signify
firstBar is a variable that stores the first bar number of the current day. So it checks if the current bar's date is the same day as that of the firstBar (seems to me that that condition would always be true).

QUOTE:
instead of waiting until that current bar closes. Will this cause any problems?
It's like saying "I know the market went up today, so let's buy this morning!", i.e., that's peeking. ALL trading signals AtMarket, AtLimit, and AtStop should be executed on the next bar, i.e., bar + 1. This is how you trade in real life.
profile picture

Eugene

#5
QUOTE:
"BuyAtMarket(bar);"

Also, see this KB article: Bars, Loops, and Bar + 1
profile picture

Eugene

#6
QUOTE:
[QUOTE]today's open is <= previous day's close

if (Open[bar] <= Close[bar - 1] )[/QUOTE]
Good solution, perfectly valid for intraday data. However, firstBar is still required for comparing with the high/low of the first 5-minute bar (and for drawing that optional horizontal line).
QUOTE:
Which seems to work somewhat, but doesn't calculate the trailing stop correctly.

On the surface, the 2% trailing stop seems to be calculated and working correctly.