PDA

View Full Version : eSignal DDL function format


werosen
12-13-2005, 10:23 AM
I appear to be stuck on the proper format to return a correct value for the NTMarketPosition function in an eSignal .efs file.

I'mhavethe following in preMain():

dll.addFunction("MarketPosition", DLL.INT, DLL.STDCALL, "MarketPosition", DLL.STRING, DLL.STRING);

I have the the following function defined prior to main():

function getMySymbol()
{
symbol = getSymbol();
if (symbol == "AB #F")
symbol = "ER2 03-06";

return symbol;
}

// Get the market position of the current instrument. "account" is optional (set to "" it not applicable).
function NTMarketPosition(Sim101)
{
return dll.call("MarketPosition", getMySymbol(), "Sim101");

To see the value returned by NTMarketPosition(), I amwriting to my formula output window:

debugClear()

debugPrintln(" NTMarketPosition(): " + NTMarketPosition());

The value returned is 0, even though my SuperDOM shows I am in a Long position for instrument ER2 03-06 for account Sim101.

Can anyone tell me what the problem is?

Regards,

Warren

NinjaTrader_Dierk
12-13-2005, 06:48 PM
Not sure what's going wrong, but here are some hints:
a) debug the symbol name as well. Are you really running it on "AB #F" (which will be mapped) or a different symbol.
b) temporarily replace the getMySymbol function by getSymbol
c) try setting account to "" and make sure Tools->Options->Misc->Default account is set to "Sim101"
d) double check that File->ATI is checked

werosen
12-13-2005, 07:39 PM
All good suggestions which I have alreadt tried, but repeated a second time.

a) debug the symbol name as well. Are you really running it on "AB #F" (which will be mapped) or a different symbol.

AB #F is running in the eSignal chart


b) temporarily replace the getMySymbol function by getSymbol

getSymbol returns AB #F to the Formla Output Window

getMySymbol returns ER2 03-06


c) try setting account to "" and make sure Tools->Options->Misc->Default account is set to "Sim101"

Default account was set to Sim101 and "" does not effect result


d) double check that File->ATI is checked

Automated Trading is checked in the File menu

Additionally, NTConnected() returns true.

What next?

werosen
12-13-2005, 08:55 PM
I have tried many variations, but here is my current iteration that still returns 0 for NTMarketPosition.

I'mhavethe following in preMain():

dll.addFunction("MarketPosition", DLL.INT, DLL.STDCALL, "MarketPosition", DLL.STRING, DLL.STRING);

I have the the following function defined prior to main():

function getMySymbol()
{
symbol = getSymbol();
if (symbol == "AB #F")
symbol = "ER2 03-06";

return symbol;
}

// Get the market position of the current instrument. "account" is optional (set to "" it not applicable).
function NTMarketPosition(account)
{
return dll.call("MarketPosition", getMySymbol(), account);

To see the value returned by NTMarketPosition(), I amwriting to my formula output window:

debugClear()

debugPrintln(" NTMarketPosition(): " + NTMarketPosition("Sim101"));

The value returned is 0, even though my SuperDOM shows I am in a Long position for instrument ER2 03-06 for account Sim101.

Regards,

Warren

NinjaTrader_Dierk
12-13-2005, 10:03 PM
You then should try to get the provided NtSample.efs working.

If that really works you can tweak it step by step to achieve what you initially itended.

That's how I usually approach weird issues like these: Take what is working, tweak it step by step and retest every iteration.

werosen
12-14-2005, 01:25 AM
When I load NTSample.efs into my chart it returns:

'Internal Error: DLL.call cannot locate(MarketPosition)'

werosen
12-14-2005, 01:50 AM
I now have the NTSample.efs loaded, but it returns 0 for NTMarketPosition(""), just like it does in my file, even though I am Long 1 contract.

werosen
12-14-2005, 02:39 AM
Aditional Info:

NTStrategies("Sim101") returns no value.

NinjaTrader_Dierk
12-14-2005, 05:23 AM
I just tested and it works expected.

Try this:
- terminate and restart NT
- clear out sim account by Tools->Options->Reset
- File->Check Automated trading interface
- Tools->Instrument manager->Double click on ER2->Misc->External feed: set to AB
- connect to Simulation feed
- select ER2 03-06 in the control center
- start eSignal
- pull up a new 1-minute chart on AB H6
- eSignal: Tools->EFS->Folmula Output Window
- Right click on chart->Formuals->Download->NTSample.efs

-> order will be placed and and you will see some logging information in the output window

Hope this helps.

werosen
12-14-2005, 06:51 AM
OK, the NTSample.efs works this way.

However;

1. If I change the eSignal chart to AB #F it does not work. Are there some settings in NT that I need to change so I can use my normal setting of AB #F for this to work?

2. The prices in the Simulated feed do not match the prices in the eSignal feed. Are there some settings I need to change in NT to use the eSignal feed instead the Simulated feed so I can get accurate pricing for my testing?

Thanks,

Warren

werosen
12-14-2005, 11:17 AM
Through trial and error, it appears to me that the DDL connection only works if I initiate an order. When I load the NTSample.efs first that places an order when loaded, and then remove that file and load my efs file that doesn't place an order at all, then all the DLL calls work in my file. If I load my efs file first without loading NTSample first, then the DLL calls in my file do not work. If I put code in my file that fires a new order when it loads, then all mt DLL calls work even if it's the first file loaded.

I can't find anything in the documentation that refers to this. Is there some function that will initiate the DLL connection without firing an order first?

NinjaTrader_Dierk
12-14-2005, 04:04 PM
1) Continous contracts are not supported (see documentation).
2) Sim feed is what is says: simulated (random) data = no correlation to any real data provider.
3) So there must be bug in your efs file. Like I said below: Take NTSample.efs - since it finally works - and tweak it step by step.

