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.STRING);
dll.addFunction("BuyingPower", DLL.String, DLL.STDCALL, "BuyingPower", DLL.DOUBLE);
dll.addFunction("CashValue", DLL.String, DLL.STDCALL, "CashValue", DLL.DOUBLE);
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("ConfirmOrders", DLL.INT, DLL.STDCALL, "ConfirmOrders", DLL.INT);
dll.addFunction("Connected", DLL.INT, DLL.STDCALL, "Connected", DLL.INT);
dll.addFunction("Filled", DLL.INT, DLL.STDCALL, "Filled", DLL.STRING, 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.STRING);
dll.addFunction("RealizedPnL", DLL.STRING, DLL.STDCALL, "RealizedPnL", DLL.DOUBLE);
dll.addFunction("SetUp", DLL.INT, DLL.STDCALL, "SetUp", DLL.STRING, DLL.INT);
dll.addFunction("StopOrders", DLL.STRING, DLL.STDCALL, "StopOrders", DLL.STRING);
dll.addFunction("Strategies", DLL.STRING, DLL.STDCALL, "Strategies", DLL.STRING);
dll.addFunction("StrategyPosition", DLL.INT, DLL.STDCALL, "StrategyPosition", DLL.STRING);
dll.addFunction("TargetOrders", DLL.STRING, DLL.STDCALL, "TargetOrders", DLL.STRING);
dll.addFunction("TearDown", DLL.INT, DLL.STDCALL, "TearDown");
}
function main()
{
if (isLastBarOnChart() && NTConnected(1))
{
if (!orderPlaced)
{
if (NTBuyMarket("MyOrderId", 1) == 0)
orderPlaced = true;
}
else
{
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");
debugPrint("RealizedPnL: " + NTRealizedPnL("") + "\r\n");
}
}
}
function NTAvgEntryPrice(account) {
return dll.call("AvgEntryPrice", getSymbol(), account);
}
function NTAvgFillPrice(orderId) {
return dll.call("AvgFillPrice", orderId, account);
}
function NTBuyingPower(account) {
return dll.call("BuyingPower", account);
}
function NTBuyLimit(orderId, quantity, limitPrice) {
return NTCommand("Place", "", "Buy", quantity, "Limit", limitPrice, 0, "", "", orderId, "", "");
}
function NTBuyMarket(orderId, quantity) {
return NTCommand("Place", "", "Buy", quantity, "Market", 0, 0, "", "", orderId, "", "");
}
function NTBuyStop(orderId, quantity, stopPrice){
return NTCommand("Place", "", "Buy", quantity, "Stop", 0, stopPrice, "", "", orderId, "", "");
}
function NTCancel(orderId) {
return NTCommand("Cancel", "", "", 0, "", 0, 0, "", "", orderId, "", "");
}
function NTCancelAllOrders() {
return NTCommand("CancelAllOrders", "", "", 0, "", 0, 0, "", "", "", "", "");
}
function NTCashValue(account) {
return dll.call("CashValue", account);
}
function NTChange(orderId, quantity, limitPrice, stopPrice) {
return NTCommand("Change", "", "", quantity, "", limitPrice, stopPrice, "", "", orderId, "", "");
}
function NTClosePosition(account) {
return NTCommand("ClosePosition", account, "", 0, "", 0, 0, "", "", "", "", "");
}
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);
}
function NTConnected() {
return (dll.call("Connected") == 0)
}
function NTFilled(orderId) {
return dll.call("Filled", orderId, account);
}
function NTFlattenEverything() {
return NTCommand("FlattenEverything", "", "", 0, "", 0, 0, "", "", "", "", "");
}
function NTGetDouble(name) {
return dll.call("GetDouble", name);
}
function NTGetInt(name) {
return dll.call("GetInt", name);
}
function NTGetString(name) {
return dll.call("GetString", name);
}
function NTMarketPosition(account) {
return dll.call("MarketPosition", getSymbol(), account);
}
function NTNewOrderId() {
return dll.call("NewOrderId");
}
function NTOrders(account) {
return dll.call("Orders", account);
}
function NTOrderStatus(orderId) {
return dll.call("OrderStatus", orderId, account);
}
function NTRealizedPnL(account) {
return dll.call("RealizedPnL", account);
}
function NTSellLimit(orderId, quantity, limitPrice) {
return NTCommand("Place", "", "Sell", quantity, "Limit", limitPrice, 0, "", "", orderId, "", "");
}
function NTSellMarket(orderId, quantity) {
return NTCommand("Place", "", "Sell", quantity, "Market", 0, 0, "", "", orderId, "", "");
}
function NTSellStop(orderId, quantity, stopPrice) {
return NTCommand("Place", "", "Sell", quantity, "Stop", 0, stopPrice, "", "", orderId, "", "");
}
function NTSellStopLimit(orderId, quantity, limitPrice, stopPrice) {
return NTCommand("Place", "", "Sell", quantity, "StopLimit", limitPrice, stopPrice, "", "", orderId, "", "");
}
function NTStopOrders(strategyId) {
return dll.call("StopOrders", strategyId);
}
function NTStrategies(account) {
return dll.call("Strategies", account);
}
function NTStrategyPosition(strategyId) {
return dll.call("StrategyPosition", strategyId);
}
function NTTargetOrders(strategyId) {
return dll.call("TargetOrders", strategyId);
}
|