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 > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 08-04-2012, 02:31 PM   #1
bascher
Junior Member
 
Join Date: Jun 2010
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
Default Multi instrument sell and buy

Hallo,

I have got a multi instrument strategy and the following code snippet:

protected override void OnBarUpdate()
{
// Is this necessary to verify the instrument 1 and 2??
if (BarsInProgress == 0)
{
double beta = SpreadPlot2(10,1,10,Symbol2).Beta;
double betage = Math.Round(beta,2);
double factor = betage*10;
int factorint = Convert.ToInt32(factor);
// Condition 1
if (CrossBelow(SpreadPlot2(10, 1, 10, Symbol2).Value, Variable0, 1))
{
string ausgabe = string.Format("Beta = {0}",beta);
Print(ausgabe);
Print(factorint);
// EnterLong(int barsInProgressIndex, int quantity, string signalName) e.g. EnterLong(0, 100, "BUY MSFT");
// Sell 10 x instrument 1
EnterShort(0,10,"SELL $NZDUSD");
// Buy factorint x instrument 2
EnterLong(1,factorint, "Buy $USDCAD");
}
// Condition 2
else if (CrossAbove(SpreadPlot2(10, 1, 10, Symbol2).Value, Variable1, 1))
{
Print("CrossAbove -2");
EnterLong(0,10,"BUY $NZDUSD");
EnterShort(1,factorint, "Sell $USDCAD");

}
}
}

There happens nothing but the following error occurs:

**NT** Error on calling 'OnBarUpdate' method for strategy 'Residual/': 'EnterLong': 'barsInProgressIndex' parameter out of valid range 0 to 0, was 1

What I have to change?
Thank you in advance for your effort.
Best regards
Benjamin
bascher is offline  
Reply With Quote
Old 08-04-2012, 04:21 PM   #2
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

bascher,

Could you also post your "Initialize()" section here? It would be helpful so I can assist you further.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 08-05-2012, 12:08 PM   #3
bascher
Junior Member
 
Join Date: Jun 2010
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
Default

My "Initialize()" section:

protected override void Initialize()
{
SpreadPlot2(10, 1, 10, Symbol2).Plots[0].Pen.Color = Color.Green;
Add(SpreadPlot2(10, 1, 10,Symbol2));
CalculateOnBarClose = true;
}
bascher is offline  
Reply With Quote
Old 08-05-2012, 12:12 PM   #4
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

bascher,

You aren't adding a second series here so OnBarUpdate() will not be called with a BarsInProgress index other than 0. You would need to add the second series you are trading in order for this strategy to work.

http://www.ninjatrader.com/support/h...nstruments.htm
NinjaTrader_AdamP is offline  
Reply With Quote
Old 08-07-2012, 11:39 AM   #5
bascher
Junior Member
 
Join Date: Jun 2010
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
Default

Hallo Adam,

thank you for your advise. The problem now is that in the output window occur an additional value. I donīt know where it comes from and what it are representing.
I only wrote:

Add(Symbol2, PeriodType.Minute, 1);

where Symbol2 is a property in the follwing way:

[Description("Symbol 2")]
[GridCategory("Parameters")]
// Force this parameter to be displayed first
[Gui.Design.DisplayName("\tSymbol 2")]
public string Symbol2
{
get
{
if ((symbol2 == "") && (ChartControl != null) && (Instruments != null))
for (int i = 0; i < ChartControl.BarsArray.Length; i++)
if (ChartControl.BarsArray[i].Instrument.FullName != Instruments[0].FullName)
{
symbol2 = ChartControl.BarsArray[i].Instrument.FullName;
break;
}
return symbol2;
}
set { symbol2 = value.ToUpper(); }
}

Without the add statement everything works.

Any hints?
Thank you in advance.
Benjamin
bascher is offline  
Reply With Quote
Old 08-07-2012, 01:02 PM   #6
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
Default

Hello,

Thanks for your patience while I reviewed.

Unfortunately dynamic properties are not supported and I really do not have a hint for you here.

-Brett
NinjaTrader_Brett is offline  
Reply With Quote
Reply

Tags
enterlong, multi instrument

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
Buy/Sell Volume jerome Indicator Development 1 12-29-2009 08:07 AM
Script is running wild: buy - sell - buy - sell ... BillCh Automated Trading 4 02-06-2009 01:01 PM
buy sell centered ? T2020 Charting 3 10-16-2008 11:20 AM
Sound on Buy and Sell laserjet General Programming 3 09-30-2008 07:00 PM
Buy Sell Indicator infotrader Charting 2 01-28-2008 02:12 PM


All times are GMT -6. The time now is 01:11 PM.