Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Show entry/exit trades with a connected line between them

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

    Show entry/exit trades with a connected line between them

    Hi there,

    I'd like to write an indicator which draws lines connecting the entry/exit positions of each manually executed trade (with ATM) as shown in the picture below (which was manually drawn).

    I've read through the NT Indicator Tutorials but none make reference to variables for trade entry/exit positions. Also, I had a quick look through the Language Reference and similarly there seems to be no methods/variables which reference the entry/exit positions of trades executed.

    Q1. Could anyone who has knowledge or NT programming tell me if what I am trying to do is even possible in the constraints of the methods/variables which are available?

    Q2. And if it is (which I hope it is!) perhaps point me in the right direction on how to tackle this? I think if I could program this it would be useful to a lot of people judging on how may requests I found on google.

    Lastly: I found a post here where there was a coded solution, but for trade station. I'm hoping to be able to replicate this in NT.



    Thank-you
    Michelle
    Last edited by michelle99; 08-15-2016, 01:04 AM.

    #2
    Hello,

    Thank you for the question.

    To answer your Q1, This is possible but is outside of the constraints or "Documented/Supported" items in the helpguide.

    There would not be any documentation or samples on this subject specifically because Indicators are not associated with an Account. This would also hold true for a Strategy as you indicate this would be for Manual orders. All NinjaScript types that can access Account order information would be specific to the selected Account and would only be limited to trades that script places.

    You could get around this using unsupported code, I will post a small sample below but please note that the sample is unsupported and undocumented meaning there is no expectations for the code to work correctly. Please use at your own risk and ensure to test the syntax you end up using if it is undocumented/unsupported code.

    Code:
    private Account simAccount;
    
    protected override void OnStartUp()
    {
    	foreach (NinjaTrader.Cbi.Account account in NinjaTrader.Cbi.Globals.Accounts)
    	{
    		if (account.Name == "Sim101")
    		{
    			simAccount = account;
    			simAccount.Execution += OnExecution;
    			simAccount.OrderStatus += OnOrderStatus;
    			simAccount.PositionUpdate += OnPosition;
    			simAccount.Connection.ConnectionStatus += OnConnection;
    			break;
    		}
    	}
    }
    
    private void OnExecution(object sender, ExecutionUpdateEventArgs e)
    {
    	Print("OnExecution: " + e.Execution.ToString());
    }
    
    private void OnOrderStatus(object sender, OrderStatusEventArgs e)
    {
    	Print("OnOrderStatus: " + e.Order.ToString());
    }
    
    private void OnPosition(object sender, PositionUpdateEventArgs e)
    {
    	Print("OnPosition: " + e.Position.ToString());
    }
    
    private void OnConnection(object sender, ConnectionStatusEventArgs e)
    {
    	Print("OnConnection: " + e.Connection.ToString());
    }
    
    protected override void OnTermination()
    {
    	if (simAccount != null)
    	{
    		simAccount.Execution -= OnExecution;
    		simAccount.OrderStatus -= OnOrderStatus;
    		simAccount.PositionUpdate -= OnPosition;
    		simAccount.Connection.ConnectionStatus -= OnConnection;
    	}
    }
    The script results in Printing the order information from an indciator by means of Subscribing to the Accounts order Events.

    I look forward to being of further assistance.
    Attached Files
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank-you for your code sample Jesse. I added the indicator your coded to my chart and then placed a trade in SIM101. Unfortunately I did not see anything on the chart, it appears the sample code is faulty(?)
      Attached Files
      Last edited by michelle99; 08-18-2016, 05:41 AM.

      Comment


        #4
        Hello,

        The sample is not faulty, you would need to utilize the Output window to see the output.

        As stated in my post, this sample Prints the order information. You can also see in the code how the script will output the data by reading the syntax used. It contains Print("") statements which would go to the Tools -> Output Window. You would need to open the Tools -> Output window and then place an order to see the output.

        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          I want to print the account name of the account that is running the ninjascript strategy. Is there a status field? How do I see the Globals.Accounts data structure?

          I just want to print("account.Name" + account.Name); and not cycle through all the accounts.

          Comment


            #6
            Got it from another post. Not sure why it works, but syntax is Print("Curr Acct: " + Account.Name);

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DJ888, 04-16-2024, 06:09 PM
            4 responses
            12 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by terofs, Today, 04:18 PM
            0 responses
            5 views
            0 likes
            Last Post terofs
            by terofs
             
            Started by nandhumca, Today, 03:41 PM
            0 responses
            5 views
            0 likes
            Last Post nandhumca  
            Started by The_Sec, Today, 03:37 PM
            0 responses
            3 views
            0 likes
            Last Post The_Sec
            by The_Sec
             
            Started by GwFutures1988, Today, 02:48 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Working...
            X