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

Problem deleting horizontal lines

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

    Problem deleting horizontal lines

    I am developing an indicator that needs to draw and remove horizontal lines.

    The lines draw properly, but I am having problem deleting them from the chart. After deleting a line, the lines still appear on the chart.

    I have developed a simple test indicator (see below.) This test indicator draws four lines, then deletes one of them. The deleted line continues to show. I have included the a .jpg to demonstrate. Interestingly, if I print out a DawObjects.Count, after creating the lines (should be four) and after deleting one line (should be three) , the DawObjects.Count values are not as expected -- both before and after the line delete thee counts are two.

    More puzzling, if I reload the indicator a number of times by pressing F5, eventually the deleted line will delete showing the lines as expected. Continued reloading of the indicator using F5, will at times be correct (only showing three lines) and at times be incorrect (showing four lines) and ignoring the line delete.

    Pleases let me know what I am doing wrong.

    Thank you for your help.


    Sample output from test Indicator:
    ----608---------------------------------
    Line count before delete: 2
    Draw Object: before deleteline1 type:NinjaTrader.NinjaScript.DrawingTools.Horizont alLine
    Draw Object: before delete@Line2 type:NinjaTrader.NinjaScript.DrawingTools.Horizont alLine
    Draw Object: before delete@Line4 type:NinjaTrader.NinjaScript.DrawingTools.Horizont alLine
    Line count after delete: 2
    Draw Object after delete: line1 type:NinjaTrader.NinjaScript.DrawingTools.Horizont alLine
    Draw Object after delete: @Line2 type:NinjaTrader.NinjaScript.DrawingTools.Horizont alLine
    Draw Object after delete: @Line4 type:NinjaTrader.NinjaScript.DrawingTools.Horizont alLine

    ----609---------------------------------
    Line count before delete: 2
    Draw Object: before deleteline1 type:NinjaTrader.NinjaScript.DrawingTools.Horizont alLine
    Draw Object: before delete@Line2 type:NinjaTrader.NinjaScript.DrawingTools.Horizont alLine
    Draw Object: before delete@Line4 type:NinjaTrader.NinjaScript.DrawingTools.Horizont alLine
    Line count after delete: 2
    Draw Object after delete: line1 type:NinjaTrader.NinjaScript.DrawingTools.Horizont alLine
    Draw Object after delete: @Line2 type:NinjaTrader.NinjaScript.DrawingTools.Horizont alLine
    Draw Object after delete: @Line4 type:NinjaTrader.NinjaScript.DrawingTools.Horizont alLine

    ----610---------------------------------
    Line count before delete: 2
    Draw Object: before deleteline1 type:NinjaTrader.NinjaScript.DrawingTools.Horizont alLine
    Draw Object: before delete@Line2 type:NinjaTrader.NinjaScript.DrawingTools.Horizont alLine
    ;Draw Object: before delete@Line4 type:NinjaTrader.NinjaScript.DrawingTools.Horizont alLine
    Line count after delete: 2
    Draw Object after delete: line1 type:NinjaTrader.NinjaScript.DrawingTools.Horizont alLine
    Draw Object after delete: @Line2 type:NinjaTrader.NinjaScript.DrawingTools.Horizont alLine
    Draw Object after delete: @Line4 type:NinjaTrader.NinjaScript.DrawingTools.Horizont alLine

    ================================================== ======================================
    Test Indicator below:

    public class LineTest : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "LineTest";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.

    Print("----" + CurrentBar + "---------------------------------");

    for(double i=1.0; i<=4.0;i++){
    NinjaTrader.NinjaScript.DrawingTools.HorizontalLin e h= Draw.HorizontalLine(this, "Line" + i.ToString(), 3000.0+(2*i), true, "");
    h.Stroke = new Stroke(Brushes.Bisque, DashStyleHelper.Solid, 2.0F);
    }


    Print(" Line count before delete: " + DrawObjects.Count );

    foreach (DrawingTool draw in DrawObjects.ToList()){
    Print("Draw Object: before delete" +draw.Tag + " type:" + draw.GetType().ToString());
    }
    RemoveDrawObject("Line3");


    Print(" Line count after delete: " + DrawObjects.Count);
    foreach (IDrawingTool hLine in DrawObjects){
    HorizontalLine draw = hLine as HorizontalLine;
    if(draw != null){
    Print("Draw Object after delete: " +draw.Tag + " type:" + draw.GetType().ToString());
    }
    }
    Print(" ");

    }
    }
    Last edited by kweiss; 09-23-2019, 06:27 AM.

    #2
    Hello Kweiss,

    Thanks for your post.

    When you post code, please either use the Code# wrappers or (better yet) attach the source code file. When you copy paste some of the characters get changed making it difficult to recreate.
    There was no jpeg attached.

    In looking at the example code, it looks like you would be drawing the lines on every onBarUpdate()? Does the same thing occur if you only do that once or once every few bars?
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul - Sorry for the confusion. I have included a .cs of the test indicator and a .jpg of the chart with incorrect line displayed. BTW, where do I find about Code# wrappers?

      As for indicator, it will usually fail the first time I place indicator on the chart. Pressing the F5 key to reload will get it to work, after a few presses. But continuing to press the F5 key causes things to mostly fail, but sometimes work.

      As for your question, drawing the lines once causes the same problem.


      Thanks for your help.





      LineTest.cs

      Comment


        #4
        Hello kweiss,

        Thanks for your reply.

        I'm unsure what your code is demonstrating so I've created a less resource intensive version that demonstrates drawing four lines and deleting one, using your code. Please apply to a fast chart (just because it waits for the 1st real time bar) such as 10 second bars and one the first real time bar close it will draw the 4 lines, then 1 bar later it prints the list of 4 objects and removes line 3 then 2 bars later it will re-print the list of objects which shows line 3 is gone as well as not on the chart. To see it run again you would actually need to remove the indicator and reapply it (because I set a bool true initially). See the attached picture and the export code file below:

        Click image for larger version

