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.MarketPosition from an indicator -> doesn't work

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

    Position.MarketPosition from an indicator -> doesn't work

    Hi,

    I'm trying to obtain information about a running strategy and the account.
    I have a strategy running, and in paralell I put an indicator sending messages to me when a new order is sent.
    I do get the information from the strategy (direction, volume and position of the strategy), but when I try to get the information from the account it doesn't work to me.

    Is because I'm doing it from an indicator?, should I do it from a strategy?

    I'm running the strategy on the main instrument (YM) in SIM, and sending the real orders to MYM..., because of that I have to check both the strategy and the real account.

    Thanks!

    #2
    Hello artson,

    Thank you for your note.

    Position.MarketPosition would only work within a Strategy as it specifically is referencing the strategy position. From within an indicator to get the account position you'd need to look through the collection of accounts and positions using Add-on code:

    private Account myAccount;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    // Find our Sim101 account
    lock (Account.All)
    myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim101");
    }

    if (State == State.DataLoaded)
    {
    lock (myAccount.Positions)
    {
    Print("Positions in State.DataLoaded:");

    foreach (Position position in myAccount.Positions)
    {
    Print(String.Format("Position: {0} at {1}", position.MarketPosition, position.AveragePrice));
    }
    }
    }
    }





    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by chbruno, 04-24-2024, 04:10 PM
    4 responses
    50 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    10 responses
    397 views
    1 like
    Last Post beobast
    by beobast
     
    Started by lorem, Yesterday, 09:18 AM
    5 responses
    19 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by WHICKED, Today, 12:56 PM
    2 responses
    15 views
    0 likes
    Last Post WHICKED
    by WHICKED
     
    Started by Felix Reichert, Today, 02:12 PM
    0 responses
    4 views
    0 likes
    Last Post Felix Reichert  
    Working...
    X