Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exposing Object Values of an Indicator

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

    Exposing Object Values of an Indicator

    Hi,

    I have read the documentation of exposing values of an indicator. I have no problem writing an indicator that exposes a value that is associated with the bar e.g. Close[0]

    Here, I am trying to expose the values of a line drawn on a Sender indicator on one chart, so it can be read by a Receiver indicator on another chart.

    I draw a horizontal line, obtain its tag and enter this tag into the Sender's code:


    PHP Code:
        public class SampleSender : Indicator
        {
            private double         exposedVariable;
            HorizontalLine         HL;
            
    
            protected override void OnStateChange()
            {
                if(State == State.SetDefaults)
                {
                    Name                    = "SampleSender";
                    Calculate                = Calculate.OnBarClose;
                    IsOverlay                = true;
                }
            }
    
            protected override void OnBarUpdate()
            {
                foreach (DrawingTool draw in DrawObjects.ToList())
                {
                    if (draw.Tag == "@Horizontal Line 3963")
                    {
                        HL                         = draw as DrawingTools.HorizontalLine;
                        exposedVariable            = HL.StartAnchor.Price;
                    }                            
                }
                Print("Sender :" + exposedVariable);
    
            }
            
            public double ExposedVariable
            {
                get { Update(); return exposedVariable; }
            } 
    

    My Receiver code is simply:
    PHP Code:
            protected override void OnBarUpdate()
            {
                Print("Receiver :" + SampleSender().ExposedVariable);
    
            }​ 
    

    I am not able to read the Sender's line value from the Receiver.

    Would appreciate your assistance on how to do achieve this.
    Last edited by Rainmakersg; 07-02-2024, 02:58 AM.

    #2
    Hello Rainmakersg,

    To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript Add-on...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter the script name in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.
    http://ninjatrader.com/support/helpG...nt8/export.htm


    The hosted symbiote indicator will not be added to a chart unless the host script is a strategy that adds the indicator to the chart with AddChartIndicator().
    If the symbiote is not added to the chart, it will not have access to the ChartControl or any objects like drawing objects.
    Likely you are seeing 'Receiver :0' printing which is showing no price was ever assigned to the property as no drawing objects were accessed.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      To give you some context, this indicator is not to be distributed to other parties, but for my own use. I am trying to align prices on ES and MES since the global lines do not draw across symbols.

      I am loading the Sender indicator on an ES chart and I am loading the Receiver indicator on the MES chart.

      Can this be achieved? I wish the sender to be an indicator instead of a strategy.

      Comment


        #4
        Hello Rainmakersg,

        If you do not wish to use a strategy, you would need to put the code in the receiver indicator that is directly applied to the chart (so it can access the ChartControl objects).
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea,

          Thanks for your reply. I am afraid I don't quite get what you mean.

          Please let me clarify what I need.

          I have attached both indicators here in this post.

          This is what I wish to achieve:

          1. I wish to open an ES chart, draw a horizontal line, get the tag, update the Sender indicator's code with the tag and load the Sender indicator to this ES chart.

          2. I then wish to open a MES chart and load the Receiver indicator to this MES chart. I hope this Receiver indicator can receive the exposed horizontal line's price from the Sender indicator.

          Please let me know which indicator I should amend, and if so how I should amend it.

          Thanks so much.
          Attached Files

          Comment


            #6
            Hello Rainmakersg,

            "I wish to open an ES chart, draw a horizontal line, get the tag, update the Sender indicator's code with the tag and load the Sender indicator to this ES chart."

            This will not be possible with a host indicator and symbiote indicator because the symbiote indicator is not added to the chart.

            The code looping through DrawingObjects.ToList() will have to be moved to the host script which is added to the chart (the receiver indicator).

            If you decide to use a strategy you can use AddChartIndicator() to add the indicator to the chart so it can loop through the DrawingObjects collection.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

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