Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do i get current market position in OnStateChange?

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

    How do i get current market position in OnStateChange?

    In OnStateChange I am trying to print the current market position like this:

    PHP Code:
    } else if (State == State.DataLoaded) {
        if (Position == null) {
            Print(" Position is null");
        } else {
            Print(" Position is "+Position);
        }
        Print(" market position is ");
        Print(Position.MarketPosition);
    } 
    
    This is telling me that Position is null and it throws an error:

    Strategy 'SimpleTestStrategy': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.

    So how can I get the initial position of a strategy? Do I just always assume it is Flat?

    #2
    Hello westofpluto, thanks for writing in.

    You would need to check this property in either State.Historical or State.Transition:

    Add these the If-Else chain in OnStateChanged:

    Code:
    else if(State == State.Transition)
    {
        // if(Position != null)
        // {
            // Print(Position.MarketPosition); // Transistion from historical to real time. 
        // }
    }
    else if(State == State.Historical)
    {
        if(Position != null)
        {
            Print(Position.MarketPosition); //Start of the historical data
        }
    }
    Please let me know if I can assist any further.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    90 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    135 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X