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 CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    52 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    29 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    194 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    355 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    274 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X