Make strategy start another strategy - NinjaTrader Programming | futures io social day trading
futures io futures trading


Make strategy start another strategy
Updated: Views / Replies:3,830 / 13
Created: by zwentz Attachments:1

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you dont need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 1  
 
Thread Tools Search this Thread
 

Make strategy start another strategy

  #1 (permalink)
 Vendor: www.ninjaterminal.com 
Austin, TX
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Optimus Futures/Rithmic
Favorite Futures: Futures [ZB]
 
Posts: 36 since Sep 2009
Thanks: 12 given, 22 received

Make strategy start another strategy

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.

 
Code
Account.Strategies[i].Disable(); //i is the index in the StrategiesCollection of your ComplicatedMA strategy
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?

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Trading for Fun
College Point, NY (Queens)
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: AMP/CQG
Favorite Futures: YM
 
Posts: 63 since Nov 2009
Thanks: 5 given, 20 received


Yes, here's how I did it (for example) ... sorry about the formatting ....

Instantiating a strategy from another strategy ...


CalledStrategy.cs
-----------------

 
Code
                            
// Called strategy (i.e. instantiated from main strategy) ...

namespace NinjaTrader.Strategy
{
          public class 
CalledStrategy Strategy
         
{

                  protected 
override void Initialize()
                   {
                         ... 

                         
Enabled true;
                }

                 
// Guts ...

           
}

CallingStrategy.cs
------------------

 
Code
                            
// Calling strategy (i.e. instantiates the called strategy)  ...

namespace NinjaTrader.Strategy
{
          public class 
CallingStrategy Strategy
         
{
                 
// Declare Called Strategy.

                
CalledStrategy cStrat;

                protected 
override void Initialize()
                 {

                        
// Instantiate Called Strategy.

                       
cStrat = new CalledStrategy();

                       
Enabled true;
              }

               protected 
override void OnTermination()
                 {
                       
base.Dispose();
               }
    
                protected 
override void OnBarUpdate()
               {
                       
// Use Called strat here ...

                      
cStrat.xyz();  // for example;
               
}
        }



Last edited by sam028; September 25th, 2010 at 07:31 AM. Reason: add coding tag
Reply With Quote
The following 3 users say Thank You to kandlekid for this post:
 
  #4 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received

Thanks kandlekid,

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.

Reply With Quote
 
  #5 (permalink)
Trading for Fun
College Point, NY (Queens)
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: AMP/CQG
Favorite Futures: YM
 
Posts: 63 since Nov 2009
Thanks: 5 given, 20 received

> Your CalledStrat is any strat as long as enabled=true, and your CallingStrat invokes the CalledStrat as a method???

You're invoking the constructor of the strategy. So it has to be the same name as the class.

>Variables

> MyTrendStrat tradeTrend; // Can you really do this???
> MyChopStrat tradeChop;

Sure.

> Initialize

> tradeTrend = new MyTrendStrat();
> tradeChop = new MyChopStrat();

> //enabled = true here should only apply to MyUberStrat... right?

I think you want to enable all the strats ... that's what I do.

> 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();

Ok, so if you add tradeChop() and tradeTrend() to MyChopStrat() and MyTrendStrat() as public member functions, then you can do ...

if (chop) tradeChop.tradeChop();
if (trend) tradeTrend .tradeTrend();

So you're calling the member functions from the instantiated objects.

>Is that the gist of it?

I think so ..

Strategies are really just C# classes ...

Reply With Quote
The following user says Thank You to kandlekid for this post:
 
  #6 (permalink)
 Vendor: www.ninjaterminal.com 
Austin, TX
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Optimus Futures/Rithmic
Favorite Futures: Futures [ZB]
 
Posts: 36 since Sep 2009
Thanks: 12 given, 22 received

Hey kandlekid,

Alright so I tried this, basically the only addition I needed to make was adding -

 
Code
Enabled = true;
- 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:

 
Code
public class DoNothing : Strategy
{
        protected override void Initialize()
        {
            CalculateOnBarClose = true;
			Enabled = true;
        }

        protected override void OnBarUpdate()
        {
        }
}
And here's where the parent strategy is calling it:

 
Code
if (!exists)
{
	Period test = new Period(PeriodType.Minute,1,MarketDataType.Last);
	DoNothing nts = new DoNothing();
	nts.Account = Acct;
	nts.SetBarsPeriodInstrument(test,position.Instrument);
	Acct.Strategies.Add(nts);
}
Am I missing something?

Reply With Quote
 
  #7 (permalink)
Trading for Fun
College Point, NY (Queens)
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: AMP/CQG
Favorite Futures: YM
 
Posts: 63 since Nov 2009
Thanks: 5 given, 20 received

Hi zwentz,

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.e.

nts.Account = Acct;

Acct.Strategies.Add(nts);


Last edited by kandlekid; September 26th, 2010 at 02:03 AM.
Reply With Quote
 
  #8 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received

I think zwentz and I are asking the same thing, just differently. This does not work:

 
Code
public class MasterStratTest : Strategy
    {
        #region Variables
 
        SampleMACrossOver cStrat;
 
        #endregion
 
        protected override void Initialize()
        {
            cStrat = new SampleMACrossOver();
            Enabled = true;
 
            CalculateOnBarClose = true;
        }
 
 
        protected override void OnBarUpdate()
        {
            cStrat.// Can't find anything that would load and enable SampleMACrossOver 
 
        }
 
 
 
        #region Properties
 
        #endregion
    }
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.

Reply With Quote
 
  #9 (permalink)
Trading for Fun
College Point, NY (Queens)
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: AMP/CQG
Favorite Futures: YM
 
Posts: 63 since Nov 2009
Thanks: 5 given, 20 received


Quoting 
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.

 
Code
// You instantiated SampleMACrossOver here (i.e. you created the strategy).

cStrat = new SampleMACrossOver();


// Here you want to call a member function (method) of SampleMACrossOver().

protected override void OnBarUpdate
{

    // For example ...

    if ( cStrat.ShortMACrossedOverLongMA() )
       Go long ...
   else if ( cStrat.ShortMACrossedUnderLongMA() )
       Go short ...
}
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).

Reply With Quote
 
  #10 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received


Ok then we are talking about different things.

If you want to call methods external to a strategy you can also use the UserDefinedMethods partial class.

Reply With Quote

Reply



futures io > > > > > Make strategy start another strategy

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can anyone help me make the RC Beginner strategy work in MultiCharts? greyhound MultiCharts 7 February 18th, 2013 06:34 AM
Utility To Transpose Optimized Strategy Values From Excel Output to Actual Strategy mercuryfx NinjaTrader 5 April 7th, 2012 04:59 PM
Ninjatrader7 ATM Strategy combine with Strategy Wizard Ninja Script schuster21 NinjaTrader Programming 4 July 4th, 2011 05:39 PM


All times are GMT -4. The time now is 02:44 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-12-15 in 0.13 seconds with 20 queries on phoenix via your IP 54.226.132.197