NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 06-04-2008, 12:09 PM   #1
Jeff 15
Member
 
Join Date: Apr 2008
Location: Fenton, MI
Posts: 33
Thanks: 0
Thanked 0 times in 0 posts
Question Question on Multi instrument forex

Im tyring to program a Strategy that enters a long position in two separate pairs and exits both pairs when a certian profit target (dollar amount of unrealized P&L) is achieved.
I think I may be close but on back tests is only entering the primary pair and not the secondary (it should enter both at the same time and exit both at the same time). It does seem to be exiting when the profit target is achieved but im not sure if it will work when both pairs are entered properly.

If anyone can look at the following and give some tips I would really apprieciat it.

Please excuse my ignorance, this is my first try at this.

Thank You,

#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
#endregion
///<summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
///</summary>
protectedoverridevoid Initialize()
{
// Add an $USDCHF 2 minute Bars object to the strategy
Add("$USDCHF", PeriodType.Minute, 2);

// Note: Bars are added to the BarsArray and can be accessed via an index value
// E.G. BarsArray[1] ---> Accesses the 1 minute Bars added above
// Add ZeroLagStochs indicator to the chart for display
// This only displays the indicator for the pimary Bars object (main instrument) on the chart
Add(ZeroLagStochs());
CalculateOnBarClose =
true;
}
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
// OnBarUpdate() will be called on incoming tick events on all Bars objects added to the strategy
// We only want to process events on our primary Bars object (main instrument) (index = 0) which
// is set when adding the strategy to a chart
if (BarsInProgress != 0)
return;

// Condition set 1
if (CrossAbove(ZeroLagStochs().Mov, 75, 1))
{
//Submits buy market order for EURUSD
EnterLong(100000, "long");
//Submits buy market order for USDCHF
EnterLong(120000, "BUY $USDCHF");
}
// Condition set 2
if (Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) >= 200)
{
//Exits EURUSD long position when total unrealized P&L reaches $200.00
ExitLong("", "long");
//Exit CHF
ExitLong("", "Buy $USDCHF");
}
}
#region Properties
#endregion
}
}
Jeff 15 is offline  
Reply With Quote
Old 06-04-2008, 01:40 PM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

You would need to do something like:

//Submits buy market order for EURUSD
EnterLong(100000, "long"
);
//Submits buy market order for USDCHF
EnterLong(1, 120000, "BUY $USDCHF");


Notice the "1" I have added which represents the secondary series.

Check out the following Help Guide section and scroll down to the "Working with a Multi-Instrument Strategy" section.

http://www.ninjatrader-support.com/H...rHandling.html
NinjaTrader_Ray is offline  
Reply With Quote
Old 06-05-2008, 06:51 AM   #3
Jeff 15
Member
 
Join Date: Apr 2008
Location: Fenton, MI
Posts: 33
Thanks: 0
Thanked 0 times in 0 posts
Question Multi instrument

Thanks Ray, I tried making the change you pointed out in you last post but it just made it only enter into the secondary pair. I read the section you asked me to. I have made a few changes but I still cant seem to get the Stategy to enter into both instruments. Can you please review what I have changed? Maybe you can steer me in the right direction.

Thank you,

protectedoverridevoid Initialize()
{
// Add an $USDCHF 2 minute Bars object to the strategy
Add("$USDCHF", PeriodType.Minute, 2);

// Note: Bars are added to the BarsArray and can be accessed via an index value
// E.G. BarsArray[1] ---> Accesses the 2 minute Bars added above

// Add ZeroLagStochs indicator to the chart for display
// This only displays the indicator for the pimary Bars object (main instrument) on the chart
Add(ZeroLagStochs());
CalculateOnBarClose = true;
}
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
private IOrder entryOrder = null;

protectedoverridevoid OnBarUpdate()
{
// OnBarUpdate() will be called on incoming tick events on all Bars objects added to the strategy
// We only want to process events on our primary Bars object (main instrument) (index = 0) which
// is set when adding the strategy to a chart
if (BarsInProgress != 0)
return;

// Condition set 1
if (CrossAbove(ZeroLagStochs().Mov, 75, 1))
{
// Submit an order for EURUSD in the context of EURUSD bar update event
if (entryOrder == null)
entryOrder = EnterLongLimit(0, true, 100000,Close[1], "long");



// Submit an order for USDCHF in the context of EURUSD bar update event
if (entryOrder == null)
entryOrder = EnterLongLimit(1, true, 120000,Close[1], "BUY $USDCHF");
}
// Condition set 3
if (Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) >= 200)
{
//Exits EURUSD long position when total unrealized P&L reaches $200.00
ExitLong("", "long");
//Exit CHF
ExitLong(1,"", "Buy $USDCHF");
}
}
#region Properties
#endregion
}
}
Jeff 15 is offline  
Reply With Quote
Old 06-05-2008, 06:59 AM   #4
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Don't see anything popping out at me.

You will need to debug your strategy. Here is a tip we put out on that in case you have never seen it.

http://www.ninjatrader-support.com/v...ead.php?t=3418
NinjaTrader_Ray is offline  
Reply With Quote
Old 06-05-2008, 01:07 PM   #5
Jeff 15
Member
 
Join Date: Apr 2008
Location: Fenton, MI
Posts: 33
Thanks: 0
Thanked 0 times in 0 posts
Question Multi instrument

Thanks again Ray, You have been a big help. I would like to use the "Print()" command to try to find some of the bugs but I am having trouble getting it to work. Would you mind showing me an example of how I would attach it on the codes below?

Thank you,

// Condition set 2
if ( Position.GetProfitLoss( Close [0],PerformanceUnit.Currency) >= 200)
{
{
ExitLong(
"", "long");

ExitLong(
1,"", "Buy $USDCHF");
}

TraceOrders =
false;
}
Jeff 15 is offline  
Reply With Quote
Old 06-05-2008, 01:40 PM   #6
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

First, put TraceOrders in Initialize() method:

Then something like:

if (yourCondition == true)
{
Print("Whatever information you want to see here");
}
NinjaTrader_Ray 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
Multi-instrument Strategy dgregor5 Strategy Development 6 06-29-2010 04:47 AM
Multi instrument order glitch/bug/question? adrian Strategy Development 5 05-01-2008 07:10 AM
Multi-Instrument help Json General Programming 11 04-22-2008 10:42 AM
Adding TICK as a multi instrument altrader Connecting 2 03-27-2008 08:25 AM
Multi Time Frame/Multi Instrument? GreenTrade Strategy Development 3 01-14-2008 02:24 PM


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