Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to modify an indicator variable from a strategy file

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

    How to modify an indicator variable from a strategy file

    As the title suggests, I am trying to modify an indicator public variable from my strategy file to make the indicator change it's behavior slightly, but it does not allow me to do anything without a reference error.

    When I try assigning a public variable of my indicator, it says "Object reference not set to instance of an object". I have tried making the variables ninja script properties, making a wrapper and using get / set method around a private variable, and just declaring the class variables themselves as public but none seem to be working because of the object reference error. I am working with simple boolean value variables.

    Indicator has code like:
    public class PriceActionTrend : Indicator
    {

    public bool LookingForOneMinBos = true;
    ...
    }


    Strategy Code:
    Declared in class:
    private PriceActionTrend OverallTrend;

    ​In State.Configure:
    OverallTrend = PriceActionTrend(60, false, 20, 2, 10);

    In OnBarUpdate:
    OverallTrend.LookingForOneMinBos = false; // THIS does not work, get error.

    #2
    Ah man, so I'm not 100% sure how it got fixed, but after I tried enabling debug mode and using visual studio debugger live and stepping through, it just didn't crash anymore when I tried to assign the variable values directly (OverallTrend.LookingForOneMinBos = false - this now works in my strategy file.

    In my indicator the variables are still just public variables of the class as I outlined in my original post. They are NOT ninjascript property variables. I do have a multi-timeframe strategy but that seems to have nothing to do with how it is suddenly working, very weird. My indicator is still being created the same way in Configure state and I use AddChartIndicator, as I always had.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    43 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    30 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    40 views
    0 likes
    Last Post CarlTrading  
    Working...
    X