PDA

View Full Version : Bulding an Array Variable for Multiple Order


Tranbo
05-05-2011, 01:15 PM
Hi, I'm learning C# and NinjaTrader, I need few suggestion from the Pros. Using this great sample for my study project SampleOnOrderUpdate_NT7.zip (http://www.ninjatrader.com/support/forum/attachment.php?attachmentid=15444&d=1291217833)

--this sample only submitted one order at a time and I would like to build a script with 3 orders or more with different entry price.

I need suggestion on how to submit 3 order using this example code...Other then copy and paste the same code 3 times.

thanks advance for your suggestion.

NinjaTrader_RyanM
05-05-2011, 01:34 PM
Hello Tranbo,

This should not require an array. Yes, you pretty much have to duplicate the structure that's used for the existing entries. You can provide unique names to your multiple entry orders by providing a unique IOrder object name, and unique signal name. You have to duplicate the same structure for each order.

//Variables region
private IOrder entryOrder = null;
private IOrder entryOrder2 = null;

//condition for entry
if (entryOrder2 == null && Close[0] > Open[0])
{

entryOrder2 = EnterLong(1, "MyEntry2");
}

//reset to terminal(null) state when flat or cancelled. Only need one OnOrderUpdate() handler
if (entryOrder2 != null && entryOrder2 == order)
{
// Reset the entryOrder object to null if order was cancelled without any fill
if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
{
entryOrder2 = null;
}
}

Tranbo
05-05-2011, 10:15 PM
// Print NinjaTrader 100 times to the output window
for (int x = 0; x < 100; x++)
{
Print("NinjaTrader");
}


what does it take to get this code above to compile and run? it is just a sample code from the help doc. Every time I tried the error is


"class member declaration is expected''

koganam
05-06-2011, 02:12 AM
// Print NinjaTrader 100 times to the output window
for (int x = 0; x < 100; x++)
{
Print("NinjaTrader");
}


what does it take to get this code above to compile and run? it is just a sample code from the help doc. Every time I tried the error is


"class member declaration is expected''

That code compiles for me, when I put it in the OnBarUpdate() or even in the Initialize() method, so your problem must be elsewhere. In what method is your code located?

Tranbo
05-06-2011, 07:01 AM
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Sample demonstrating the use of the OnOrderUpdate() method.
/// </summary>
[Description("Sample strategy demonstrating a use case involving the OnOrderUpdate() method")]
public class SampleOnOrderUpdate : Strategy
{
#region Variables
private IOrder entryOrder = null; // This variable holds an object representing our entry order
private IOrder stopOrder = null; // This variable holds an object representing our stop loss order
private IOrder targetOrder = null; // This variable holds an object representing our profit target order
#endregion

/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()

// Print NinjaTrader 100 times to the output window
for (int x = 0; x < 100; x++)
{
Print("NinjaTrader");
}

It is on the top part of a perfectly working script

NinjaTrader_Bertrand
05-06-2011, 07:10 AM
It looks like you're missing the needed braces for OnBarUpdate() :

protected override void OnBarUpdate()
{
// Print NinjaTrader 100 times to the output window
for (int x = 0; x < 100; x++)
{
Print("NinjaTrader");
}
}