Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Has anyone had any luck starting a strategy from within another strategy? Like say your conditions are met and you'd like to start a new strategy, for whatever reason.
I know you can disable a currently running strategy; take for instance you have two strategies called SimpleMA and ComplicatedMA and you want to disable complicated from simple.
Now that disables the strategy, but there is no corresponding Enable(); or Start(); or Initialize(); function to start it, from what I can tell anyway.
So has anyone had any luck doing such a thing?
Can you help answer these questions from other members on NexusFi?
I haven't tried it yet but I want to make sure my logic is correct. Your CalledStrat is any strat as long as enabled=true, and your CallingStrat invokes the CalledStrat as a method???
Example:
MyTrendStrat is a stand-alone strat that works well in trending markets, and enabled=true.
MyChopStrat is a stand-alone strat that works well in chop, and enabled =true.
MyUberStrat has logic that decides if we are trending or in chop. It is the only strat I enable at the start of a session.
MyUberStrat would contain:
Variables
MyTrendStrat tradeTrend; // Can you really do this???
MyChopStrat tradeChop;
Initialize
tradeTrend = new MyTrendStrat();
tradeChop = new MyChopStrat();
//enabled = true here should only apply to MyUberStrat... right?
Then you lost me in OnBarUpdate().
If my MyUberStrat has chop and trend bool logic, what I want to do is this:
OnBarUpdate
if (chop) tradeChop();
if (trend) tradeTrend();
?
Is that the gist of it?
This is SQL weekend for me so I'm preoccupied but if what you say is true and robust (a "master" strategy can start and stop other strategies), that opens up some new avenues for me and the Ninja community in general.
Alright so I tried this, basically the only addition I needed to make was adding -
- in the Initialize(); function of my called strategy. However, Initialize never gets called and so Enabled is never set to true. And I know from my own testing that just setting the strategy's Enabled property to true from the calling strategy doesn't work.
Here's my called strategy, DoNothing:
And here's where the parent strategy is calling it:
I just realized that there are 2 threads here, yours and MXASJ's.
The NT 7 doc says that Initialize is called once upon starting a strat.
So I guess you have to determine if the strategy is ever started (seems
circular, because that's the problem you're trying to solve).
I guess I can really only comment on my method of starting a sub
strategy. Anyway, what exactly is Acct and what are you doing with it?
I think zwentz and I are asking the same thing, just differently. This does not work:
In your initial note you have "xyz" as an example. Like the comments in the code above state, I can't find anything that would load and enable another strategy.
Hope that helps. I'm not sure exactly when the strategy is loaded and enabled, but I've had no problems using
my method above. All of my strategies are enabled after I've applied them to the chart (as long as I have a
simulated, live or market replay connection).