werosen
12-14-2005, 04:08 PM
Do you have an answer for my last communication?

NinjaTrader_Dierk
12-14-2005, 04:24 PM
Not true. You may want to try the NTPlayback.efs which does not place orders at all. Please refer to the docs.

Thanks

werosen
12-14-2005, 04:59 PM
Based on your last response I'm not sure I am properly communicating the issue, so I will try a different approach. If I load the NTSample.efs file, a trade is initiated and the DLL calls work correctly. If I comment out the code in the NTSample.efs file that initiates a trade and only fire the code that displays the values returned in the Formula Output Window, it does not appear to work correctly.

After loading the modifiedfile, I am manually initiating a market order for 1 contract Longin the NT Control Center and that order is being filled. When I advance the eSignal Chart that is running the file by one bar to initiate another DLL call, all the NTfunctions return a value of 0, except OrderStatus, which is null. I would expect that NTMarketPosition("") would return a value of 1, not 0, to reflect the fact that I am 1 contract Long.

The modified code is as follows:

/* Copyright (c) 2005, NinjaTrader LLC ninjatrader@ninjatrader.com (mailto:ninjatrader@ninjatrader.com). All rights reserved. */

var dll = new DLL("NtDirect.dll");
var orderPlaced = false;
var printDone = false;

function preMain()
{
setPriceStudy(true);
setStudyTitle("NT Sample");
dll.addFunction("AvgEntryPrice", DLL.DOUBLE, DLL.STDCALL, "AvgEntryPrice", DLL.STRING, DLL.STRING);
dll.addFunction("AvgFillPrice", DLL.DOUBLE, DLL.STDCALL, "AvgFillPrice", DLL.STRING);
dll.addFunction("Command", DLL.INT, DLL.STDCALL, "Command", DLL.STRING, DLL.STRING, DLL.STRING, DLL.STRING, DLL.INT, DLL.STRING, DLL.DOUBLE,
DLL.DOUBLE, DLL.STRING, DLL.STRING, DLL.STRING, DLL.STRING, DLL.STRING);
dll.addFunction("Connected", DLL.INT, DLL.STDCALL, "Connected");
dll.addFunction("Filled", DLL.INT, DLL.STDCALL, "Filled", DLL.STRING);
dll.addFunction("GetDouble", DLL.DOUBLE, DLL.STDCALL, "GetDouble", DLL.STRING);
dll.addFunction("GetInt", DLL.INT, DLL.STDCALL, "GetInt", DLL.STRING);
dll.addFunction("GetString", DLL.STRING, DLL.STDCALL, "GetString", DLL.STRING);
dll.addFunction("MarketPosition", DLL.INT, DLL.STDCALL, "MarketPosition", DLL.STRING, DLL.STRING);
dll.addFunction("NewOrderId", DLL.STRING, DLL.STDCALL, "NewOrderId");
dll.addFunction("Orders", DLL.STRING, DLL.STDCALL, "Orders", DLL.STRING);
dll.addFunction("OrderStatus", DLL.STRING, DLL.STDCALL, "OrderStatus", DLL.STRING);
dll.addFunction("SetUp", DLL.INT, DLL.STDCALL, "SetUp", DLL.STRING, DLL.INT);
dll.addFunction("Strategies",DLL.STRING, DLL.STDCALL, "Strategies", DLL.STRING);
dll.addFunction("StrategyPosition", DLL.INT, DLL.STDCALL, "StrategyPosition", DLL.STRING);
dll.addFunction("TearDown", DLL.INT, DLL.STDCALL, "TearDown");
}

function main()
{

/*
if (isLastBarOnChart() && NTConnected())
{
if (!orderPlaced)
{
if (NTBuyMarket("MyOrderId", 1) == 0)// buy 1 unit at market, assign order id (optionally)
orderPlaced = true;
}
else
{
// print some information on the current position and order
debugPrint("Position size: " + NTMarketPosition("") + "\r\n");
debugPrint("AvgEntryPrice: " + NTAvgEntryPrice("") + "\r\n");
debugPrint("OrderStatus: " + NTOrderStatus("MyOrderId") + "\r\n");
debugPrint("Filled #: " + NTFilled("MyOrderId")+ "\r\n");
debugPrint("AvgFillPrice: " + NTAvgFillPrice("MyOrderId") + "\r\n");
}
}
*/
// print some information on the current position and order
debugClear()
debugPrint("Position size: " + NTMarketPosition("") + "\r\n");
debugPrint("AvgEntryPrice: " + NTAvgEntryPrice("") + "\r\n");
debugPrint("OrderStatus: " + NTOrderStatus("MyOrderId") + "\r\n");
debugPrint("Filled #: " + NTFilled("MyOrderId")+ "\r\n");
debugPrint("AvgFillPrice: " + NTAvgFillPrice("MyOrderId") + "\r\n");
}

