• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DrawArrowDown/Up question

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

    DrawArrowDown/Up question

    Hello,

    I'd have an basic question. (sorry for it). My strategy plot DrawArrowDown/Up with different name and I'd like them to show the Tags on chart and output window but my problem is to find the right method to this. I tried to use this: Print(DrawArrowDown.Tag.ToString()); but I got error. This is an string but the DrawArrowDown.Tag isn't work too. Could you help me which method can I to show the Tag of the exist DrawArrowDown?

    thanks. Ron

    #2
    Ron

    You can access the information at the time of creation or later with an iteration of the DrawObjects.

    Creation:

    Code:
    protected override void OnBarUpdate() 
    {
        // Draws an Arrow Down
        IArrowDown arrow = DrawArrowDown("tag1", true, 0, High[0] + TickSize, Color.Red);
     
        // Print the tag of the draw object
        Print(arrow.Tag);
    }

    Searching existing objects:


    Code:
    protected override void OnBarUpdate()
    {
     // Loops through the DrawObjects collection
     foreach (IDrawObject draw in DrawObjects)
     {
             // Finds DrawArrow objects
             if (draw is IArrowUp || draw is IArrowDown)
             {
                  print(draw.tag);
             }
    }

    Comment


      #3
      Hello Ensotrader,

      many thanks for help!!!! that is great! :-)

      Comment


        #4
        Hello Ron,

        Thank you for your post and thank you to Enso for responding.

        Enso, is correct here in getting the Tag name for all the Up and Down Arrows.

        Here is a link for more information on the IDrawObjects -
        http://www.ninjatrader.com/support/h...drawobject.htm
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Hello Enso,

          I followed your code but I'd have another question how can It solved? My goal is, there is the historical chart and I'd like to place at least 4 arrow to mark the selected bars. I'd like to reach this: where I placed the arrows it should give me back the OHLC datas of current selected bars. I give name to arrows e.g. A1, A2, A3, B1, B2... And in the output window I'd like to copy the selected bar datas and other coded operation with this datas. Therefore I have to search the arrow with A1,A2... Tags. When I use your codes and I'd like to find only arrow with A1 Tag and I’d like to set the color of background in then this situation will colored all bars on chart.
          My simple code:
          Code:
          foreach (IDrawObject draw in DrawObjects)
           {    if ((draw is IArrowUp || draw is IArrowDown) && draw.Tag == "A1")
                   {   Print(draw.Tag + "  " + CurrentBar); BackColor = Color.PaleGreen;    }}
          This method can find the Tag “A1” on the chart but it will print the datas at every bar (from beginning to the last with its currentbars) and make color the background at every bar too. My question would be how can be amended this code to show me ONLY the searched drawing item?
          I treid with this too but this situation is the same:

          Code:
          protected override void OnBarUpdate()
                  {   if (DrawObjects["someTag"] != null && DrawObjects["someTag"].DrawType == DrawType.ArrowUp)
             {    Print(DrawObjects.Count + "\tt " +CurrentBar); BackColor = Color.Aqua;   }    }
          thanks Ron
          Last edited by rontrade; 11-14-2014, 03:21 AM.

          Comment


            #6
            Ron,

            The OnBarUpdate() method is called for each bar that NT processes for your chart.
            As such, your code uses the current bar information so long as it finds an arrow with an A1 tag, since it doesn't discriminate for the bar related to the arrow.

            Are you manually placing the arrows, or programmatically? If programmatically, then you should print the data then and adjust the display at that point.
            If manually, then you'll need to recast the draw object to either an IArrowDown or IArrowUp and use the barsAgo property to reference the associated bar for the arrow. Even then, it's going to do that on each time OnBarUpdate() is called.

            Comment


              #7
              Hi Ron,

              EnsoTrader is correct. The object exists in a collection that is not synced with the primary bar series. On every bar as you loop through the list of objects they will always exist.

              The arrow object itself does have a barsAgo value that you can use.

              If the barsAgo is 0 then its on the current bar.

              Code:
              foreach (IDrawObject draw in DrawObjects)
              {
              if (draw.DrawType == DrawType.ArrowUp)
              {
              IArrowUp thisArrow;
              thisArrow = (IArrowUp) draw;
              if (thisArrow != null)
              Print(thisArrow.BarsAgo);
              }
              }
              However, I would recommend that you track this a different way. Perhaps with a couple of bool series; one that has a true for each bar with an up arrow, one that has a true for each bar with a down arrow.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hello ChelseaB & EnsoTrader!

                Many thanks for help and code! Enso idea was correct but your code really helped me since I'm not an hard core coder!

                Ron

                Comment


                  #9
                  Hello,

                  It managed to follow your instructions. But I got another problem. It is difficult to explain.
                  That happend: I draw two arrows one up and one down. It can recognise the OHLC of the bars and draw a line between both point. It works, as can be seen picture 1 but there is an special cases when I move the arrow closer with 1 bar to each other the NT can’t able to draw the line. After couple of bars occur the problem the line can’t drawn the NT in an limited distance. I don’t know what happend in this situation and how should I fix it.
                  I have on chart 722 piece bars, from last friday
                  Could you see the pictures? What should I set on chart?
                  I attached the cs.
                  Thanks for help! Ron
                  Click image for larger version

