Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Proper Indicator Initialization and Call

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

    Proper Indicator Initialization and Call

    Hi, I have a question regarding the proper way to initialize and call indicator variables because the examples aren't always consistent and it's hard to infer why one example may show things one way and a different example will show them another. In this case I'm attempting to place a VWAP which is declared, initialized and called in what I think is the same way but it doesn't work.

    Using the SampleMultiTimeFrame strategy that NinjaTrader has given us they declare their 6 SMA variables, sma50b0 to b3, sma5b0 to b3

    Next in Data.Loaded they call the first 2 (sma50b0 and sma5b0) which establishes their period and then they add it to the chart.

    Next in OnBarUpdate they call the other 4 variables via an if variable is null, assign this command. State.DataLoaded seems like it would be a better place to initialize these 4 variables but either way it works in this instance.

    Copying this format I am setting up a linear regression channel. It's declared just below the public class ... : strategy;
    private OrderFlowVWAP VWAP;

    Code:
    State.DataLoaded
    if (VWAP == null)
    {
    VWAP = OrderFlowVWAP(VWAPResolution.Standard, Bars.TradingHours, VWAPStandardDeviations.Two, 1,2,3);
    
    a bunch more code
    
    AddChartIndicator(VWAP);
    where the AddChartIndicator(VWAP) results in a compile error - Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.

    Any idea why this might be the case and/or how this should be handled? From the example it seems like the correct way to do it.

    Edit: is there an issue using the if( indicator == null) then assign values as NT may not be reading it as null since it was assigned?
    Last edited by itsthefriz; 09-12-2021, 10:22 AM.

    #2
    Hello itsthefriz,

    The Order Flow VWAP can be called in OnStateChange() when State is State.DataLoaded the same as the SMA().

    Attached is an exported test script.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Interesting, probably not the first time you've heard this but yours worked. I copied the line
      Code:
      VWAP = OrderFlowVWAP(VWAPResolution.Standard, TradingHours.String2TradingHours("CME US Index Futures RTH"), VWAPStandardDeviations.Three, 1, 2, 3);
      in and then added the AddChartIndicator(VWAP); and it worked. Mine was very similar but resulted in an object not assigned error at AddChartIndicator(VWAP)

      Anyways, thanks for the help!
      Last edited by itsthefriz; 09-13-2021, 05:47 PM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      633 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      364 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      567 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      568 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X