Enter positions on the same bar as exit: Moving Average Ribbon
Author: cll01
Creation Date: 3/5/2012 3:16 AM
profile picture

cll01

#1
I've got a Moving Average Ribbon strategy up and running, and would like new short(long) positions to be entered on the same date that I've got a long(short)exit. With the current setup the new position is entered the day after an old position is exited. My first guess was that going to File/Preferences/Slippage and setting Tick Slippage to 0 under "For Futures" would do the trick, but no. Any other suggestions?
profile picture

Eugene

#2
I do not even pretend to understand what Slippage (or Commission for that matter) may have to do with entering on the same date. :-)

Since you haven't specified whether your Strategy is rule- or code-based, see these answers from our Knowledge Base:

* Code-based: WealthScript Techniques | Creating a Stop-And-Reverse (SAR) system - for a design pattern that reverses into an opposite trade on the same bar
* Rule-based: How to create a stop-and-reverse system in a Rule-based Strategy?
profile picture

cll01

#3
I wouldn't bring commission into this discussion, but setting a trade entry on the day after an exit surely would account for some slippage if the closing price on day two could be regarded as the next tick compared to the closing price on day one. But of course this would only be the case if you don't have intraday prices and/or the open, high, and low. That's why I thought the File/Preferences/Tick Slippage could be a solution to the problem mentioned above.

In my case a trade signal is given when the price series crosses all defined Moving Averages: A long(short) position is exited and a short(long) position is entered.
This signal appears on the same day, so why is the entry for the new trade set for the next bar by default? (This is a Rule-Based / Drag+Drop designed strategy).
I'd gladly attach a screenshot of the rules if someone could give me a hint on how to do this. And yes, I've noticed the IMG button...

A suggested solution under "How to create a stop-and-reverse system in a Rule-based stratety" was to allow for Multiple open Positions under Position Management, but as mentioned this does not work well for strategies with multiple conditions. What happens for multiple conditions is that a new long(short) position is entered each and every day the price series is above(below) the averages. Though that sounds like a lot of fun, it's not what I'm looking for.

One of my last options seems to be the suggestion under "WealthScript Techniques | Creating a Stop-And-Reverse (SAR) system" that states that [...the very first trade should be processed individually by making a check for Positions.Count equal to zero.] Unfortunately I'm not sure how to do this although the code looks pretty simple. I've included it at the end of the post.

Being that script editing is the only solution to this problem I find it hard to understand why The Stop-And-Reverse option which existed in legacy versions of Wealth-Lab was removed for the purpose of simplification...

I'm grateful for any suggestions, and I hope you'll forgive me for the extreme length of this post.

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

Eugene

#4
How about this?
CODE:
Please log in to see this code.
profile picture

cll01

#5

Thank you for your very quick answer!

I ran the strategy, and trades are executed on the same bar as requested.
However, It seems to be a bit off compared to the script first posted.
For example, the very first trade is a short position.
This should not be exited before the price rises above all averages, but the trade is in fact exited as soon as the price is above the entry level (and still below all averages).
In addition, it seems that this strategy enters a short position when the price is above all averages, when in fact I would like the opposite to happen.
I'll gladly attach a screenshot as soon as I figure out how to do that...

I wish I could edit these things myself, but I'm afraid I'm going to need some time to get accustomed to c#.

If this is corrected, and there's a variable I can change in the code to include and adjust a trailing stop or fixed stop loss, this is pretty much all I need as a starting point to really get going.

Thank you for your help and patience!
profile picture

Eugene

#6
QUOTE:
In addition, it seems that this strategy enters a short position when the price is above all averages, when in fact I would like the opposite to happen.

Oops, that's a copy/paste error. See the revised code which should do the job.

P.S.
QUOTE:
For example, the very first trade is a short position.

Depends on the factors like data loading range and ultimately, which condition triggered first: long or short. No problem here.
QUOTE:
I'll gladly attach a screenshot as soon as I figure out how to do that...

See your open ticket for a how-to.
profile picture

cll01

#7

Just what I was looking for, and more!
I love the way you've included scrollbars that enables a quick change of the parameters.
Is it possible to include the following in the same manner:
1. scrollbar for sizing a stop-loss and/or trailing stop.
2. scrollbar for sizing profit taking.
3. scrollbar for sizing days between entry and exit?

I know that an implementation of these things may be a lot more complex than I'm able to understand, but it certainly looked like a breeze the way you did it.
If you're able to include these things, it will probably keep me so busy that I'll stay away from the forum for a while =)

And yes, by now I'm gladly going for a full purchase of your software!

Thank you!

profile picture

Eugene

#8
Sure it's possible. Here you go:
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).