Condition true today and yesterday
Author: soshaughnessey
Creation Date: 10/17/2015 2:30 PM
profile picture

soshaughnessey

#1
I am relatively new to WealthLab. I have it running with my basic strategy but I am missing one thing.

I have a series of conditions that trigger my sell. They are primarily EMA based. However, I don't want it to be too sensitive so I need the condition to be true in the current bar as well as the last bar.

Basically:
Today's Fast EMA is below Today's Slow EMA
AND
Yesterday's Fast EMA was below Yesterday's Slow EMA

I can't seem to make Multiconditional groups work for this but I might be doing something wrong. Any insight would be appreciated.

profile picture

Eugene

#2
Multi-Condition Groups just require a number of conditions to be met within a lookback period but do not necessarily discern the order of those conditions.

If you don't mind some coding then "Open code in new window" and add one extra code line like this:
CODE:
Please log in to see this code.

Assuming EOD data, the idea is that your yesterday's EMAs are referenced by "bar-1".


And if you'd like to keep it Rules-based then the following workaround should work:

1. If not already installed, download and install the Community Indicators extension and restart WLP
2. Add your EMA condition for today as usual
3. From "General indicators", add an extra "Indicator is below indicator". This will be for yesterday's EMA.
4. Now for Indicator1 aka yesterday's Fast EMA, select ShiftedMA and adjust its parameters: ChoiceOfMA.EMA, offset = 1, etc.
5. Repeat for yesterday's Slow EMA. The only parameter that differs in the EMA period.

Voila. The trick here is that the ShiftedMA was created specifically to offset popular MAs and thus facilitate the use of delays in rule-based Strategies.

profile picture

soshaughnessey

#3
Thank you. I think I understand this. I appreciate your help.
profile picture

soshaughnessey

#4
Any advice on how to get the second most recent Close price? The last Close is what is typically used but I want the close from the previous bar. As before, I would prefer to stay in the rules editor and not drop to code.
profile picture

Eugene

#5
Same approach as in my post #2.

To get the previous bar's close, choose ShiftedMA with 1-period SMA and offset = 2.
profile picture

soshaughnessey

#6
Eugene -

Thank you for your answer. It is very creative. I never would have come up with a 1 day moving average as a way to find yesterday's close! In fact, when I assumed that you misread my question and then I thought about it for a couple seconds. Thank you for being a great resource.
profile picture

Eugene

#7
Sean,

Glad to help.