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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    87 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    128 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    65 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    117 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X