Using Multi-Condition Group for consecutive condition "Volume above/below SMA"
Author: Investit
Creation Date: 6/4/2015 9:29 PM
profile picture

Investit

#1
On page 103 of the User Guide it states the following
QUOTE:
Consider the following image. The MC Group is AND'd with "Moving Average is trending
up" but OR'd with "Bullish Hammer" below. Within the MC Group of conditions, all 3
are Required Conditions to have occurred at least once during the specified 4-bar
Lookback Period. Consequently, the BuyAtMarket condition will trigger if ("Moving
Average is trending up" AND "MC Group") OR "Bullish Hammer".



I am trying to use the rule "Volume is<X% above SMA" for x=1% for 2 consecutive days. I put the rule in above the MC Group then to get the 2nd day I used the rule in the Multi-Condition Group and set look back to 2 and was not getting the desired results.

I noticed in the above that it states that the "conditions to have occurred at least once".

I don't want it for "at least once" I want it to occur for all (2) days.

What am I missing? I want to use this 2 day (or more) strategy with other conditions that don't have consecutive parameter.
Would you point me in the right direction?

Thanks
profile picture

Eugene

#2
Multi-Condition Groups are useful for introducing 'fuzzy logic' to your scripts like in the UG example: "conditions have occurred at least X times during the lookback period". This doesn't mean "to occur consecutively for all (X) days" but in some cases, they can be used to create a consecutive condition:

Can you do an "and then" command using rules?

Some conditions requiring consecutive action are already available in Rules:

* Price increases (decreases) a consecutive number of bars
* Indicator is above (below) a value for n consecutive bars
* Indicator is above (below) Indicator for n consecutive bars
* Indicator increases (decreases) a number of bars within period
* External Symbol Price increases (decreases) a consecutive number of bars
* External Symbol Moving Average increases (decreases) a consecutive number of bars
etc.

N Consecutive bars Rule: how to use Close price?

Now to your case. Unless I'm missing something, MC Groups don't seem directly applicable to your particular condition. It's easy to code in the script directly but not using available rules I guess. Here's an example of a 2-day (or more) consecutive staying of Volume below 50% of SMA(Volume):

CODE:
Please log in to see this code.


Anticipating your possible question, to avoid frgamentation of the rule system we do not have plans to include a consecutive condition for Volume SMA.
profile picture

Investit

#3
You anticipated my question --- it was worth a shot :)

I use to do some programming years ago but I am getting old an rusty and don't feel confident in working directly in the code. I do want to get into it sometime after I make some progress with using the rules. Do you have a beginners guide that you would recommend - i think if I get the basic structure down that it may come back quickly.

I appreciate the suggestions and links above -- it has given me some other ideas to try


Just to make sure that I didn't misrepresent and that I understand the logic -- Could my initial example above not work because I set the look back to 2 (thinking 2 consecutive days) vs 1 . This would depend on whether the definition of the MC look back set to 1 is equal to the current day or to the prior day?

If it is the current day then it will never work
If it is the prior day then would this work?

If I put "Volume is<X% above SMA" for x=1% above the MC it should find the first occurrence.
Then if I have "Volume is<X% above SMA" for x=1% below the MC and set look back to 1 it looks back one day and the condition is not true
However
If the next day meets the condition above the MC then the statement below the MC would be true for the prior day.
Therefore I would have the 2nd consecutive day of the condition occurring.


Does this sound right?
btw -thanks for your patience


profile picture

Eugene

#4
Multi Condition Groups are generally not meant for consecutive occurrences, rathe the opposite thing i.e. 'fuzzy logic'. A typical task is "find if all (or just some) required conditions have occurred at least once during a specified lookback period". The Rule Wizard is powerful but it has its limitations. Inevitably you encounter with the need to express your idea directly in code.

QUOTE:
Does this sound right?

I haven't tested it but sounds like your approach might work as it follows the design pattern in my reply. Initially I thought of it too, it's OK for 2 consecutive conditions but what happens when you need more - say for optimizing the variable? The resulting construct in Rules would become rather inelegant.

QUOTE:
Do you have a beginners guide that you would recommend - i think if I get the basic structure down that it may come back quickly.

Sure. I checked and the links in the FAQ are still live: How do I start with C# ? In particular, that C# Yellow Book 2010 now 2014.
profile picture

Investit

#5
Eugene
The MC approach does not seem to test out (and as you said limits the number of days) so I am trying an alternate to get two consecutive days where volume is above the SMA(30).

Using Indicator is above Indicator for n consecutive bars
Setting Indicator 1 to SMA(Volume,1)
Setting indicator 2 to SMA(Volume,30)
Number of bars n set to 2 (assume this is 2 days)

I used the stock AAPL to test (Daily scale for 2 years) and I do not get a consistent result showing a buy date for every 2 consecutive day period with the volume greater than the 30 day MA.
The date for some pairs are missed altogether and some instances it misses the 2 consecutive days and gives me the next day which may be lower than the SMA(30)

I also tried the same with the closing price with similar inconsistent results. (I eventually want the 2 high volume days ties to 2 positive price days)

I assume that the buy date that shows would be the date for the second of the 2 consecutive days.

What am I missing?

Thanks
profile picture

Eugene

#6
QUOTE:
I assume that the buy date that shows would be the date for the second of the 2 consecutive days.

Assumption is correct only if you used BuyAtClose (that does not produce Alerts). For other entry types, the buy date is the next bar (on which the condition may become false).
profile picture

Investit

#7
Thanks - that makes sense and could explains some of the seemingly inconsistent data that I was getting since I was using Buy at Market
profile picture

Eugene

#8
To anybody interested in MC Groups. Check out our tutorial video on Youtube:

Wealth-Lab 101: Strategy Builder Multi-Condition Groups
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).