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

draw objects display

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

    draw objects display

    Hallo,

    I need to add some script into the existing one to change the settings of the draw objects display.
    They are displaying "Calculate on bar close - false" right in the moment of creation (the conditions are executed) - it's ok.
    But I also need to add the script to remove the drawing object right in the moment of termination (in case the conditions are no longer executed) before the price bar will be closed.

    Thank you for your help,
    Richard
    Attached Files

    #2
    Hello,

    Thank you for your forum post.

    In this case you would need to run the Strategy in Calculate on Bar Close = False.

    Then move all your COBC = True logic in your indicator code to if(FirstTickOfBar)
    {
    //You OnBarUpdate code here, this works in COBC = True mode.
    }


    Then outside of this you will add your code to delete the drawing objects if the conditions are no longer true, this will execute on every tick allowing you to remove the drawing object if the condition was no longer true.

    Another method to do this if you dont want the objects deleted at the first sign of the conditions no longer being true, would be to check this on the creation of the next bar weather or not the previous bars conditions where true and remove the drawing objects if they are not true. Best way to do this would be with a boolSeries.



    Let me know if I can be of further assistance.

    Comment


      #3
      ... I have thought about ang got solution. Is it correct?
      thanks for advice.

      protected override void Initialize()
      {
      CalculateOnBarClose = false;
      }
      protected override void OnBarUpdate()
      {
      // Condition set 1
      if (//some conditions)
      {
      DrawTriangleUp("My triangle up" + CurrentBar, false, 0, Low[0] + -10 * TickSize, Color.Lime);
      DrawText("My text up" + CurrentBar, "0/v", 0, Low[0] + -15 * TickSize, Color.DimGray);
      }
      // Condition set 2
      else if (//some conditions)
      {
      DrawTriangleDown("My triangle down" + CurrentBar, false, 0, High[0] + 10 * TickSize, Color.Crimson);
      DrawText("My text down" + CurrentBar, "0/v", 0, High[0] + 15 * TickSize, Color.DimGray);
      }
      else
      {
      RemoveDrawObject("My triangle up" + CurrentBar);
      RemoveDrawObject("My text up" + CurrentBar);
      RemoveDrawObject("My triangle down" + CurrentBar);
      RemoveDrawObject("My text down" + CurrentBar);
      }
      }
      Attached Files

      Comment


        #4
        Hello,

        Does it run as you expect live?

        There are always 10 different ways to do things in coding Looks like it should work though.

        Let me know if I can be of further assistance.

        Comment


          #5
          Hello,

          yes it runs as I expected

          Comment


            #6
            Excellent, Great job!

            Comment


              #7
              This is the final output, just for accuracy.

              Code:
              protected override void Initialize()
                      {
                          CalculateOnBarClose = false;
                      }
              protected override void OnBarUpdate()
                      {
                          // Condition set 1
                          if (//some conditions)
                          {
                              DrawTriangleUp("My triangle 0v up" + CurrentBar, false, 0, Low[0] + -10 * TickSize, Color.Lime);
                              DrawText("My text 0v up" + CurrentBar, "0/v", 0, Low[0] + -15 * TickSize, Color.DimGray);
                          }
              			else
              			{
              				RemoveDrawObject("My triangle 0v up" + CurrentBar);
              				RemoveDrawObject("My text 0v up" + CurrentBar);
              			}
              
                          // Condition set 2
                          if (//some conditions)
                          {
                              DrawTriangleDown("My triangle 0v down" + CurrentBar, false, 0, High[0] + 10 * TickSize, Color.Crimson);
                              DrawText("My text 0v down" + CurrentBar, "0/v", 0, High[0] + 15 * TickSize, Color.DimGray);
                          }
              			else
              			{
              				RemoveDrawObject("My triangle 0v down" + CurrentBar);
              				RemoveDrawObject("My text 0v down" + CurrentBar);
              			}
                      }

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by RideMe, 04-07-2024, 04:54 PM
              6 responses
              31 views
              0 likes
              Last Post RideMe
              by RideMe
               
              Started by tkaboris, Today, 05:13 PM
              0 responses
              2 views
              0 likes
              Last Post tkaboris  
              Started by GussJ, 03-04-2020, 03:11 PM
              16 responses
              3,281 views
              0 likes
              Last Post Leafcutter  
              Started by WHICKED, Today, 12:45 PM
              2 responses
              19 views
              0 likes
              Last Post WHICKED
              by WHICKED
               
              Started by Tim-c, Today, 02:10 PM
              1 response
              10 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X