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

Remove a DrawTriangle

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

    Remove a DrawTriangle

    How do I make a drawn symbol (triangle in my case) disappear when the condition was present at the beginning of the bar but changed when the bar progresses.

    The BarColor I am using, as given in the piece of code below behaves correctly but not the drawn triangle. Once drawn it remains. Makes sense of course, but is there a piece of code I could add that would make it disappear when the condition changes while the bar is in progress?

    if (Close[0] > Opens[0][0]
    && Rising (LinReg(BarsArray[1],4))
    ...
    && LinReg(BarsArray[1],4)[0] > LinReg(BarsArray[1],9)[0]
    && Rising (LinReg(BarsArray[3],4)))

    {
    BarColor = barUpColor;
    DrawTriangleUp("My triangle" + CurrentBar, false, 0, EMA(drawplace)[0], DrawUpColor);
    }

    sandman

    #2
    Originally posted by sandman View Post
    How do I make a drawn symbol (triangle in my case) disappear when the condition was present at the beginning of the bar but changed when the bar progresses.

    The BarColor I am using, as given in the piece of code below behaves correctly but not the drawn triangle. Once drawn it remains. Makes sense of course, but is there a piece of code I could add that would make it disappear when the condition changes while the bar is in progress?

    if (Close[0] > Opens[0][0]
    && Rising (LinReg(BarsArray[1],4))
    ...
    && LinReg(BarsArray[1],4)[0] > LinReg(BarsArray[1],9)[0]
    && Rising (LinReg(BarsArray[3],4)))

    {
    BarColor = barUpColor;
    DrawTriangleUp("My triangle" + CurrentBar, false, 0, EMA(drawplace)[0], DrawUpColor);
    }
    else RemoveDrawObject("My triangle" + CurrentBar);

    sandman
    Added in blue.

    Comment


      #3
      Hello sandman,
      The most convenient way to remove a draw object is with RemoveDrawObject ("name");
      What i suggest is to declare a private string tmp variable and inside your code:

      Code:
      if (Close[0] > Opens[0][0] && Rising (LinReg(BarsArray[1],4)) ...
      && LinReg(BarsArray[1],4)[0] > LinReg(BarsArray[1],9)[0] && Rising (LinReg(BarsArray[3],4)))
      {
      BarColor = barUpColor;
      DrawTriangleUp('My triangle' + CurrentBar, false, 0, EMA(drawplace)[0], DrawUpColor);
      [B][I]tmp = "My triangle" + CurrentBar;[/I][/B]
      }
      Later on when you want to remove

      Code:
      [B][I]if (condition to remove triangle)
      {
       RemoveDrawObject (tmp);
      }
      [/I][/B]

      Here is a link to RemoveObject: http://www.ninjatrader.com/support/h...drawobject.htm



      Please let me know if I can be of further assistance.
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        koganam

        Thanks. I tried that and get an error message as in the attached image and have no idea what it implies. (Keep in mind I am not an expert coder. I mainly use the solution-oriented trial and error method

        sandman
        Attached Files

        Comment


          #5
          Originally posted by sandman View Post
          koganam

          Thanks. I tried that and get an error message as in the attached image and have no idea what it implies. (Keep in mind I am not an expert coder. I mainly use the solution-oriented trial and error method

          sandman
          That is what happens when I see an incomplete snippet of code and assume that the entire block has been posted.

          The new code that you posted shows that your if block already had an attached else block: the original posted code showed only a completed if block. You will have to remove the addition that I posted. Until we see the logic of the entire if ... else block, there is little that can be said.

          Regardless, the statement to remove the drawing is correct: it is a matter of where it is to be placed.

          Comment


            #6
            Hello sandman & koganam

            To complete the loop.

            The reason for the error is the sequence of the if statement.

            You cannot have if - else - else if, it must be if -else if- else.

            Here is a reference: http://msdn.microsoft.com/en-us/library/5011f09h.aspx

            Please let me know if I can be of further assistance.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              koganam. Sorry about that. If you could look at this here and give me a suggestion where to place it. sandman

              protected override void OnBarUpdate()
              {
              // Ignore if there are not enough bars on charts to calculate
              //if (CurrentBar < 10) return;
              if (CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired || CurrentBars[2] < BarsRequired || CurrentBars[3] < BarsRequired)
              return;

              if(BarsInProgress != 0) return;

              // Condition set 1a - LONG
              if (Close[0] > Opens[0][0]
              && Rising (LinReg(BarsArray[1],4))
              && Rising (LinReg(BarsArray[1],9))
              && Rising (LinReg(BarsArray[2],4))
              && Rising (LinReg(BarsArray[2],9))
              && LinReg(BarsArray[2],4)[0] > LinReg(BarsArray[2],9)[0]
              && LinReg(BarsArray[1],4)[0] > LinReg(BarsArray[1],9)[0]
              && Rising (LinReg(BarsArray[3],4)))

              {
              BarColor = barUpColor;
              DrawTriangleUp("My triangle" + CurrentBar, false, 0, EMA(drawplace)[0], DrawUpColor);
              }

              else if (Close[0] > Opens[0][0]
              && Rising (LinReg(BarsArray[1],4))
              && Rising (LinReg(BarsArray[1],9))
              && LinReg(BarsArray[1],4)[0] > LinReg(BarsArray[1],9)[0]
              && Rising (LinReg(BarsArray[2],4))
              && Rising (LinReg(BarsArray[2],9))
              && Rising (LinReg(BarsArray[3],4)))
              {
              DrawTriangleUp("My triangle" + CurrentBar, false, 0, EMA(drawplace)[0], DrawUpColor);
              }

              else if (Close[0] > Opens[0][0]
              && Rising (LinReg(BarsArray[1],4))
              && Rising (LinReg(BarsArray[1],9))
              && LinReg(BarsArray[2],4)[0] > LinReg(BarsArray[2],9)[0]
              && Rising (LinReg(BarsArray[2],4))
              && Rising (LinReg(BarsArray[2],9))
              && Rising (LinReg(BarsArray[3],4)))
              {
              DrawTriangleUp("My triangle" + CurrentBar, false, 0, EMA(drawplace)[0], DrawUpColor);
              }

              else if (Close[0] > Opens[0][0])
              {
              BarColor = Color.Empty;
              }

              // Condition set 2a - SHORT etc.

              Comment


                #8
                Originally posted by sandman View Post
                koganam. Sorry about that. If you could look at this here and give me a suggestion where to place it. sandman

                protected override void OnBarUpdate()
                {
                // Ignore if there are not enough bars on charts to calculate
                //if (CurrentBar < 10) return;
                if (CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired || CurrentBars[2] < BarsRequired || CurrentBars[3] < BarsRequired)
                return;

                if(BarsInProgress != 0) return;

                // Condition set 1a - LONG
                if (Close[0] > Opens[0][0]
                && Rising (LinReg(BarsArray[1],4))
                && Rising (LinReg(BarsArray[1],9))
                && Rising (LinReg(BarsArray[2],4))
                && Rising (LinReg(BarsArray[2],9))
                && LinReg(BarsArray[2],4)[0] > LinReg(BarsArray[2],9)[0]
                && LinReg(BarsArray[1],4)[0] > LinReg(BarsArray[1],9)[0]
                && Rising (LinReg(BarsArray[3],4)))

                {
                BarColor = barUpColor;
                DrawTriangleUp("My triangle" + CurrentBar, false, 0, EMA(drawplace)[0], DrawUpColor);
                }

                else if (Close[0] > Opens[0][0]
                && Rising (LinReg(BarsArray[1],4))
                && Rising (LinReg(BarsArray[1],9))
                && LinReg(BarsArray[1],4)[0] > LinReg(BarsArray[1],9)[0]
                && Rising (LinReg(BarsArray[2],4))
                && Rising (LinReg(BarsArray[2],9))
                && Rising (LinReg(BarsArray[3],4)))
                {
                DrawTriangleUp("My triangle" + CurrentBar, false, 0, EMA(drawplace)[0], DrawUpColor);
                }

                else if (Close[0] > Opens[0][0]
                && Rising (LinReg(BarsArray[1],4))
                && Rising (LinReg(BarsArray[1],9))
                && LinReg(BarsArray[2],4)[0] > LinReg(BarsArray[2],9)[0]
                && Rising (LinReg(BarsArray[2],4))
                && Rising (LinReg(BarsArray[2],9))
                && Rising (LinReg(BarsArray[3],4)))
                {
                DrawTriangleUp("My triangle" + CurrentBar, false, 0, EMA(drawplace)[0], DrawUpColor);
                }

                else if (Close[0] > Opens[0][0])
                {
                BarColor = Color.Empty;
                }

                // Condition set 2a - SHORT etc.
                That depends on what you really want to do. You can put it as the final else block, if it is what is to happen if NONE at all of all the preceding blocks is entered. If you want the Triangle removed also when you set BarColor to Color.Empty, or only when you meet that condition, then you may have to put the same statement in that block (just the bare statement, without the else; as you cannot have an else clause inside an if block.)

                Comment


                  #9
                  Originally posted by koganam View Post
                  That depends on what you really want to do. You can put it as the final else block, if it is what is to happen if NONE at all of all the preceding blocks is entered. If you want the Triangle removed also when you set BarColor to Color.Empty, or only when you meet that condition, then you may have to put the same statement in that block (just the bare statement, without the else; as you cannot have an else clause inside an if block.)
                  koganam (and also Paul),

                  Now I think I have got enough information from you to test it out tomorrow.

                  Thank you.

                  sandman

                  Comment


                    #10
                    koganam and Paul.

                    It was a matter of placing it in the right place in the code and after some attempts I got it figured out, tested it for a few days and it works as intended. Thanks to both of you.

                    Another question in this context: Is it possible to vary the size of the drawing symbol, in this case an arrow up or arrow down? I attach a screenshot which shows the arrows and the part of the code I am using to create the arrows.

                    sandman
                    Attached Files

                    Comment


                      #11
                      Hello Sandman,

                      Thanks for your post. Glad you have that working.

                      I am not aware of a way to vary the size of the symbol directly through the DrawArrow. I have seen where it is possible to use DrawText and then using a symbol type font that you can acccomplish that (by changing the font size of the drawn symbol). Here is a reference to an older thread on the subject: http://www.ninjatrader.com/support/f...nge+size+arrow.
                      Paul H.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by timmbbo, Today, 08:59 AM
                      0 responses
                      1 view
                      0 likes
                      Last Post timmbbo
                      by timmbbo
                       
                      Started by bmartz, 03-12-2024, 06:12 AM
                      5 responses
                      33 views
                      0 likes
                      Last Post NinjaTrader_Zachary  
                      Started by Aviram Y, Today, 05:29 AM
                      4 responses
                      14 views
                      0 likes
                      Last Post Aviram Y  
                      Started by algospoke, 04-17-2024, 06:40 PM
                      3 responses
                      28 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by gentlebenthebear, Today, 01:30 AM
                      1 response
                      8 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Working...
                      X