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

How link 2 drawn objects?

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

    How link 2 drawn objects?

    Hello Support!

    I need your help.

    My script draws 2 objects on chart Text and ArrowLine

    line = DrawArrowLine(string tag, int startBarsAgo, double startY, int endBarsAgo, double endY, Color color)

    text = DrawText(string tag, string text, int barsAgo, double y, Color color)

    The idea is to move text drawn object and in the same time the line object moves. I think it may works through the objects coordinates, but how make this and in which method call? OnBarUpdate() or something?

    Regards.

    #2
    Hello alex_bbfg,

    Thanks for your post.

    Correct, the objects would move based on the supplied coordinates. The OnBarUpdate method is where you would want to have this updated.

    The barsago would represent where in time you want to draw the text or draw the start/end of the line. Using "0" (zero) would place the object in time on the current bar, Using 1 would set the object on the previous bar (time).

    The double y is the vertical (price) level at which the text object will be drawn. In the case of the line object, the two price levels allow you to specify a line that can be of any direction/angle.

    Note that each object must have a unique tag name. The "tag" name can be used in two ways. 1) If you keep it as an unchanging tag name, then the object will move if the coordinates change, in actuality it is first removed then redrawn. 2) If you change the tag name each time the coordinates change then the objects will remain on the screen and a new object drawn (added). To create unique tag names it is not uncommon to specify "tag1"+CurrentBar.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hello Paul,

      thank you for your reply.

      I made the following code

      protectedoverridevoid OnBarUpdate()
      {
      if(CurrentBar < 100) return;

      ITexr tt = DrawText(
      "TXT", "TEXT", 10, 42, Color.Red);
      tt.Locked =
      false;

      IArrowLine lin = DrawArrowLine(
      "Xtag", false, tt.Time, tt.Y, tt.Time.AddMinutes(30), tt.Y+0.3, Color.Red, DashStyle.Solid , 3);
      lin.Locked =
      false;

      Print(tt.Time.ToString() +
      " " + tt.Y.ToString());
      Print(lin.EndTime.ToString() +
      " " + lin.EndY.ToString() + " " + lin.StartTime.ToString() + " " + lin.StartY.ToString());
      }

      it draws arrow and text one time on chart, and then when I move text by mouse nothing happens. The output window prints same data.

      What may be wrong?

      Regards.

      Comment


        #4
        Hello alex_bbfg,

        Thanks for your reply.

        I did not understand that you wanted to manually move a draw object. The information I provided was for moving the objects within code only without external adjustment.

        To accomplish the goal of moving an object by mouse and then having other objects move in relationship you would need to:
        1) Draw the objects (as you have) on screen
        2) Move the object with the mouse
        3) Check the manually moved objects new position
        4) Redraw the following object with the new coordinates.

        Here is your code slightly modified:

        Code:
        		if (doItOnce)  // Draw the initial objects once
        		{
        		IText tt = DrawText("TXT", "TEXT", mystartbarsago, Low[0], Color.Blue);
        		tt.Locked = false;
        
        		IArrowLine lin = DrawArrowLine("Xtag", false, tt.Time, tt.Y, 
        			tt.Time.AddMinutes(30), tt.Y+0.3, Color.Red, DashStyle.Solid , 3);
        		lin.Locked = false;
        
        			doItOnce = false;
        		}
        		
        		foreach (IDrawObject o in DrawObjects)  // Query the moved object
        		{
        			if (o.Tag == "TXT")   // If the object is the original name
        			{
        				IText newtt = (IText)o;   // create handle
        				cstartbarsago = newtt.BarsAgo;  // get the moved objects X location
        				cy = newtt.Y;					// get the moved objects Y location
        				
        			}		
        		}
        		
        		DrawArrowLine("Xtag", false, cstartbarsago, cy, cstartbarsago-10, cy, Color.Red, DashStyle.Solid , 3);
        Please note that the code redraws only when there is either a new bar (CalculateOnBarClose = true), or on each tick (CalculateOnBarClose = False);

        In the attached video showing the results of the code, CalculateOnBarClose = false however the market is very slow at the moment so there are pauses before the line is adjusted by the code (no sound). http://screencast.com/t/QeRzA14ff
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hello Paul,

          The greatest reply I’ve ever got!
          You gave me the logic of the script actions, then provided the code of logic with comments of possible nuances. Brilliant!
          Finally, you compiled the code and made me the video of the code working. Give me the contacts of your bosses and I tell them how good you are.
          Instead of OnBarUpdate() method I used the following

          this.ChartControl.ChartPanel.MouseMove += new MouseEventHandler(Form1_MouseMove);

          no any pauses then happens.

          Paul, I’m impressed of your help and I’d like to ask some more.

          Now I’m developing big project. I’m not professional programmer I did not have specific education and all my knowledge of c# and code writing are from internet.
          My program will connect to NinjaTrader.sdf file and build the list of trades with ability to sort and filter them. On double click on trade entry the script will draw required information on charts. I almost done it. In future, the script will connect to my external sql database and make required actions with data. I see both big and small problems to this.
          I need to work with several charts and the way I launch the script is the indicator script which I attach to each chart. So I’m looking for the way to launch my program external of NinjaTrader, but have the ability to work with the NT’s charts.
          One small problem is how to move visible part of chart to the place of drawings made my script in case them outside the visible one.
          All your ideas will be helpful for me. I’m not good in English and if something is not clear ask, I find he way to explain.

          Regards.

          Comment


            #6
            Hello alex_bbfg,

            Thanks for your reply and I appreciate the comments.

            I needed to stay within the confines of Ninjascript supported methodology so i am glad you were aware of the chartcontrol/mousevent and could tie them together with the code example provided.

            Regrettably I would be unable to assist you on your larger project. If it would help we could provide you with a list of 3rd party programmers that would be able to meet your needs.
            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by wzgy0920, 04-20-2024, 06:09 PM
            2 responses
            26 views
            0 likes
            Last Post wzgy0920  
            Started by wzgy0920, 02-22-2024, 01:11 AM
            5 responses
            32 views
            0 likes
            Last Post wzgy0920  
            Started by wzgy0920, Yesterday, 09:53 PM
            2 responses
            49 views
            0 likes
            Last Post wzgy0920  
            Started by Kensonprib, 04-28-2021, 10:11 AM
            5 responses
            191 views
            0 likes
            Last Post Hasadafa  
            Started by GussJ, 03-04-2020, 03:11 PM
            11 responses
            3,230 views
            0 likes
            Last Post xiinteractive  
            Working...
            X