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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      57 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      30 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      41 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      58 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      47 views
      0 likes
      Last Post CarlTrading  
      Working...
      X