// Get the average entry price of a position of an account. "account" is optional.
function NTAvgEntryPrice(account) {
return dll.call("AvgEntryPrice", getSymbol(), account);
}

// Get the average fill price of an order.
function NTAvgFillPrice(orderId) {
return dll.call("AvgFillPrice", orderId);
}

// Place a buy limit order. "orderId" is optional (set to "" it not applicable).
function NTBuyLimit(orderId, quantity, limitPrice) {
return NTCommand("Place", "", "Buy", quantity, "Limit", limitPrice, 0, "", "", orderId, "", "");
}

// Place a buy market order. "orderId" is optional (set to "" it not applicable).
function NTBuyMarket(orderId, quantity) {
return NTCommand("Place", "", "Buy", quantity, "Market", 0, 0, "", "", orderId, "", "");
}

// Place a buy stop order. "orderId" is optional (set to "" it not applicable).
function NTBuyStop(orderId, quantity, stopPrice) {
return NTCommand("Place", "", "Buy", quantity, "Stop", 0, stopPrice, "", "", orderId, "", "");
}

// Place a buy stop limit order. "orderId" is optional (set to "" it not applicable).
function NTBuyStopLimit(orderId, quantity, limitPrice, stopPrice) {
return NTCommand("Place", "", "Buy", quantity, "StopLimit", limitPrice, stopPrice, "", "", orderId, "", "");
}

// Cancel an order by its order id.
function NTCancel(orderId) {
return NTCommand("Cancel", "", "", 0, "", 0, 0, "", "", orderId, "", "");
}

// Cancel all orders at all accounts.
function NTCancelAllOrders() {
return NTCommand("CancelAllOrders", "", "", 0, "", 0, 0, "", "", "", "", "");
}

// Change an order by its order id.
function NTChange(orderId, quantity, limitPrice, stopPrice) {
return NTCommand("Change", "", "", quantity, "", limitPrice, stopPrice, "", "", orderId, "", "");
}

// Close any position of the current instrument at an account. "account" is optional (set to "" it not applicable).
function NTClosePosition(account) {
return NTCommand("ClosePosition", account, "", 0, "", 0, 0, "", "", "", "", "");
}

// Submits a NinjaTrader command.
function NTCommand(command, account, action, quantity, orderType, limitPrice, stopPrice, timeInForce, oco, orderId, template, strategy) {
return dll.call("Command", command, account, getSymbol(), action, quantity, orderType,
limitPrice, stopPrice, timeInForce, oco, orderId, template, strategy);
}

// Indicates if the connection to NinjaTrader is established. 0 = connected, -1 not connected.
function NTConnected() {
return (dll.call("Connected") == 0)
}

// Get the filled of an order.
function NTFilled(orderId) {
return dll.call("Filled", orderId);
}

// Close all positions and cancels all order at all account.
function NTFlattenEverything() {
return NTCommand("FlattenEverything", "", "", 0, "", 0, 0, "", "", "", "", "");
}

// Get a double value by its name.
function NTGetDouble(name) {
return dll.call("GetDouble", name);
}

// Get an integer value by its name.
function NTGetInt(name) {
return dll.call("GetInt", name);
}

// Get a string value by its name.
function NTGetString(name) {
return dll.call("GetString", name);
}

// Get the market position of the current instrument at an account. "account" is optional (set to "" it not applicable).
function NTMarketPosition(account) {
return dll.call("MarketPosition", getSymbol(), account);
}

// Get a new unqiue order id.
function NTNewOrderId() {
return dll.call("NewOrderId");
}

// Get a string of order IDs of all orders initiated through the ATI of an account separated by '|'.
function NTOrders(account) {
return dll.call("Orders", account);
}

// Get the current status of an order.
function NTOrderStatus(orderId) {
return dll.call("OrderStatus", orderId);
}

// Place a sell limit order. "orderId" is optional (set to "" it not applicable).
function NTSellLimit(orderId, quantity, limitPrice) {
return NTCommand("Place", "", "Sell", quantity, "Limit", limitPrice, 0, "", "", orderId, "", "");
}

// Place a sell market order. "orderId" is optional (set to "" it not applicable).
function NTSellMarket(orderId, quantity) {
return NTCommand("Place", "", "Sell", quantity, "Market", 0, 0, "", "", orderId, "", "");
}

// Place a sell stop order. "orderId" is optional (set to "" it not applicable).
function NTSellStop(orderId, quantity, stopPrice) {
return NTCommand("Place", "", "Sell", quantity, "Stop", 0, stopPrice, "", "", orderId, "", "");
}

// Place a sell stop limit order. "orderId" is optional (set to "" it not applicable).
function NTSellStopLimit(orderId, quantity, limitPrice, stopPrice) {
return NTCommand("Place", "", "Sell", quantity, "StopLimit", limitPrice, stopPrice, "", "", orderId, "", "");
}

// Gets a string of strategy IDs of all strategies of an account separated by '|'. Duplicate ID values can be returned if strategies were initiated outside of the ATI.
function NTStrategies(account) {
return dll.call("Strategies", account);
}

// Get the position of a strategy.
function NTStrategyPosition(strategyId) {
return dll.call("StrategyPosition", strategyId);
}

