Strategy/Backtest with proprietary Studies

eickeee

Member
Joined
Aug 26, 2022
Posts
9
Likes
2
Hey folks,

How can I access signals or exported data from proprietary studies (I do not have access to the org. source code to copy stuff arround) that are visible in the alert history or data windows generated in my own study/strategy to backtest or automate some execution behaviour that depends on those proprietary studies/signals?

As far as I understand the API documentation (and from the posts here), the normal way would be to extend from a Study and then override onSignal(). This does not work for me, because while I have the Jar file with class files to the mentioned studies, they are obfuscated and when trying to extend from them somehow the compiler does not seem to accept anything.

I tried to create a separate study/strategy, attached it to the same chart and hoped that the signals that appear in the alert window might appear in my onSignal() but unfortunately not. Furthermore when checking for exportedValues via RuntimeDescriptor, I unfortunately also do not get anything back.

Am I missing something or is the "signal, study, stragety" concept/design not made for my requirements - hence external signals can only be used for the alert window!? 🙈

Would there be any other create way to hook into the alert data or data from the data window somehow?

Thanks!

Cheers,
eickeee
 

Per

Active member
Joined
Jun 12, 2021
Posts
28
Likes
7
There is a post on here somewhere with source code for most of the signals etc that MW provides.
 

eickeee

Member
Joined
Aug 26, 2022
Posts
9
Likes
2
Hey @Per I think you misunderstood me. I have/use proprietary, not from MV studies that already create signals. Those I'd like to use in a strategy study to ease backtesting or even automate some execution and I wonder if and how this is possible.
 

Spin

Well-known member
Joined
May 22, 2019
Posts
480
Likes
192
You would need to custom-code that Strategy to react to said signals

e.g.:
  • Study checks conditions and realizes all of them are met for a BUY (could be anywhere in your Study, I mostly put this in a different 'checkSignals'-method)
  • Study sends a Signal (it actually sends it to the DataContext from the chart it's on)
    Java:
    ctx.signal(i, Signals.CROSS_ABOVE_HIGH, msg, round(top));
  • Strategy receives the signal (so the code below would be in a 'Strategy-class', in 'onSignal'
    Java:
    if (position <= 0 && signal == Signals.CROSS_ABOVE_HIGH) {     
    if (thisStrategy.debug_Enabled) {
                debug("BUY on buy signal (when no position open yet) !");
            
            }
  • Strategy opens position (still in 'onSignal' in the Strat)
    Java:
    entryOrder = createMktEntry(ctx, buy, getSettings().getInteger(TRADE_LOTS) * instr.getDefaultQuantityAsFloat());
    ctx.submitOrders(entryOrder);
 

eickeee

Member
Joined
Aug 26, 2022
Posts
9
Likes
2
Thanks for answering @Spin!
I'm aware of the normal process (according to examples and sdk programming guide), however, as stated I do not have access to the code of the proprietary studies and while I'm in possession of the jar/class files, the code is obfuscated and simply extending did not work because of compiler complaints when loading the jar as libary to the classpath🙈
And while I could not find any other information or creative solutions, I just did not want to believe that there is no other concept and that those signals that the developer has actually properly added, can only be used in the alert windows but not via SDK in any way ☹️
 

eickeee

Member
Joined
Aug 26, 2022
Posts
9
Likes
2
I actually found a solution that might not be perfect but it allows you hooking exported values from other studies on your chart into a new study/strategy.

1. Add an `InputDescriptor` to your new study during initialization
Java:
@Override
public void initialize(Defaults defaults) {
    var sd = createSD();
    var tab = sd.addTab("General");
    SettingGroup basicSettings = tab.addGroup("Basic Settings");
    basicSettings.addRow(new InputDescriptor(INPUT, "Input 1", Enums.BarInput.CLOSE));
}

2. You can now get the key that was used for exporting the value to the DataSeries and retrieve the value via key access
Java:
@Override
protected void calculate(int i, DataContext dataContext) {
    Object inputKey = getSettings().getInput(INPUT);
    Object currentInputValue = dataContext.getDataSeries().getValue(inputKey);
}

3. In the UI you can then chose from all values from the Data Window - e.g. VWAP that you have on your chart
1672834676544.png
 

Spin

Well-known member
Joined
May 22, 2019
Posts
480
Likes
192
That is actually a nice find, @eickeee (y)(y)

Although this does not allow you to 'transpose' values from one study to another, it will certainly help others (and myself) in certain tricky situations.

Good job !! :)
 
Top