EMA System with Exit on Close
Author: rap555
Creation Date: 12/29/2008 1:40 PM
profile picture

rap555

#1
Newbie trying to set up an automated system using New Strategy from Rules and having a challenge. System is: trading on an EMA 16/34 crossover on a 15 minute chart. However, I want to close out the position at end of day. I have no difficulty with the entry position but when I try and set the exit using Sell at Close it assumes the current 15 minute bar, not EOD. Fidelity advises they don't know how to combine different time frames (i.e., 15 minutes and daily). Is this possible and can it be done using rules or does code need to be written? If code, then I'm lost cause I don't have that knowledge.

Any help would be most appreciated.
profile picture

Eugene

#2
Not everything can be implemented using the built-in rules, and you picked a good example. This WL5 Wiki KB article will illustrates how a similar task can be done in code:

Intraday / Multi-Time Frame | Mixing intraday and daily data
profile picture

Eugene

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

rap555

#4
Thanks Eugene! What's the best resource to learn to write and understand code? Is there anything on the WL site?
profile picture

Eugene

#5
There are numerous free web resources, books, online classes and so on. By learning a .NET language, preferably C# (the language that Strategy Editor speaks), you will know how to code in Wealth-Lab.

For instance, a selected number of comprehensive online resources is linked in our WL5 Wiki FAQ:
How do I start with C# ?

After learning some basic concepts (because programming trading strategies in Wealth-Lab typically does not require more advanced stuff), you'll be able to make a good use of the WealthScript Programming (Language) Guide, QuickRef and the Wealth-Lab Wiki site which contains many solutions and examples.
profile picture

rap555

#6
Eugene - One last question. Began reading some of the sites you recommended but need to get some trades going (my learning curve for programming is going to be a long tme). What would be the addition to the script to add an "or" condition to the exit strategy as follows:

an intra-day stop loss of 3%.

I really appreciate your help.

profile picture

Eugene

#7
QUOTE:
an intra-day stop loss of 3%.

Change the appropriate section with this code snippet, where I also have included a check that prevents entry on the last bar of the day:
CODE:
Please log in to see this code.

QUOTE:
Began reading some of the sites you recommended but need to get some trades going (my learning curve for programming is going to be a long tme).

Then I'd suggest to pick the easiest book, something like "C# for Dummies". Anyway you won't need some obscure programming stuff but the language basics. You're welcome to ask your WealthScript/C# questions here.
profile picture

rap555

#8
Very helpful - thanks again!
profile picture

rap555

#9
Eugene - in reading through the WLP User Guide it state "AtClose Orders are not supported by the Orders tool". So does that mean my end of day Sell at Close parameter will not execute? If so, can I modify it to sell at a specific time for that day, such as 3:59:00 pm? If so, can you give me the language?

Thanks.
profile picture

BigReturns

#10
If it's the last bar of the market day, I would think a SellAtMarket would for most cases...

Also, in addition to rap's first question how would you approach selling a position at close at after the 2nd market day after purchasing?

-Kip
profile picture

Eugene

#11
QUOTE:
So does that mean my end of day Sell at Close parameter will not execute? If so, can I modify it to sell at a specific time for that day, such as 3:59:00 pm? If so, can you give me the language?

CODE:
Please log in to see this code.


QUOTE:
Also, in addition to rap's first question how would you approach selling a position at close at after the 2nd market day after purchasing?

Please see this KB article:
Closing Intraday Positions at End of Day
WealthScript Translator will turn the WL4 code to C# in a second, you'd only have to remove the PortfolioSynch line.
profile picture

Cone

#12
Rather than getting into the convoluted logic of that KB article, the following is probably sufficiently robust, though you'll have to change the MarketClose constant value for half days.

CODE:
Please log in to see this code.
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).