NinjaTrader_Dierk
12-14-2005, 05:32 PM
That is correct. At the ATI you only can expect to see order and position information of orders and positions entered through ATI and not from within NT.

werosen
12-14-2005, 06:02 PM
OK, that helps a lot to know that.

I have also figured outand tested a way torun the file in an AB #F eSignal chart. For your own reference, you would replace getSymbol() with getMySymbol() in the appropriate NTfunctions and includethe new function getMySymbol() below. Naturally, you would have to have the correct contract expiry date.

// Set function to return symbol format for NinjaTrader
function getMySymbol()
{
symbol = getSymbol();
if (symbol == "AB #F")
symbol = "AB H6";

return symbol;
}

NinjaTrader_Dierk
12-14-2005, 06:23 PM
Thanks for your code snipplet.

werosen
12-14-2005, 06:24 PM
I just placed a new order using the following:

NTCommand("Place","Sim101","ER2 03-06","Buy",1,"MARKET", 0, 0,"DAY","","","12TickBasic1","")

The Buy market order was executed and filled, but the Profit/Loss brackets were not placed. I do have a valid strategy template named 12TickBasic1.

I can't seem to find where the parameter are inconsistant with the documentation. Can you tell me what I've missed and why it did not execute the strategy?

werosen
12-14-2005, 06:49 PM
I was in error. The last piece of code I sent you for NTCommand to place an order did not fire at all, so it did not accept the market order. I'm still not sure what is wrong with the command. It seems to fit the documentation.

werosen
12-14-2005, 07:21 PM
I see that the DLL Interface Functions definition is different from the eSignal Functions definitions, so I changed the command to:

NTCommand("Place","Sim101","Buy",1,"MARKET",0,0,"DAY","","","12TickBasic1","")

But it still doesn't fire.

The line NTBuyMarket("MyOrderId", 1) does exexcute a trade from my file so I know there isn't a problem elsewhere in the file., but I'm at a loss as to why the NTCommand is not firing.

NinjaTrader_Dierk
12-14-2005, 07:55 PM
What do the logs say?

werosen
12-15-2005, 02:12 AM
The Log says:

AT, 'Place;Sim101;AB H6;Buy;1;MARKET;0;0;DAY;;;12TickBasic1;' processing

NinjaTrader_Dierk
12-15-2005, 05:11 AM
Is there any other log (please check an log option -> right click)? If not then I'm lost on that issue.

I would suggest this:
a) try using the IOF builder on the file interface and start from simple to complicated to see which combination of parameters work
b) then switch to the EFS file and apply these parameters

OR
a) start with NTSample.efs
b) insert NTCommand as replacement of the order submit methods and tweak it step by step

werosen
12-15-2005, 05:20 AM
I dont understand what you are asking me to do bY;

Is there any other log (please check an log option -> right click)?

Can you explain?

NinjaTrader_Dierk
12-15-2005, 05:22 AM
Is the log you posted the first in the window (Note: turn off any filtering)?

werosen
12-15-2005, 05:27 AM
Yes, it was the first (top) line in the log. I have no filtering applied to the log.

werosen
12-15-2005, 06:19 AM
If I put:

NTCommand("Place","Sim101","Buy",1,"MARKET",0,0,"DAY","","","12TickBasic1","")

in NTSample.efs in place of NTBuyMarket("MyOrderId", 1), then the Market Order will be filled and the Stop/Loss positions for the strategy will be placed, but all the debug lines

debugPrint("Position size: " + NTMarketPosition("") + "\r\n");
debugPrint("AvgEntryPrice: " + NTAvgEntryPrice("") + "\r\n");
debugPrint("OrderStatus: " + NTOrderStatus("MyOrderId") + "\r\n");
debugPrint("Filled #: " + NTFilled("MyOrderId")+ "\r\n");
debugPrint("AvgFillPrice: " + NTAvgFillPrice("MyOrderId") + "\r\n");

will return a value of 0, except for OrderStatus, which is null. If I remove the strategy name, it will fill the market order, but the debug lines still return 0. All the other values in the "Place' command are shown to be required in the documentation.

NinjaTrader_Dierk
12-15-2005, 06:40 AM
werosen wrote:
IIf I remove the strategy name, it will fill the market order, but the debug lines still return 0. All the other values in the "Place' command are shown to be required in the documentation.


Make this work first = make an NTCommand replacing the NTBuyMarket work first and then add the strategy.

werosen
12-15-2005, 06:41 AM
I'm not sure what the OIF builder tells me since I'm using the DLL. I took a look at it and there was a difference between what it generated and what was wrritten in the log as follows:

Log: AT, 'PLACE;SIM101;AB H6;BUY;1;MARKET;0;0;DAY;;;12TickBasic1;' processing

OIF Builder: PLACE;SIM101;ER2 03-06;BUY;1;MARKET;0;0;DAY;;;12TickBasic1;

The command line parameters and syntax match the eSignal Functions documentation exactly, and since it does not work properly in the NTSample.efs file, I don't know what to do at this point.

werosen
12-15-2005, 06:46 AM
The NTCommand with and without the strategy parameter has the same result in the NTSample.efs file in all me tests.

What would I do to the NTCommand that currently doen't work correctly without the strategy parameter, to make it work correctly?

werosen
12-15-2005, 06:49 AM
Here is the code for the NTSample.efs file that has an NTCommand replacing NTBuyMarket("MyOrderId", 1).