Name:	kweiss-1.PNG
Views:	509
Size:	54.6 KB
ID:	1071762

        [ATTACH]n1071763[/ATTACH]



        In terms of wrappers, not sure what you are after. Here is the only help guide link I have: https://ninjatrader.com/support/help...neousPractices outside of Ninjascript: https://stackoverflow.com/questions/...-it-help-to-do


        Paul H.NinjaTrader Customer Service

        Comment


          #5

          Hi Paul -

          Thank you for sending this demonstration. Your code has the same problem as mine. After deleting Line3, there are 4 lines displayed on the chart. I need to have three lines displayed.

          I have included a .jpg that shows the 4 lines on the chart and the DrawingObjects dialog box.




          Click image for larger version

Name:	HLineTestProblem.JPG
Views:	354
Size:	138.9 KB
ID:	1071795








          Comment


            #6
            Hello kweiss,

            Thanks for your reply.

            I've created a short video to show what this looks like live: https://Paul-ninjaTrader.tinytake.co...Nl8xMTU0NjI1NA I forgot to open the Drawing objects window in the video so you'll have to accept my word that it only shows the Line1, Line2, Line4.

            On your end, please make sure you are connected to live (or playback with replay data) and I would suggest closing all workspaces and creating a new workspace with only one new chart and perform the test again. If you do not see exactly the same as I have shown and advised, please send your trace and log files into PlatformSupport[at]NinjaTrader[dot]Com. Mark the e-mail atten: Paul and ticket# 2284118. You can do this by going to the Control Center-> Help-> Email Support. Ensuring 'Log and Trace Files' is checked will include these files. This is checked by default.
            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by RubenCazorla, 08-30-2022, 06:36 AM
            3 responses
            77 views
            0 likes
            Last Post PaulMohn  
            Started by f.saeidi, Yesterday, 12:14 PM
            9 responses
            23 views
            0 likes
            Last Post f.saeidi  
            Started by Tim-c, Today, 03:54 AM
            0 responses
            3 views
            0 likes
            Last Post Tim-c
            by Tim-c
             
            Started by FrancisMorro, Today, 03:24 AM
            0 responses
            4 views
            0 likes
            Last Post FrancisMorro  
            Started by Segwin, 05-07-2018, 02:15 PM
            10 responses
            1,772 views
            0 likes
            Last Post Leafcutter  
            Working...
            X