Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

use Positions[0].MarketPosition

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

    use Positions[0].MarketPosition

    Hi,

    I want to use Positions[0].MarketPosition as an argument in a method and then in the method, compare it to an integer value.

    I'm trying to see if there is a certain number (for example 2) of contracts open. I figured Positions[0].MarketPosition would be an integer (positive for long, negative for short, 0 for flat). That didn't work.

    I'm doing something like this in the method:

    public bool Symbol1Done(int cons1, int position)
    {
    if (OrderType == 1 && cons1 == position)
    {
    Symbol1Filled = true;
    return (true);
    }
    else
    {
    return (false);
    }
    }

    What is the type and how do I compare it to an integer?

    Thank you!

    Folls

    #2
    Hi Folls,

    The type MarketPosition returns is a MarketPosition type. This means you want to compare it to things like MarketPosition.Long or MarketPosition.Short instead of an int.

    Code:
    if (Positions[0].MarketPosition == MarketPosition.Long)
         // Do something
    http://www.ninjatrader-support.com/H...tPosition.html

    To determine the number of contracts you have in a position you can use the .Quantity property.

    Code:
    if (Positions[0].Quantity > 1)
         // Do something
    http://www.ninjatrader-support.com/H.../Quantity.html
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Great reply!

      Thanks. That was a very detailed, thoughtful reply.

      Folls

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      633 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      364 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      567 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      568 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X