NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > Application Technical Support > Automated Trading

Automated Trading Support for automated trading systems using NinjaScript. Support for our ATI (Automated Trading Interface) used to link an external application such as TradeStation and eSignal to NinjaTrader.

Reply
 
Thread Tools Display Modes
Old 03-06-2011, 01:38 AM   #1
skyholder84
Member
 
Join Date: Sep 2010
Posts: 84
Thanks: 0
Thanked 0 times in 0 posts
Default Running multiple strategies on the same security

Hi,

I have two strategies for trading the same security (eg: EURUSD on a short term and on a long term strategy). I want them to work independently, without knowledge or consideration as to what the other strategy is doing. Ie, I don't mind doubling my risk, or having my two strategies make equal, opposing trades (since they'll close out at different times anyway).

My problem is that I use "Position.MarketPosition == MarketPosition.Flat" as a condition to ensure that each strategy handles only one trade at a time.

As a result, when strategy A is long EURUSD, strategy B cannot trade, since the account is not "flat" EURUSD. This is because Position.MarketPosition == MarketPosition.Flat is a reference to the account position.

In light of these facts, it becomes clear that Position.MarketPosition == MarketPosition.Flat is not a valid mode of position control when running two strategies side by side trading the same security.

I would like to know how I can programme my two strategies to run side by side on the same security without one interrupting the other. Is it possible? As alternatives to "Position.MarketPosition == MarketPosition.Flat", I have tried using Position.Quantity and Variables0-9 to determine if the strategy has traded, but neither seems to work (since Variable0 is undefined at the beginning of a loop, and for some strange reason, position.quantity work).
skyholder84 is offline  
Reply With Quote
Old 03-06-2011, 01:45 AM   #2
skyholder84
Member
 
Join Date: Sep 2010
Posts: 84
Thanks: 0
Thanked 0 times in 0 posts
Default

Also, if there is no way to prevent the strategies from clashing, I might have to consider opening a separate IB account so that the issue does not arise. Will I be able to use the same NT license for both IB accounts? Am hoping to find a solution though!
skyholder84 is offline  
Reply With Quote
Old 03-06-2011, 01:01 PM   #3
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 90 times in 82 posts
Default

skyholder84, NinjaTrader strategies are completely independent of each other. As such, they cannot read position information from other strategies. Since NinjaScript is based off of C#, you are able to code up a position tracker however you wish, from writing to a file and then reading that file in your other strategy, the whole way to a full-featured MySQL database that tracks all orders, fills, and positions.

So it is possible, but not in a direct fashion.
NinjaTrader_Austin is offline  
Reply With Quote
Old 03-06-2011, 07:52 PM   #4
skyholder84
Member
 
Join Date: Sep 2010
Posts: 84
Thanks: 0
Thanked 0 times in 0 posts
Default

Would I be able to say, set a different order quantity for each strategy to act as a control?

Illustration:

Strategy A trades only 1 contract
Strategy B trades 2 contracts

The control logic would go like this:

If(StrategyAGeneralConditions = True
&& Position.Quantity != 1
&& Position.Quantity != 3)

{EnterLong(20000, "LS1");}

- If Position Quantity is 0, neither strategy has traded, and Strategy A is good to go.
- If Position Quantity is 2, only Strategy B has traded, and Strategy A is also good to go.
- If Position Quantity is 3, both strategies have traded, and Strategy A is blocked from further trading (Of course, a similar measure will be written in Strategy B)

Hence, as long as Position.Quantity != 1, my strategy can "deduce" that it hasn't traded.

Can I use the Position.Quantity function as a control in this way?
skyholder84 is offline  
Reply With Quote
Old 03-07-2011, 04:19 PM   #5
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hi skyholder84,

Your net account position will reflect activity for both strategies, but all the properties you're using only apply within the strategy instance that access them. If you check MarketPosition, you're checking that strategies position rather than the account position.

There are only a handful of account level properties you can access. The rest are specific to the strategy instance calling them.
NinjaTrader_RyanM is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Running Strategies in Replay with Multiple Accounts FormulaXTrader Automated Trading 5 03-14-2011 03:24 AM
Running Ninja Strategies with Multiple Data Feeds in Simulation Mode KBJ Version 7 Beta General Questions & Bug Reports 3 07-12-2010 09:09 PM
Running multiple strategies simultaneously d.allen101 Strategy Development 7 08-14-2009 05:50 AM
Running Multiple Strategies on 1 Instrument SystemTrading Strategy Development 5 02-25-2009 12:04 PM
PCTools Internet Security software. Anyone running this ok? saltminer Connecting 1 01-27-2009 07:31 AM


All times are GMT -6. The time now is 05:27 PM.