Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 Davidtowleii, Today, 12:15 AM
      0 responses
      3 views
      0 likes
      Last Post Davidtowleii  
      Started by guillembm, Yesterday, 11:25 AM
      2 responses
      9 views
      0 likes
      Last Post guillembm  
      Started by junkone, 04-21-2024, 07:17 AM
      9 responses
      68 views
      0 likes
      Last Post jeronymite  
      Started by trilliantrader, 04-18-2024, 08:16 AM
      4 responses
      20 views
      0 likes
      Last Post trilliantrader  
      Started by mgco4you, Yesterday, 09:46 PM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Working...
      X