This will execute the order, but the other DLL calls return a value of 0 after the order is filled.

/* Copyright (c) 2005, NinjaTrader LLC ninjatrader@ninjatrader.com (mailto:ninjatrader@ninjatrader.com). All rights reserved. */

var dll = new DLL("NtDirect.dll");
var orderPlaced = false;
var printDone = false;

function preMain()
{
setPriceStudy(true);
setStudyTitle("NT Sample");
dll.addFunction("AvgEntryPrice", DLL.DOUBLE, DLL.STDCALL, "AvgEntryPrice", DLL.STRING, DLL.STRING);
dll.addFunction("AvgFillPrice", DLL.DOUBLE, DLL.STDCALL, "AvgFillPrice", DLL.STRING);
dll.addFunction("Command", DLL.INT, DLL.STDCALL, "Command", DLL.STRING, DLL.STRING, DLL.STRING, DLL.STRING, DLL.INT, DLL.STRING, DLL.DOUBLE,
DLL.DOUBLE, DLL.STRING, DLL.STRING, DLL.STRING, DLL.STRING, DLL.STRING);
dll.addFunction("Connected", DLL.INT, DLL.STDCALL, "Connected");
dll.addFunction("Filled", DLL.INT, DLL.STDCALL, "Filled", DLL.STRING);
dll.addFunction("GetDouble", DLL.DOUBLE, DLL.STDCALL, "GetDouble", DLL.STRING);
dll.addFunction("GetInt", DLL.INT, DLL.STDCALL, "GetInt", DLL.STRING);
dll.addFunction("GetString", DLL.STRING, DLL.STDCALL, "GetString", DLL.STRING);
dll.addFunction("MarketPosition", DLL.INT, DLL.STDCALL, "MarketPosition", DLL.STRING, DLL.STRING);
dll.addFunction("NewOrderId", DLL.STRING, DLL.STDCALL, "NewOrderId");
dll.addFunction("Orders", DLL.STRING, DLL.STDCALL, "Orders", DLL.STRING);
dll.addFunction("OrderStatus", DLL.STRING, DLL.STDCALL, "OrderStatus", DLL.STRING);
dll.addFunction("SetUp", DLL.INT, DLL.STDCALL, "SetUp", DLL.STRING, DLL.INT);
dll.addFunction("Strategies",DLL.STRING, DLL.STDCALL, "Strategies", DLL.STRING);
dll.addFunction("StrategyPosition", DLL.INT, DLL.STDCALL, "StrategyPosition", DLL.STRING);
dll.addFunction("TearDown", DLL.INT, DLL.STDCALL, "TearDown");
}

function main()
{
if (isLastBarOnChart() && NTConnected())
{
if (!orderPlaced)
{
// if (NTBuyMarket("MyOrderId", 1) == 0)// buy 1 unit at market, assign order id (optionally)
if (NTCommand("Place","Sim101","Buy",1,"MARKET",0,0,"DAY","","","","") == 0)
orderPlaced = true;
}
else
{
// print some information on the current position and order
debugPrint("Position size: " + NTMarketPosition("") + "\r\n");
debugPrint("AvgEntryPrice: " + NTAvgEntryPrice("") + "\r\n");
debugPrint("OrderStatus: " + NTOrderStatus("MyOrderId") + "\r\n");
debugPrint("Filled #: " + NTFilled("MyOrderId")+ "\r\n");
debugPrint("AvgFillPrice: " + NTAvgFillPrice("MyOrderId") + "\r\n");
}
}
}

// Get the average entry price of a position of an account. "account" is optional.
function NTAvgEntryPrice(account) {
return dll.call("AvgEntryPrice", getSymbol(), account);
}

// Get the average fill price of an order.
function NTAvgFillPrice(orderId) {
return dll.call("AvgFillPrice", orderId);
}

// Place a buy limit order. "orderId" is optional (set to "" it not applicable).
function NTBuyLimit(orderId, quantity, limitPrice) {
return NTCommand("Place", "", "Buy", quantity, "Limit", limitPrice, 0, "", "", orderId, "", "");
}

// Place a buy market order. "orderId" is optional (set to "" it not applicable).
function NTBuyMarket(orderId, quantity) {
return NTCommand("Place", "", "Buy", quantity, "Market", 0, 0, "", "", orderId, "", "");
}

// Place a buy stop order. "orderId" is optional (set to "" it not applicable).
function NTBuyStop(orderId, quantity, stopPrice) {
return NTCommand("Place", "", "Buy", quantity, "Stop", 0, stopPrice, "", "", orderId, "", "");
}

// Place a buy stop limit order. "orderId" is optional (set to "" it not applicable).
function NTBuyStopLimit(orderId, quantity, limitPrice, stopPrice) {
return NTCommand("Place", "", "Buy", quantity, "StopLimit", limitPrice, stopPrice, "", "", orderId, "", "");
}

// Cancel an order by its order id.
function NTCancel(orderId) {
return NTCommand("Cancel", "", "", 0, "", 0, 0, "", "", orderId, "", "");
}

// Cancel all orders at all accounts.
function NTCancelAllOrders() {
return NTCommand("CancelAllOrders", "", "", 0, "", 0, 0, "", "", "", "", "");
}

