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 charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      55 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      142 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      160 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      96 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      276 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X