Name:	pic2.jpg
Views:	1
Size:	432.8 KB
ID:	872752

                  Click image for larger version

Name:	pic3.jpg
Views:	1
Size:	398.5 KB
ID:	872753

                  Click image for larger version

Name:	pic4.jpg
Views:	1
Size:	372.6 KB
ID:	872754

                  TempLine.cs
                  Last edited by rontrade; 11-30-2014, 03:50 PM.

                  Comment


                    #10
                    Hi rontrade,

                    I'm having some difficulty understanding the issue.

                    The line is sometimes not being drawn, is this correct?

                    What is the start bars ago value and end bars ago value of the line when it is not appearing?

                    What are the start price and end price values?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello,

                      Sorry for my english knowledge. : -)
                      The line is sometimes not being drawn, this correct.
                      At the last position
                      - where the line was properly drawn:
                      -start bars ago: 373; start Price:0,8561;time: 26/11 2014; 8:40
                      -end bars ago: 358.; end price 0,84865 ;time: 26/11 2014; 11:10
                      - where the line wasn’t properly drawn:
                      -start bars ago: 373; start Price:0,8561;time: 26/11 2014; 8:40
                      -end bars ago: 359; end price 0,84955 ;time: 26/11 2014; 11:10
                      So, the start bars ago (373) was same, but the and bars ago was moved back with 1 bar (from 358 to 359)

                      I don’t know what can be the problem because of it has moved back only with one bar and the conditionss were almast same.
                      The Nt gives me this error:
                      **NT** Error on calling 'OnBarUpdate' method for strategy 'TempLine/b6deaef5cfd84253aa2ea6910e1522af': TempLine.DrawLine: startBarsAgo out of valid range 0 through 272, was 273. But I don’t see what does it mean and what will the NT.
                      I hope that can help you!

                      Thanks Ron

                      Comment


                        #12
                        Hi rontrade,

                        I think I am understanding the issue.

                        The arrows are manually drawn is this correct?

                        And you loop through the existing arrows and get the barAgo value for the arrows and use these as the end points for the line.

                        I am not able to test your script because it will not compile.

                        May I have an export of the script? (That will ensure all dependencies are met)

                        To export your script do the following:
                        1. Click File -> Utilities -> Export NinjaScript
                        2. Enter a unique name for the file in the value for 'File name:'
                        3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
                        4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


                        By default your exported file will be in the following location:
                        • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


                        Below is a link to the help guide on Exporting NinjaScripts.
                        http://www.ninjatrader.com/support/h...nt7/export.htm
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello Chelsea,

                          thanks for reply. yes, I forgot to mention the arrows are manually drawn so I'd like to loop through that arrows and those should give me the necessary datas for drawing line.
                          I exported and attached the script.
                          Thanks Ron
                          Attached Files

                          Comment


                            #14
                            Hi rontrade,

                            Ok, I've got the script imported and I am testing. I see I have to make a Aqua down arrow and a Bisque up arrow for it to work.

                            So far I am seeing that it works. I'm not sure what to do to make the line disappear. I move the arrows, but this does not cause any action to happen.

                            Also, it seems that the line is not calculating the bars ago values correctly. Instead it moves forward on every bar.

                            What action do I need to take to cause the line to disappear?
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Hello,

                              I attached an video what happen if I move manually the arrows. If them reach an limit of barsago will appear the problem.

                              I hope it can be understandable.
                              I can't upload the file here so I give another link: http://ul.to/9oc6tc9a
                              thanks Ron

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by RandanAL, 09-21-2019, 09:05 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_ChrisSch  
                              Started by afoschini, Today, 02:57 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post afoschini  
                              Started by Newtrader101, Yesterday, 06:31 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_EricB  
                              Started by Tyler7498, Yesterday, 07:34 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post Tyler7498  
                              Started by Woomera, Yesterday, 07:24 PM
                              2 responses
                              12 views
                              0 likes
                              Last Post Woomera
                              by Woomera
                               
                              Working...
                              X