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

sending a list from one indicator to another

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

    sending a list from one indicator to another

    Hi all,


    I have a question concerning the exchange of data between two indicators.

    I have an indicator that have a list of price levels that I would like to use to draw in another chart with another indicator.

    In my first indicator ( the one that owns the list of double) I have exposed the list like that :

    [Browsable(false)]
    [XmlIgnore()]
    public List<double> Zone
    {
    get { Update(); return zone; }
    }

    In my second indicator ( the one that receives the list and use it to draw lines and rectangles I have the following structure :

    First in my Variables region I have created a list :

    #region Variables
    List<double> zone = new List<double>();
    #endregion

    Second in my OnBarUpdate() method I initialize my list to the list of my first indicator and draw some stuff :

    protected override void OnBarUpdate()
    {

    int count = 0;
    double temp = 0;

    if(Bars.FirstBarOfSession){
    zone = MyfirstIndicator().Zone;
    }

    foreach(double item in zone){
    count +=1;

    if(count % 2 != 0)
    temp = item;
    else
    DrawRectangle("Zone"+item, false, Bars.BarsSinceSession, temp, 0, item, Color.Bisque, Color.Bisque, 3);

    }


    I get the following error :

    Error on calling 'OnBarUpdate' method on bar1 : Object reference not set to an instance of an object.


    What is wrong with my code ?



    Thanks


    Bernard

    #2
    Suggest you use try-catch blocks to isolate out which line is causing you problems.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Bernard, as an alternate way of doing this and using just one indicator, have you considered stream writer? On start up all charts would read from the file. If new data was then entered into parameter settings, it would be written to the file. An F5 refresh of other charts would cause a new read from the file. This would work well if setting up zones once a day but your application may be different.
      eDanny
      NinjaTrader Ecosystem Vendor - Integrity Traders

      Comment


        #4
        Thanks guys


        I will try try catch block to isolate the error.

        eDanny thanks for the suggestion but this indicator could go to potential clients and I would like to avoid having them pressing F5 key or any others keys to update the indicator. When you deal with the public the simpler it is the better it is...


        Thanks

        Bernard

        Comment


          #5
          Bernard, you need to instantiate your list in the first indicator. It is not necessary in the second indicator because you use the reference to the first indicator-list only, your instantiation here is just trashed.

          Regards
          Ralph

          Comment


            #6
            I tried a lot of things and the error starts when I initialize my list.

            Ralph I am not sure I know how to code what you are explaining. Could you be more specific.

            I have no problem using exposed variables or lists from an indicator to a strategy but my problem lies with the relation between two indicators...



            Bernard

            Comment


              #7
              My explanation was related to your code example in conjunction with the error message about usage of a non-initialised reference.
              You use in your second indicator MyfirstIndicator().Zone, but I don't see the initialisation of property Zone in the first indicator. If you missed it, it would cause the error message mentioned.

              Regards
              Ralph

              Comment


                #8
                OK I understand


                I am not showing it but my list has been obviously initialized in the first indicator.



                Thks



                Bernard

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by CortexZenUSA, Today, 12:53 AM
                0 responses
                1 view
                0 likes
                Last Post CortexZenUSA  
                Started by CortexZenUSA, Today, 12:46 AM
                0 responses
                0 views
                0 likes
                Last Post CortexZenUSA  
                Started by usazencortex, Today, 12:43 AM
                0 responses
                2 views
                0 likes
                Last Post usazencortex  
                Started by sidlercom80, 10-28-2023, 08:49 AM
                168 responses
                2,262 views
                0 likes
                Last Post sidlercom80  
                Started by Barry Milan, Yesterday, 10:35 PM
                3 responses
                10 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Working...
                X