// Change an order by its order id.
function NTChange(orderId, quantity, limitPrice, stopPrice) {
return NTCommand("Change", "", "", quantity, "", limitPrice, stopPrice, "", "", orderId, "", "");
}

// Close any position of the current instrument at an account. "account" is optional (set to "" it not applicable).
function NTClosePosition(account) {
return NTCommand("ClosePosition", account, "", 0, "", 0, 0, "", "", "", "", "");
}

// Submits a NinjaTrader command.
function NTCommand(command, account, action, quantity, orderType, limitPrice, stopPrice, timeInForce, oco, orderId, template, strategy) {
return dll.call("Command", command, account, getSymbol(), action, quantity, orderType,
limitPrice, stopPrice, timeInForce, oco, orderId, template, strategy);
}

// Indicates if the connection to NinjaTrader is established. 0 = connected, -1 not connected.
function NTConnected() {
return (dll.call("Connected") == 0)
}

// Get the filled of an order.
function NTFilled(orderId) {
return dll.call("Filled", orderId);
}

// Close all positions and cancels all order at all account.
function NTFlattenEverything() {
return NTCommand("FlattenEverything", "", "", 0, "", 0, 0, "", "", "", "", "");
}

// Get a double value by its name.
function NTGetDouble(name) {
return dll.call("GetDouble", name);
}

// Get an integer value by its name.
function NTGetInt(name) {
return dll.call("GetInt", name);
}

// Get a string value by its name.
function NTGetString(name) {
return dll.call("GetString", name);
}

// Get the market position of the current instrument at an account. "account" is optional (set to "" it not applicable).
function NTMarketPosition(account) {
return dll.call("MarketPosition", getSymbol(), account);
}

// Get a new unqiue order id.
function NTNewOrderId() {
return dll.call("NewOrderId");
}

// Get a string of order IDs of all orders initiated through the ATI of an account separated by '|'.
function NTOrders(account) {
return dll.call("Orders", account);
}

// Get the current status of an order.
function NTOrderStatus(orderId) {
return dll.call("OrderStatus", orderId);
}

// Place a sell limit order. "orderId" is optional (set to "" it not applicable).
function NTSellLimit(orderId, quantity, limitPrice) {
return NTCommand("Place", "", "Sell", quantity, "Limit", limitPrice, 0, "", "", orderId, "", "");
}

// Place a sell market order. "orderId" is optional (set to "" it not applicable).
function NTSellMarket(orderId, quantity) {
return NTCommand("Place", "", "Sell", quantity, "Market", 0, 0, "", "", orderId, "", "");
}

// Place a sell stop order. "orderId" is optional (set to "" it not applicable).
function NTSellStop(orderId, quantity, stopPrice) {
return NTCommand("Place", "", "Sell", quantity, "Stop", 0, stopPrice, "", "", orderId, "", "");
}

// Place a sell stop limit order. "orderId" is optional (set to "" it not applicable).
function NTSellStopLimit(orderId, quantity, limitPrice, stopPrice) {
return NTCommand("Place", "", "Sell", quantity, "StopLimit", limitPrice, stopPrice, "", "", orderId, "", "");
}

// Gets a string of strategy IDs of all strategies of an account separated by '|'. Duplicate ID values can be returned if strategies were initiated outside of the ATI.
function NTStrategies(account) {
return dll.call("Strategies", account);
}

// Get the position of a strategy.
function NTStrategyPosition(strategyId) {
return dll.call("StrategyPosition", strategyId);
}

NinjaTrader_Dierk
12-15-2005, 06:58 AM
Then there is an error in your script
a) original script works as expected
b) you replaced NTBuyMarket and it's no longer working
-> replacement has an error

Again I want to advice you to do an exact (!) replacement first and next change parameter by parameter. Since you epxerience these issues, it does not make sense to change more than one thing at a time.

werosen
12-15-2005, 07:21 AM
Your documentation says that all the fields I am using are required. Are you suggesting that they are not required as stated in Commands and Vaild Parameters section?

If so, which parameters can I eliminate?

NinjaTrader_Dierk
12-15-2005, 07:38 AM
I suggest you go step by step:

- NTBuyMarket: NTCommand("Place", "", "Buy", quantity, "Market", 0, 0, "", "", orderId, "", "");

- your approach: NTCommand("Place","Sim101","Buy",1,"MARKET",0,0,"DAY","","","","")

There is more than one parameter different, no?

werosen
12-15-2005, 07:48 AM
The Buy market command in the NTSample file is:

NTBuyMarket("MyOrderId", 1)

The stucture for the NTCommand that is shown as required in your Commands and Valid Parameters document is:

NTCommand("Place","Sim101","Buy",1,"MARKET",0,0,"DAY","","","","")

What parameters in the above NTCommand are not required, even though your documentation says they are required?

NinjaTrader_Ray
12-15-2005, 09:01 AM
Please do this:

Your original function call is:

NTCommand("Place","Sim101","Buy",1,"MARKET",0,0,"DAY","","","12TickBasic1","")

change to this:

NTCommand("Place","","Buy",1,"MARKET",0,0,"DAY","","","","")

Does this work? If yes, then add the next parameter until you reach what part of the function call does not work for you. Then we know where your problem is and can then advise.

werosen
12-15-2005, 10:23 AM
The problem was inusing Sim101for the account parameter. By leaving it blank, everything works. When I put it back in, all the previous problems come back.

