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

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,

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by TraderBCL, Today, 04:38 AM
            2 responses
            11 views
            0 likes
            Last Post TraderBCL  
            Started by martin70, 03-24-2023, 04:58 AM
            14 responses
            105 views
            0 likes
            Last Post martin70  
            Started by Radano, 06-10-2021, 01:40 AM
            19 responses
            606 views
            0 likes
            Last Post Radano
            by Radano
             
            Started by KenneGaray, Today, 03:48 AM
            0 responses
            4 views
            0 likes
            Last Post KenneGaray  
            Started by thanajo, 05-04-2021, 02:11 AM
            4 responses
            471 views
            0 likes
            Last Post tradingnasdaqprueba  
            Working...
            X