- ago
I have 2 strategies for the same symbol, and I do not want to trade if this symbol already has an open position from another strategy currently open

Is there a way to do it?
0
580
19 Replies

Reply

Bookmark

Sort
- ago
#1
Yes, there are several ways. Off the top of my head:

1. Using global variables (*Global methods), set a flag in one strategy and make a check for its presence in the other. Requires coding.

2. Combine the logic of two strategies into one, then in Strategy Settings > Position Sizing set "Max Open Per Symbol" to 1. Possible to do with Blocks.
0
- ago
#2
Option 1. I don't know anything about code, only using blocks

Option 2. Need to have it in 2 strategies

Any more ideas?
0
- ago
#3
Despite being so flexible and powerful, no-code solutions like Blocks have their limitations which can be avoided using code.
0
MIH8
- ago
#4
Hello Eugene.

QUOTE:

Yes, there are several ways. Off the top of my head:

1. Using global variables (*Global methods), set a flag in one strategy and make a check for its presence in the other. Requires coding.

2. Combine the logic of two strategies into one, then in Strategy Settings > Position Sizing set "Max Open Per Symbol" to 1. Possible to do with Blocks.


Interesting! This reminds me of Post #14 (replied to Cone Post #12) in the following thread.
https://www.wealth-lab.com/Discussion/Unexpected-Exit-Signals-Running-two-strategies-8427
0
- ago
#5
QUOTE:
Option 1. I don't know anything about code, only using blocks
Option 2. Need to have it in 2 strategies
Any more ideas?

Well, there's a weird option if you can check if a symbol is already owned by your broker's portfolio. If you like this option, then vote for the feature request https://www.wealth-lab.com/Discussion/Access-Accounts-data-from-broker-programmatically-7914

I want to retract the above suggestion because it only works for real-time trading. It's not going to work for historical backtesting because it only delivers a look at the real-time portfolio. But it would prevent WL from creating new duplicate positions in real-time--if that's the "only" goal. (One still might get duplicate positions created in the backtest.)