Furthermore, I have just now set up my live feed to my broker Alaron, and having done so, there are now 2 accounts available to choose from. Now that there are 2 accounts to choose from, when I use Sim101 as the account parameter, everything works properly, whereas passing the account parameter before caused malfunctions.

My conclusion is that when there is only one account in NT and you send an account parameter, then it causes problems. At least that was the case in all my testing. Hopefully it will be clear sailing from here.

Cheers

NinjaTrader_Ray
12-15-2005, 10:35 AM
Great.

For clarification, when you were having the problem, were you connected to eSignal or our Simulated Data Feed connection?

Ray

werosen
12-15-2005, 10:39 AM
The Simulated Data Feed.

werosen
12-15-2005, 10:52 AM
Sorry Ray, I spoke too soon.

It is not working when I use Sim101 for the account parameter, it only works when I leave the account parameter empty.

What now?

werosen
12-15-2005, 09:00 PM
More Info:

If I fire a tradeWITHOUT the account parameter, and it is the first trade I fire after opening NT,the trade will fire. If I theninsert the account number and reload the efs file, the trade will not fire. If I then take the account parameter back out and reload the efs file, the trade will then fire.

If I fire a tradeWITH the account parameter, and it is the first trade I fire after opening NT,the trade will fire. If I thenremove the account number and reload the efs file, the trade will not fire. If I thenput the account parameter back in and reload the efs file, the trade will then fire.

In other words, whichever format I use on the first trade that is fired after opening NT (with or without the account parameter) dictates whether or not the account parameter can be used in subsequent trades, and that state will remain in force until NT is closed and reopened.

So far all this testing is being done using the Sim101 account on the Simulated Data Feed. I am running eSignal 7.91 & NT 5.0.1000.5. All theefs filesare being run in the eSignal Bar Replay Mode.

NinjaTrader_Ray
12-16-2005, 01:45 AM
That is correct. That is how it should work. Will update the Help-->Guide.

werosen
12-16-2005, 01:54 AM
Good morning ninjatrader.

Thanks for the response, but which is correct? The functionality for my 1st question, or the way I set up the Account Connection for paper trading to Alaron, or both?

Warren

NinjaTrader_Ray
12-16-2005, 01:59 AM
Either is correct. Just stick to the same protocol. If you use empty string for account, then NT will use the Default account that is set under Tools-->Options. Anytime you make a function call, pass in empty string for account for the default account, pass in the account name for any other account.

werosen
12-16-2005, 02:20 AM
When I use an Account parameter in my NTCommand for 'Place", the NTMarketPosition always returns 0 in both my file and the NTSample.efs file after the order is filed. When I place an order and it is filled without using an Account parameter, then both files correctly return a value for NTMarketPosition showing the number of contracts filled.

Any ideas why it's not working with an Account parameter?

NinjaTrader_Ray
12-16-2005, 04:02 AM
Whatever account name (real name or empty string) that is usedin the first function call to place an order needs to be used in subsquent data retrieval calls otherwise you will get a zero if you have a position open.

Here is what I highly recommend. Set your Default account under Tools-->Option, Misc tab to Sim101.

In your EFS, anytime you want to send an order to, or get information from the Sim101 account, pass in an empty string into the account parameter.

In your EFS, anytime you want send an order to, or get informatino from a live account, passing the account name into the account parameter.

Ray

werosen
12-16-2005, 04:40 AM
Thanks Ray:

I did figured that out about an hour ago and I think all your functionality will work quite well within the context of my application. I think the missing piece of the puzzle in my problems all along revolves around the fact that I didn't understand how your DLL was initialized relative to the use of the Account parameter, and if I had understood that from the start, I probably would have avoided about 90% of my issues. But the effort to get to this point has been worthwhile in acquiring the depth of knowledge about the NT platform in general. I belong to a large ad hoc trading association that will be watching my success in completing an automated interface from eSignal to NT and am sure that many of the traders will switch to NT based on my experience. I think I'll be able to start testing a completed platform by Monday.

With regards to another issue, I sent some account related questions tothe support email yesterday, but have had no response.I'd appreciate it if you could get me the answers. Following is the body of that email.

Thanks again foryour assistance.

Warren

Hello:

I have just set up NinjaTrader with my broker Alaron, and I have a few questions.

1. If I Connect to Alaron and then Disconnect, when I try and reconnect again I get a message that says I have to close NT completely and reopen it to reconnect. Is it supposed to work this way?

2. I set up a second Account Connection to Alaron in NT that is identical to the first one, except I selected "Test" for the Server Type, but the Alaron server will not accept the connection. Is there something else I need to do to be able to 'paper trade' on my Alaron connection?

Regards,
Warren Rosenfeld

NinjaTrader_Ray
12-16-2005, 06:36 AM
No problem.

I am glad that you have found the experience worthwhile, we have as well. What we will do for the next update is add documentation regarding how the ATI is initialized.

Now the anwers to your questions:

1) This is a bug in the Patsystems API. Upon disconnect the DLL must be unloaded and therefore we have to shut down the application. That is our only work around.

2) Papertrading on your alaron account can only be done using our internal simulation account which is the Sim101 account. You only need one Alaron connection set to Live (TEST is really reserved for developers) and then set your systems to only send ordes to the Sim101 account. As a safety measure, enable "Global Simulation Mode" via the File menu. This will ensure that NO orders will ever be sent to your live Alaron account by accident.

