Help with Day Trading Strategy
Author: NewDayTrader
Creation Date: 5/11/2010 12:47 PM
profile picture

NewDayTrader

#1
Please help me with the following Wealth-Lab Pro 5 strategy:

Buy at Market

If DI+ crosses DI-
followed by ADX crossing above 20

Then if price within 2% of high for the day

Sell at Market **I don't want to receive any sell signals**

Stop Loss at 20%
profile picture

Eugene

#2
The requirements are not clear.
QUOTE:
Buy at Market

How many positions?
QUOTE:
If DI+ crosses DI-

Crosses above? Below?
QUOTE:
followed by ADX crossing above 20

Followed when? On next intraday bar? or today? or...? When to invalidate the setup?
profile picture

NewDayTrader

#3
CONDITIONS: (If the price is within 2% of the day's high) AND (if DI+ crosses DI- followed by ADX crossing ABOVE 20 within 30 minutes), then receive a buy alert (buy position at market?).

I anticipate needing to adjust how close the price is to the daily high and the timeframe.

I will supply Wealth-Lab Pro (WLP) with a list of stocks for daytrading. I only wish to receive alerts to buy because I will manage all trades manually through Active Trader Pro. I do want alerts for each stock listed each time the above condition is met, but I hope to avoid coding for multiple positions if possible.

I don't need WLP to generate a sell signal, and I would like to avoid receiving any sell alerts from WLP (sell position at market if stop loss exceeds 20%?).

Hopefully, my idea is clearer now. Please let me know if any more clarifications are needed. Thank you.
profile picture

Eugene

#4
QUOTE:
AND (if DI+ crosses DI-

Still, clarification is required if DI+ crosses above DI- or below. Depending on your preference, just comment/uncomment CrossOver/CrossUnder.
QUOTE:
I do want alerts for each stock listed each time the above condition is met, but I hope to avoid coding for multiple positions if possible.

These are contradicting statements. New signal = new alert = new position.
QUOTE:
I don't need WLP to generate a sell signal, and I would like to avoid receiving any sell alerts from WLP (sell position at market if stop loss exceeds 20%?).

In this case, it's enough not to program any exit signal at all.

Also, I'll assume that you're looking to cancel the setup if day is done.
CODE:
Please log in to see this code.
profile picture

NewDayTrader

#5
Thanks for your help Eugene.

I've found that I need an additional condition to DI+ crossing above DI-. The code needs to check that "DI+ > DI-"; otherwise, I receive an alert even when "DI- > DI+" if the "DI+ > DI-" condition was met sometime during the preceding 30 minutes. I made several attempts to code this condition with the following item being the last one I tried based upon an example in the Wealth-Lab Wealthscript Programming Guide. (I received several error messages about invalid arguments and conversions.)

CODE:
Please log in to see this code.


I have the code below with the comment underlined where this condition needs to be placed.

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

Eugene

#6
QUOTE:
The code needs to check that "DI+ > DI-"; otherwise, I receive an alert even when "DI- > DI+" if the "DI+ > DI-" condition was met sometime during the preceding 30 minutes.

This was your design. I asked and your reply was: "within 30 minutes". The code is programmed exactly per this specification:
QUOTE:
(if DI+ crosses DI- followed by ADX crossing ABOVE 20 within 30 minutes)


Additional condition like that will not make any sense in this context, as it would make easier to program the code from scratch - without the "setup" logic required to make this "within 30 minutes" possible.

So, if you need both conditions active on the same bar, eliminate the setup logic and make your entry plain simple like this:
CODE:
Please log in to see this code.


P.S. I didn't ask what timeframe you're using. Is it 30-minute?
profile picture

NewDayTrader

#7
QUOTE:
Additional condition like that will not make any sense in this context, as it would make easier to program the code from scratch - without the "setup" logic required to make this "within 30 minutes" possible.

So, if you need both conditions active on the same bar, eliminate the setup logic and make your entry plain simple like this:


CODE:
Please log in to see this code.


In this modified section of code, it seems to me that both (DI+ crossing above DI-) AND (ADX crossing above 20) must occur during the same bar to trigger a buy. Is this true? For my particular trading signal, I need for (1) (DI+ to cross above DI-), then for (2) (ADX to cross above 20) within a specified time from the occurence of (1)--probably within 5-30 minutes. Certainly if (2) is met 30 minutes or more after (1) occurs, a buy alert should NOT be given. However, as the code was previously written, if (3)DI- crossed above DI+, and then (4)(ADX crossed above 20), I would receive 2 buy alerts: one after (2) was completed during a price increase and the other after (4) was completed during a price decrease assuming that (4) occurred within 30 minutes of (2) occurring.

QUOTE:
P.S. I didn't ask what timeframe you're using. Is it 30-minute?


Yes, I'll be using 1-minute bars so my original timeframe is 30 minutes. I imagine the timeframe will need to be shortened to work correctly.
profile picture

Eugene

#8
Next time, please use the QUOTE and CODE tags that you can see on top of the new post box, to tell quoted text from your words. Like this:
QUOTE:
For my particular trading signal, I need for (1) DI+ to cross above DI-, then for (2) ADX to cross above 20 in this order

This is exactly what my code is doing (tested on 5-minute bar scale).
profile picture

NewDayTrader

#9
Sorry Eugene, it appears that I was modifying my last entry while you were replying. (I didn't think you would still be working at this time of night. Guess I'm not the only one online here!) So even if your code does require condition 1 to be met and for condition 2 to be met sometime later, I still need to specify a timeframe. If condition 2 takes place too long after condition 1 is met, it's no longer a valid buy signal.

Thanks,
Mike
profile picture

Eugene

#10
Certainly you're not the only one online, 'cause it's noon here in Europe ;)
QUOTE:
Certainly if (2) is met 30 minutes or more after (1) occurs, a buy alert should NOT be given.

You're right, but one exception - repeated crossing of DI+ over DI- will make the setup start again. This is why it's possible to see a signal more than 30 minute later, and this is not a mistake - it just wasn't in your programming specification.

Let's then try this code that would reset the setup each time there's secondary DI+/DI- crossover:
CODE:
Please log in to see this code.
profile picture

NewDayTrader

#11
Thanks for the code Eugene especially the reset for DI+ crossing DI-. Here's my attempt to write the code for short selling; however, it fails to trigger properly. Can you help me find my error(s)?

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

Eugene

#12
We can't know what's properly for shorts since no requirements were expressed before, but for starters, there's difference between CrossOver and CrossUnder (QuickRef for more).
profile picture

NewDayTrader

#13
For shortselling, I would like the code to trigger if (1) the price is within 20% of the low--I will change the percentage later, (2)then (DI- crosses above DI+), followed by (3) (ADX crossing above 20) within 30 minutes of the occurence of (2).

I loaded data for many different stocks and found that the code fails to trigger any trades on the first day. (Yes, I found many times when a short sell should have triggered.) The code also failed to work for any of the stocks today when I ran it in the strategy monitor.
profile picture

Eugene

#14
On the surface, code looks fine. Not sure if you forgot to invert this leftover of the long version?
CODE:
Please log in to see this code.
profile picture

NewDayTrader

#15
This is your original code from the long version.

CODE:
Please log in to see this code.


I had to change the last condition from the original code you gave me to trigger the false setup properly in the long version.

CODE:
Please log in to see this code.

So I think this part of the code is OK in the short version.

Also, please see my previous post. I think the short code fails for the first day only. Am I improperly seeding an initial value or something similar?
profile picture

Eugene

#16
QUOTE:
So I think this part of the code is OK in the short version.

Right, this is what I was pointing out.
QUOTE:
Also, please see my previous post. I think the short code fails for the first day only. Am I improperly seeding an initial value or something similar?

To me it looks OK. If you think there's a problem, please describe what does "fails" mean, the symbol, the time frame, and data range.
profile picture

NewDayTrader

#17
One data set I've examined is SPY 1-minute 5/10/2010 to 5/14/2010.

For 5/10/2010, the conditions to trigger a shortsell on the next bar were met for the following times but no signal is generated:

10:29,12:13,12:29,1:04,3:08


For days 5/11/2010 through 5/14/2010, it appears that the code generates shortsell signals at the expected times.

Thanks!

profile picture

Eugene

#18
Just load more data.
profile picture

NewDayTrader

#19
The problem with including the previous day's data is that the daily low may no longer be valid for the particular day I'm trading. For example, if the previous day's daily low is 100, but today's daily low is 103, then my daily low for trading is 100. I want to receive alerts based upon the value of 103. (My current requirement is for the price to be within 1.5% of the daily low.)
profile picture

Eugene

#20
Setup is reset each, so you can do to the dailyLow:
CODE:
Please log in to see this code.