In addition, this third option would likely require some coding. If you want to do more complex strategies, then you'll need to code. If you don't want to learn to code, then get a local partner (who knows C#) to do the coding for you. And it's more fun with a partner anyway.
0
- ago
#6
If one doesn't want to code then such "code partner" is one of us team members. A solution for such tasks with requirements going beyond the capabilities is available through Concierge Support:

https://www.wealth-lab.com/Discussion/WealthLab-Concierge-Support-Service-8517
0
- ago
#7
It's difficult to understand why WL can't handle this future request in blocks if this GLOBAL solution can be done in code? (Per Post #1)

What's the big deal about it? How challenging is it if you have it in "code" already?
0
- ago
#8
I'd like to be wrong but this doesn't appear to be an option universal and intuitive enough to justify the inclusion in Blocks. Maybe Glitch or Cone think it otherwise.
0
- ago
#9
QUOTE:
How challenging is it if you have it in "code" already?

You are correct. Doing it in code is also challenging as well. You have a "classical" CompSci reader/writer problem were you have "two" (many threads) different strategies reading and writing into the same shared resource which isn't intrinsically thread safe.

What can be done is allocate a thread-safe global object, which all the strategies would have access to. But debugging the operation of this thread-safe global requires a seasoned programmer. It not something the average WL coder should be attempting.

And the logistical issue is how many WL users would actually need this feature? I would forget about the option# 1 coding solution.
0
Glitch8
 ( 11.81% )
- ago
#10
Hi Kls,

You are welcome to submit this as a #FeatureRequest. We have quite a back log but if enough users vote for your request it can rise up to the top of the wish list.

Why is it so hard to understand that we simply can’t implement every one off request that we come across here?
0
MIH8
- ago
#11
@superticker

QUOTE:

.. And the logistical issue is how many WL users would actually need this feature? ...


Two or multiple strategies operating on the same dataset is not something very special imho.
For sure this isn't an extraordinary feature request and should be already part of the basic design.

@Kls

QUOTE:

It's difficult to understand why WL can't handle this future request in blocks if this GLOBAL solution can be done in code? (Per Post #1)

What's the big deal about it? How challenging is it if you have it in "code" already?


They don't have a solution for it in any form. And it is not a trivial task to solve it by the way.
It is even more complex if it needs to be integrated in an existing design.
From users point of view this is a basic requirement imo.
0
Glitch8
 ( 11.81% )
- ago
#12
Hey MIH, I strongly disagree. It's not a basic requirement. In fact, in the 20+ years I've been doing this it's the first time it's come up. I think it's unfair to make such a claim.
2
MIH8
- ago
#13
I apologize. I do not want to devalue the software and the people behind in any way at this point.

What I want to say is that the idea of applying two strategies simultaneously to one data set is very basic and intuitive. Especially in a system like WL, which is very good for developing many ideas and strategies. The thought inevitably comes to mind. For example, applying strategies to a data set like the Nasdaq 100.
0
- ago
#14
My concern is totally different than anything mentioned. Adding such a subtle feature in WL may create weird WL behavior that would confuse many typical WL users.

The other problem is that the .NET framework only offers thread-safe datatypes, which give mutually exclusive access to both reader and writer. But in this reader/writer problem, only the writer needs exclusive access. And the .NET framework does not offer a datatype for that case. They do have an execution locking library call that can do it, however, with thread critical sections. A graduate-level advanced OS textbook should include examples using critical sections.
0
Glitch8
 ( 11.81% )
- ago
#15
You can of course apply two strategies to the same dataset with out restriction. The issue comes when trying to coordinate between the two. System A needs to know the state of System B at every point in time, and vice versa. This implies that the two systems need to somehow communicate, but if you’re only running one of the strategies for example how do you do that?

The problem really is not the hard to overcome, you need to just combine the two strategies into one within a code based strategy. Then it becomes trivial. But kls states that this is not an option and wants a solution in building blocks. I can’t imagine how we could implement this in building blocks in two strategies.

Since WL is a backtesting tool primarily, I’m approaching this from a backtesting perspective. Kls mentions he doesn’t want to “trade” so maybe this is a trading only request? If so then it’s probably easier to implement. But we try to build features that you can BACKTEST to see if they work instead of things that apply only to trading.
0
MIH8
- ago
#16
QUOTE:

My concern is totally different than anything mentioned. Adding such a subtle feature in WL may create weird WL behavior that would confuse many typical WL users.

The other problem is that the .NET framework only offers thread-safe datatypes, which give mutually exclusive access to both reader and writer. But in this reader/writer problem, only the writer needs exclusive access. And the .NET framework does not offer a datatype for that case. They do have an execution locking library call that can do it, however, with real-time critical sections. A graduate-level advanced OS textbook should include examples using critical sections.


Hi superticker.

I think you are making the issue even more complex than it needs to be.
The strategies are already running in parallel independently of each other and should be kept that way.

The result, the signals can be synchronized after they have been generated and passed to the Order Manager.
After the strategy manager has generated the signals, the order manager can process the signals across strategies and then pass them to the broker. The issue is still complex enough.

As far as the backtest is concerned, a meta-strategy should serve as a basis.
Instead of choosing a separate data set for each strategy, one could specify one data set for all strategies.
An attribute to a symbol in the data set could be used to specify which strategy has exclusive access to it.
This access refers to the duration of a trade.

Thinking about it that would mean, if the Meta-Strategy can handle it, you can run the Meta-Strategy in the SM. (no clue if this is possible now).
1
- ago
#17
I agree using a meta-strategy (option# 2.5) to insure both strategies are executing together and sharing information makes the most sense.

---
Off topic, but I test each new stock against all my strategies, then uniquely assign it to the dataset/strategy combination that performs the very best. I forbid my stocks from using more than one strategy. You get more reproducible results by going with a simpler design.
1
MIH8
- ago
#18
@superticker
QUOTE:

.. I forbid my stocks from using more than one strategy. ...


Interesting wording. Although it is clear you just want to point out that you exlusively use a stock by one strategy it means a different design. A strategy is using the data not the other way around in WL. Attaching a strategy to a symbol (dataset) would not run into that issue or would be trivial to solve. I do not say it would be better but simply different design.

@Glitch
QUOTE:

... The problem really is not the hard to overcome, you need to just combine the two strategies into one within a code based strategy. Then it becomes trivial. ...


True for a specific combination of two strategies. However, having a tool like the Meta-Strategy could solve the task in principle. A huge advantage is to measure the synergy of strategies without having to code countless combinations, which would be impractical.

One difficulty with coding is that it is usually not a one-time thing. The strategy must be tested, at least in the beginning, changes are made constantly. Mostly the way from the idea to the finished strategy is a process. Unfortunately, on this way it can turn out that the idea does not work which leads to the next point ...

@Eugene
QUOTE:

If one doesn't want to code then such "code partner" is one of us team members. A solution for such tasks with requirements going beyond the capabilities is available through Concierge Support:

https://www.wealth-lab.com/Discussion/WealthLab-Concierge-Support-Service-8517


Good thing!, but it requires a ready for production strategy. My first impression that it is a chicken and egg problem.
You don't want to use an untested strategy productively, but you can't test it because you can't implement it.
You certainly want to avoid spending money on a strategy that ultimately won't be used.

The key point might be this one in such a case "Expert Analysis or your Strategy, with recommendations for improvements". If this includes a pre-evaluation with some kind of default backtest to see the potential of the strategy it would result in an objective feedback if it is worth to realize. On the flip side, you certainly don't want to spend time on something that will eventually lead to a rejection of the task.

Happy weekend
0
- ago
#19
@MIH
QUOTE:
The result, the signals can be synchronized after they have been generated and passed to the Order Manager.
After the strategy manager has generated the signals, the order manager can process the signals across strategies and then pass them to the broker. The issue is still complex enough.


Just wanted to chime in and say I totally agree with you here and how you described implementation. This is how I'd envision it as well. E.g. Run X number of strategies across N tickers. If ANY of the strategies trade any of the N tickers (entry or exit) then trade that ticker. Each ticker has it's own "state" flags based on an OR condition applied to the results of each Strategy run. (Buy or Sel flags, In a current trade flag, etc). Any of the strategies has the right to alter the state of the flags on any stock. Ideally you could specify how you'd like the results of each Strategy combined, e.g. OR'd or AND'd, in some way's a Meta Strategy version thing that perhaps looks similar to a "Building Blocks editor with the Multi-condition Groups" workflow path. (This is largely how I've worked around accomplishing this in the current Building Blocks capabilities.)

As a work around to this I've just built extraordinarily long and complex singe strategies with multiple (way too many!) Buy/Sell blocks that use Multi-condition Groups :) I'd much prefer to just have built individual strategies and OR'd (and AND'd) them together as described above in Meta Strategy (or somewhere else). Perhaps this is more of a Meta Strategy Feature Request instead of within Building Blocks.

I'm still new here and figuring everything out so just chiming in when I see someone else who's clearly been trading/building strategies for a while like I have and also running into the same thing.
0

Reply

Bookmark

Sort