Ray

werosen
12-16-2005, 06:59 AM
OK, I understand. Now I have a new issue:

If I initiate an order with a unique orderId and NO strategy template nameas follows:

NTCommand("Place","Sim101","BUY",1,"LIMIT",679.20,0,"DAY","3890","","","")

I can use the ID in NTOrderStaus("3890") & NTFilled("3890") and they will return the correct values:

If I add a strategy template name and initate an order as follows:

NTCommand("Place","Sim101","BUY",1,"LIMIT",679.20,0,"DAY","3891","","12TickBasic1","")

The brackets will be properly placed, but the NTOrderStaus("3891") & NTFilled("3891") functions will no longer return a value.

Can you tell me how to correct this so I can use both an orderId and a strategy template name?

Furthermore:

If I initiate an order with a strategy template name & NO orderId as follows:

NTCommand("Place","Sim101","BUY",1,"LIMIT",679.20,0,"DAY","","","12TickBasic1","")

and try and use NTOrderStaus("ENTRY") & NTFilled("ENTRY") or NTOrderStaus("TARGET1") & NTFilled("STOP2"), then no values are returned by these functions.

Your documentation for PLACE COMMAND in 'Commands and Valid Parameters' states: "If specifying a strategy template name, there is no need to pass in an order id as the strategy based orders can be referenced by their internally generated names such as TARGET1, STOP1 and so on."

Can you explain why the function do not work when these names are used?

aspTrader
12-17-2005, 12:40 AM
werosen wrote:
The prices in the Simulated feed do not match the prices in the eSignal feed. Are there some settings I need to change in NT to use the eSignal feed instead the Simulated feed so I can get accurate pricing for my testing?

I have found that the eSignal Last, Bid, Ask price closely matches the Ninja Trader Pats Last, Bid, Ask.

I believe there is an issue when running the Ninja Trader External Data Feed. The SuperDOM Bid and Ask Sizes do not match the Control Center Bid/Ask Sizes and the External Data Feed source sizes. When running Pats, however, the Control Center Bid/Ask sizes and the SuperDOM Bid/Ask sizes DO match.

NinjaTrader_Ray
12-17-2005, 08:41 AM
The ATI works correctly as designed but I could have (and now will) clarify the documentation for the Place command.

When using initiating a strategy using the ATI, orders associated to that strategy can't be referenced by order name or orderId except in the NTCancel and NTChange methods.

So for clarification, you can't get fill or status information on stop/target/entry or exit orders. Will add to list.

I may change the entry order logic so you can reference it by the order id passed in in the Place command.

Ray

aspTrader
12-17-2005, 01:03 PM
Hi Ray and Dierk,

What's really needed is access from the ATI calling application to ALL orders and ALL their properties regardless of their origin.

There is no way for you to predict in advance what data ATI users will find they need and what data it will turn out that they never need.

The path to a clean design and a world class Automated Trade Interface is clear:

Don't decide for automated system developers what we should have access to and what we shouldn't have access to. Provide us with access to ALL the data and functionality of the Ninja Trader platform and let us decide for ourselves what we need in our systems.

NinjaTrader_Dierk
12-17-2005, 10:54 PM
aspTrader wrote:
Hi Ray and Dierk,
...

Don't decide for automated system developers what we should have access to and what we shouldn't have access to. Provide us with access to ALL the data and functionality of the Ninja Trader platform and let us decide for ourselves what we need in our systems.

To clarify: It is not our intention to decide for you what you want to use.

Let me try to provide you a more complete picture:
a) as you know there are the ATI functions right now
b) additionally we do have the NT framework as a full-fledged set of .NET based order management features

Right now we are about to learn to what extend (a) makes sense for users opposed to just using (b). This is area of learning to us. Please provide us with feedback (as you did) and give us some time to think about the situation and how we need to improve both alternatives.

Our concern always is (and was) to address our customer's requirements properly.

Thanks

werosen
12-18-2005, 02:52 AM
You responded:

"When using initiating a strategy using the ATI, orders associated to that strategy can't be referenced by order name or orderId except in the NTCancel and NTChange methods."

However, when I use:

NTCancel("ENTRY")

after an order is placed with:

NTCommand("Place","Sim101","BUY",1,"LIMIT", 688.50, 0,"DAY","","","12TickBasic1","")

and the order is accepted, but not yet filled,

The log returns:

OIF, 'Cancel;;AB H6;;0;;0;0;;;ENTRY;;' order with ID/Name'ENTRY' does not exist

The Unfilled order is displayed in the Basic Entry Window with the name 'Entry'

Please advise. I must complete this programming today.

werosen
12-18-2005, 03:40 AM
So as not to leave 'no stone unturned', I also submitted the order line with an orderId and got the same result.

NinjaTrader_Ray
12-18-2005, 12:46 PM
Use "ENTRY1"

werosen
12-18-2005, 01:12 PM
Entry1 works in the NTCommand Cancel and ONLY if you pass a Strategy ID with the original order, and Use that Startegy ID with the NTCommand Cancel.

It does NOT work with the NTCancel() function, butsince I have found a waythatit will work, even though it doesn't work the other way, I'll take it at this point.