• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position By Name In Indicator?

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

    Position By Name In Indicator?

    NT7 Support,
    I have built a couple of indicators that track the profit/loss of my strategies by market position on whether they are long or short using the following in the indicator

    "if (account.Positions != null)
    {
    NinjaTrader.Cbi.PositionCollection positions = account.Positions;
    //Print("positions " + positions);

    foreach(NinjaTrader.Cbi.Position position in positions)
    {
    if (position.MarketPosition == MarketPosition.Long)
    {........"

    I am trying to fork over similar code to track my positions in an indicator based on the entry name. How can I call the strategy position by its signalName in an indicator?

    #2
    Hello,

    Thank you for the post.

    Using the Positions collections specifically I don't believe this would be possible. The Position object does not contain the executions that created that position.

    Using the executions collection you could get the Name and other information of the execution to calculate a position from the various executions.

    Code:
    foreach(NinjaTrader.Cbi.Execution execution in account.Executions)
    {
    	Print(execution.Name);
    }

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

    Comment


      #3
      Thanks Jesse.

      That worked and its humming along! Appreciate the fast response!

      Comment


        #4
        Jesse,

        After further testing it appears this is not solving my problem fully.

        An example of how I am programming my indicator is as follows
        -if execution.Name == "Strategy1"
        {
        do something
        }

        -if exeuction.Name == "Strategy2"
        {
        do something
        }

        With the execution.Name code provided if the day's session has had a trade opened for Strategy1 && Strategy2 it continues... But I am only looking to track open positions and not the days session of trades.

        Is it possible to have execution.Name from the database cleared after the trade is closed? Or is there some other method for calling a position name only by the open position and not historical (session) data?

        Comment


          #5
          Hello,

          Thank you for the reply.

          What you are currently doing is undocumented/unsupported so you would need to likely solve this with logic. NT7 was not really intended to be used in this way although it technically is possible. Because you are working with all of the executions you would need to add any filters you need with logic.

          If you are only looking for the open position, you would likely need to omit the prior executions that no longer apply to that position with logic. You could potentially do this by checking the time of the execution or having the strategy provide unique entry names with a prefix, for example, Strategy1_1, Strategy1_2 etc.. Moving from historical to realtime you could possibly get the Count of the collection to know how many Historical executions were submitted to omit them when running in realtime. Really this would be something you would need to work around for the purpose as there is no direct method to pull a position by a signal name, nor is there a method to access the executions from a position.

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

          Comment


            #6
            Originally posted by Cpuerta View Post
            Or is there some other method for calling a position name only by the open position and not historical (session) data?
            Since you've shown interest in this area, I'll point out the undocumented
            goodies in the EmailTrades.cs script discussed in this thread,

            https://ninjatrader.com/support/foru...ad.php?t=65186

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by jamesthomas11, Today, 05:00 AM
            1 response
            6 views
            0 likes
            Last Post sledge
            by sledge
             
            Started by zextra, Today, 04:22 AM
            0 responses
            4 views
            0 likes
            Last Post zextra
            by zextra
             
            Started by kevinenergy, Yesterday, 05:13 PM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_EricB  
            Started by yknuser, Yesterday, 09:18 PM
            2 responses
            14 views
            0 likes
            Last Post yknuser
            by yknuser
             
            Started by istock999, Yesterday, 04:30 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_ChrisSch  
            Working...
            X