Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MarketPosition and OnStateChange() Function

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

    MarketPosition and OnStateChange() Function

    Hi all,
    I have to configure a strategy which was coded 2 years ago for one of my friend.
    The code checks the market position and state with if blocks but I get CS0019 errors when I try to compile. I added the sample codes below.

    Code Samples
    if (((NinjaTrader.NinjaScript.NinjaScript) this).State == 1) ...
    if (((NinjaTrader.NinjaScript.NinjaScript) this).State != 2) ...
    if (((StrategyBase) this).Position.MarketPosition != 2) ...
    else if (((StrategyBase) this).Position.MarketPosition == 1) ...

    I want to learn the property values that I can use instead of 1 and 2.
    (Does 1 refer to Historical or Terminated or sth. else for the State? Does 2 refer to MarketPosition.Long or Short or Flat?)
    Thanks in advance.

    #2
    Hello myxappem,

    The code you provided is not valid, you are trying to compare a State and a Position to an Int, you would need to use the correct code like shown in the example pages for these items. I have linked those pages below.

    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.

    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by kinfxhk, 07-13-2026, 10:18 AM
    0 responses
    57 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 07-13-2026, 09:50 AM
    0 responses
    39 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 07-13-2026, 07:21 AM
    0 responses
    45 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 07-11-2026, 02:11 AM
    0 responses
    35 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    153 views
    0 likes
    Last Post SalmaTrader  
    Working...
    X