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

How to check Account Market Position for specific instrument?

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

    How to check Account Market Position for specific instrument?

    Hi,

    I know that if I run the same strategy on say, 4 different ES charts (ie. 2-min, 5-min, 30-min, 60-min), but I want to open a position in any of those charts only when I am flat in my account, I would use PositionAccount.MarketPosition == MarketPosition.Flat before entering a position. That way, there would be no possibility of me accidentally going short ES on one chart while being long in another (and thus ending up flat altogether).

    However, what if I want to add 4 more charts with this same strategy but on a different instrument? Let's say oil (CL). Now, I would want to know, before opening a position, whether I was flat IN THAT PARTICULAR INSTRUMENT. How would I go about doing this? What would be the line of code that would query my ACCOUNT market position for a specific instrument?

    Thank you in advance! This forum is great!


    #2
    Hi Mike0405, thanks for your post.

    The PositionsAccount object will keep track of this. Its an array and will hold info on all of the instruments you have a position in:




    e.g.
    Code:
    for(int i = 0; i < PositionsAccount.Length; i++)
                    Print(PositionsAccount[i].MarketPosition);
    You can also edit the strategy so that it works upon two instruments at once, this might be more straight forward. Heres a guide on multi time frame and instrument scripts:



    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by DavidHP, Today, 07:56 AM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by kujista, Today, 06:23 AM
    3 responses
    9 views
    0 likes
    Last Post kujista
    by kujista
     
    Started by Mindset, Yesterday, 02:04 AM
    2 responses
    18 views
    0 likes
    Last Post NinjaTrader_RyanS  
    Started by f.saeidi, Today, 08:03 AM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by samish18, 04-17-2024, 08:57 AM
    15 responses
    54 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Working...
    X