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 NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    62 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    134 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    75 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    50 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X