Strategy that relies on >1 studies

jibanes

Member
Joined
Jul 16, 2019
Posts
23
Likes
0
I would like to do a strategy that relies on a combination of studies.
You could see, for instance, that an entry (buy) would be triggered IF RSI<30 OR crosses the lower bollinger band.
Obviously I can't just call study.initialize() and study.calculateValues(); it's not that simple.
Do you know how to invoke a study (i.e. RSI) and retrieve the enumerated Values? (keep in mind that I can't just "extend" the RSI study, since I will have to call more than one).
 

Spin

Well-known member
Joined
May 22, 2019
Posts
477
Likes
191
I have done this a couple of times by storing values onto the DataSeries (in each of the separate Studies you need), and then have my Strategy's logic decide whether a signal BUY / SELL should be given or not.

I sort of outline that solution in this thread:

https://support.motivewave.com/forum/index.php?threads/how-can-i-plot-a-line-with-json.482/post-1825


I hope this helps to get you on your way :)

edit: you would add all the RSI and Bollinger values you intend to use to your DataSeries in a (slightly modified) version of those two Studies and have your Strategy look them up to check for signals.

edit2: more info on this in the MW SDK Manual (search for "Export Values", page 18 onwards): Programming Guide
 
Last edited:

jibanes

Member
Joined
Jul 16, 2019
Posts
23
Likes
0
Do you use reflection to make calculate/calculateValues public in the study that belongs to another class?
 
Last edited:

Spin

Well-known member
Joined
May 22, 2019
Posts
477
Likes
191
I'm afraid I am not entirely sure what you mean @jibanes :unsure:

I can tell you the 'CalculateValues' in my Study (that is used in cooperation with a Strategy) is "protected".

You do not need to set it to 'public' to be able to export Values, if that is what you mean
 

jibanes

Member
Joined
Jul 16, 2019
Posts
23
Likes
0
But here I wouldn't "extend" a particular Study.

I would have a "strategy" class that extends Study that leverages multiple outputs from multiple apps that itself extend Study and generate signals based on the outputted Values of said multiple studies.

So basically I can't simply call PriceChannel.calculate() AND TilsonIE2.calculate() from this strategy (even if I feed it the right values in series/ctx).

Unless perhaps you advise me to create intermediary classes that wrap around PriceChannel.calculate() AND TilsonIE2.calculate() ?

Let me know how you would do it.
 

Spin

Well-known member
Joined
May 22, 2019
Posts
477
Likes
191
I see.

How about you check for a set of conditions in one Study and write a Value of 1 to series when these conditions are met.
And check for a set of (different) conditions in the other Study and write a (differently named) Value of 1 as well to the series.

And have your Strategy check

Code:
if (Value1 + Value2 => 2)
{
    fire signal
}

Wouldn't that work ?
 

jibanes

Member
Joined
Jul 16, 2019
Posts
23
Likes
0
I don't think so, because the series is instantiated under a strategy class that doesn't extend to specific studies?
i.e.
the strategy class definition:
public class B031 extends Study {}

the studies it relies on to perform its analysis (for parameter optimization for instance), there could be (read: would be) more studies:
public class TilsonIE2 extends Study {} which has TilsonIE2.calculate()
public class PriceChannel extends Study {} which has PriceChannel.calculate()
 

Spin

Well-known member
Joined
May 22, 2019
Posts
477
Likes
191
You may be right :) Someone needs to test this (or post here if they have done so already :LOL:)

I now remember that I bumped into the same wall once, and simply merged the two Studies I needed into one 'meta-Study' that held all the Values I needed.

Your suggestion of working with intermediary classes could also work, but I think the 'meta-Study' will be easier to implement.
 
Top