Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

eSignal DDL function format

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    eSignal DDL function format

    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

    #2
    imported post

    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

    Comment


      #3
      imported post

      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?

      Comment


        #4
        imported post

        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

        Comment


          #5
          imported post

          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.

          Comment


            #6
            imported post

            When I load NTSample.efs into my chart it returns:

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

            Comment


              #7
              imported post

              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.

              Comment


                #8
                imported post

                Aditional Info:

                NTStrategies("Sim101") returns no value.

                Comment


                  #9
                  imported post

                  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.

                  Comment


                    #10
                    imported post

                    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

                    Comment


                      #11
                      imported post

                      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?

                      Comment


                        #12
                        imported post

                        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.

                        Comment


                          #13
                          imported post

                          Do you have an answer for my last communication?

                          Comment


                            #14
                            imported post

                            Not true. You may want to try the NTPlayback.efs which does not place orders at all. Please refer to the docs.

                            Thanks

                            Comment


                              #15
                              imported post

                              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 [email protected]. 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);
                              }


                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by arvidvanstaey, Today, 02:19 PM
                              4 responses
                              11 views
                              0 likes
                              Last Post arvidvanstaey  
                              Started by samish18, 04-17-2024, 08:57 AM
                              16 responses
                              61 views
                              0 likes
                              Last Post samish18  
                              Started by jordanq2, Today, 03:10 PM
                              2 responses
                              9 views
                              0 likes
                              Last Post jordanq2  
                              Started by traderqz, Today, 12:06 AM
                              10 responses
                              18 views
                              0 likes
                              Last Post traderqz  
                              Started by algospoke, 04-17-2024, 06:40 PM
                              5 responses
                              48 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X