Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error accessing DrawingTools.HorizontalLine from an indicator

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

    Error accessing DrawingTools.HorizontalLine from an indicator

    Hello,

    I want to access the price value of a manually inserted horizontal line from an indicator, but without success. I'm using a code snippet I found on the documentation.

    This is the code that generates a casting error:

    Code:
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale) {
                foreach (Gui.NinjaScript.IChartObject thisObject in ChartPanel.ChartObjects) {
                    Print(String.Format("There is the object {0} of type {1}", thisObject.Name, thisObject.GetType()));
                    if (thisObject.GetType().ToString() == "NinjaTrader.NinjaScript.DrawingTools.HorizontalLine") {
                        Print(String.Format("Accessing the object {0} of type {1}", thisObject.Name, thisObject.GetType()));
                        NinjaTrader.NinjaScript.DrawingTools.HorizontalLine hl = (NinjaTrader.NinjaScript.DrawingTools.HorizontalLine) thisObject;
                        stopValue = hl.EndAnchor.Price;
                        Print(String.Format("{0} is the stopValue", stopValue));
                    }
                }
            }
    and this is the error that I get:

    -------------------------------------
    There is the object Horizontal Line of type NinjaTrader.NinjaScript.DrawingTools.HorizontalLin e


    Accessing the object Horizontal Line of type NinjaTrader.NinjaScript.DrawingTools.HorizontalLin e


    Indicator 'JTrader': Error on calling 'OnRender' method on bar 398: Impossibile eseguire il cast di [A]NinjaTrader.NinjaScript.DrawingTools.HorizontalLin e a [B]NinjaTrader.NinjaScript.DrawingTools.HorizontalLin e. Il tipo A ha origine da '01114480d21a40bcb3fce4e44d3c0a38, Version=8.0.7.1, Culture=neutral, PublicKeyToken=null' nel contesto 'LoadFrom' nella posizione 'D:\Documenti\NinjaTrader 8\tmp\01114480d21a40bcb3fce4e44d3c0a38.dll'. Il tipo B ha origine da 'f17f71556d69481983abea6394adb227, Version=8.0.7.1, Culture=neutral, PublicKeyToken=null' nel contesto 'LoadFrom' nella posizione 'D:\Documenti\NinjaTrader 8\tmp\f17f71556d69481983abea6394adb227.dll'
    -------------------------------------


    I don't get why the casting error occurs, the instance thisObject is of the same type of the casting.

    #2
    Also I don't find the documentation of IChartObject...

    Comment


      #3
      I also tried to add the horizontal line from inside the indicator, but for some reason the end user cannot move the horizontal line. He can delete it if allowed, but can't move it.

      Comment


        #4
        Hello barabba,

        Regarding the cast of the object, this is caused by NinjaTrader creating a temporary assembly of the drawing objects after a compile so as to not interrupt the objects in memory.

        Below is a link to a post with a workaround.


        I'm not familar with IChartObject. Are you trying to find the IDrawingTool HorizontalLine object that is returned by Draw.HorizontalLine()?




        Drawing objects that are created by an indicator cannot be edited or deleted manually. If deleted, this will remove the indicator from the chart.
        Instead, the object would need to be removed or modified by the indicator itself. (You could use a button or another action to trigger changes like removing the object)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you for your answer. I will try the workaround.

          I'm writing an indicator to solve my needs in discretionary trading, and this indicator wants to show an horizontal line to the user purposelly to be moved by the user to the desired price level. I'm sure there are good reasons for not allowing the user to edit objects created by indicators, but there are also good reasons to allow this. At least I think NT should let the indicator's creator choose.

          Comment


            #6
            Hello barabba,

            I have submitted a feature request on your behalf for the NinjaTrader Development to consider allowing drawing objects placed by scripts to be modified manually in a future version of NinjaTrader.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello barabba,

              Your request for the ability to manually modify drawing objects that were created by custom scripts is being tracked with ID #SFT-2499.

              Please note it is up to the NinjaTrader Development to decide if and when a request will be implemented.

              Thank you for your suggestion. Please let me know of any other suggestions you have for NinjaTrader.
              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
              648 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              369 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              108 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              572 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              574 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X