Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DrawText and COBC = False

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

    DrawText and COBC = False

    Howdy--

    I've build an indicator that gives me a bar label above the High[0] and below the Low[0] that shows where the High or Low is in relation to a SMA, Bollinger 1 and Bollinger 2. So for instance, if the High[0] is between the SMA and BB1, the label will be "BB1".

    When you plot these labels on a chart, they plot perfect for historical bars, however on the current bar when COBC = false, NT plots multiple labels if the label changes from SMA to BB1 or BB2.

    I'm currently using:

    DrawText("upperBB1" + CurrentBar, "BB1", 0, High[0] + 3 * TickSize, Color.Red);

    I'd like to modify my code such that when COBC = false, only one label is drawn as the bar develops.

    Does anyone have any ideas on how I might do this?

    Please let me know if you have any questions.

    Thanks for your help,

    Aventeren

    #2
    Hello aventeren,

    Thank you for your post.

    You could achieve this two ways. You can use the same tag name for the drawing objects, or you can manually remove the drawing object before drawing a new one.

    I recommend that you use the same tag name for all of the drawing objects. You can still put CurrentBar on the tag name to make it unique for each bar, but instead of "upperBB1" use something across the board like "marker"

    DrawText(string tag, string text, int barsAgo, double y, Color color)
    http://www.ninjatrader.com/support/h...7/drawtext.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the idea, Chelsea.

      I tried changing the label tag name to "upperlabel" for the High labels and "lowerlabel" for the Low labels, but that doesn't seem to be working, as I'm getting multiple labels still.

      How would I go about clearing the text before the label logic?

      Thanks,

      Aventeren

      Here is the code I'm using:
      Code:
      if(High[0] >= valueBB2upper) // The upper BB2 has been touched
      			{
      				DrawText("upperlabel" + CurrentBar, "BB2", 0, High[0] + 1 * yoffset * TickSize, Color.White);
      			}	
      			
      			else if(High[0] >= valueBB1upper) // The upper BB1 has been touched
      			{
      				DrawText("upperlabel" + CurrentBar, "BB1", 0, High[0] + 1 * yoffset * TickSize, Color.Blue);
      			}	
      			
      			else if(High[0] >= valueSMA) // The upper SMA has been touched
      			{
      				DrawText("upperlabel" + CurrentBar, "SMA", 0, High[0] + 1 * yoffset * TickSize, Color.Magenta);
      			}
      		
      		if(Low[0] <= valueBB2lower) // The lower BB2 has been touched
      			{
      				DrawText("lowerlabel" + CurrentBar, "BB2", 0, Low[0] - 1 * yoffset * TickSize, Color.White);
      			}	
      			
      			else if(Low[0] <= valueBB1lower) // The lower BB2 has been touched
      			{
      				DrawText("lowerlabel" + CurrentBar, "BB1", 0, Low[0] - 1 * yoffset * TickSize, Color.Blue);
      			}
      			
      			else if(Low[0] <= valueSMA) // The lower SMA has been touched
      			{
      				DrawText("lowerlabel" + CurrentBar, "SMA", 0, Low[0] - 1 * yoffset * TickSize, Color.Magenta);
      			}
      Last edited by aventeren; 11-26-2013, 09:45 AM.

      Comment


        #4
        Hi aventeren,

        By using the same tag name each time DrawText is called it will remove the older drawing object with the same tag name and replace this. They are not stacked as the older instance will be completely removed.

        So that I can test this code what values are you using for valueBB2upper, and valueBB2lower?

        What instrument are you testing this with?

        Is there any other code that can affect this behavior that is not included?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I've basically plotted a 20 SMA with a Bollinger Band 1 and a Bollinger Band 2 on either side of the SMA.

          I first calculate the SMA using this:

          valueSMA = SMA(20)[0];

          Then I calculate the bands off using:

          valueStdDev = StdDev(20)[0];
          valueBB1upper = valueSMA + 1 * valueStdDev;
          valueBB2upper = valueSMA + 2 * StdDev;
          valueBB1lower = valueSMA - 1 * StdDev;
          valueBB2lower = valueSMA - 2 * StdDev;

          The if else statements then cycle within OnBarUpdate() to make sure that the correct label is used.

          When I was using unique labels for each label (i.e., upperBB2 instead of upperlabel), it was drawing the historic bars correctly and drawing multiple labels on the current bar when COBC = false.

          When I changed to a uniform label (i.e., upperlabel), it does not draw the historical bar labels correctly or the current bar (i.e., I'm getting multiple labels on both historic and current bars).

          It seems like the labels are not clearing or something.

          Thanks for your help, Chelsea...we'll get this.

          Aventeren
          Last edited by aventeren; 11-26-2013, 10:05 AM.

          Comment


            #6
            Hello aventeren,

            With the code that is here I would expect exactly 2 text objects on every bar.

            Is this not what is happening? Is this not what you are trying to accomplish?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I, too, would expect two draw objects, but I am getting 2 draw objects on either side (sometimes) and 1 draw object (sometimes).

              For instance, it will plot the correct SMA labels if price is between the SMA and BB1, but then for some reason also plot a lower BB1 label--even though price never dropped below the lower BB1.

              Weird.

              Comment


                #8
                Hi aventeren,

                "but I am getting 2 draw objects on either side (sometimes)"

                Does this mean you are getting a total of four text boxes? 2 on either side?

                Is there more code to your script than you have posted?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  With respect to the values and labels, no, there is no other code that changes the values or labels.

                  In OnBarUpdate(), I have first a calculations sections to refresh the various values, then I have then labels section to draw the labels.

                  I'm doing a NT restart to see if something is weird.

                  Comment


                    #10
                    Hi aventeren,

                    "but I am getting 2 draw objects on either side (sometimes)"

                    Does this mean you are getting a total of 4 text boxes? 2 on either side?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Here is a screen capture of the label weirdness: http://screencast.com/t/W2jGruYt5jVj.

                      This is with COBC = false and with the upper labels having the name tag "upper" and the lower labels having the name tag "lower".

                      As you can see, some labels plot correctly, while others are plotting multiple labels.

                      Comment


                        #12
                        Hello aventeren,

                        May I have an export of this script to test on my end?

                        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.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          DrawText and COBC = False

                          Thanks, Chelsea. Here is the code.
                          Attached Files

                          Comment


                            #14
                            Any thoughts?

                            Comment


                              #15
                              Hi aventeren,

                              Thanks for the code. I am giving this a test now.

                              I appreciate your patience.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by chartchart, 05-19-2021, 04:14 PM
                              3 responses
                              577 views
                              1 like
                              Last Post NinjaTrader_Gaby  
                              Started by bsbisme, Yesterday, 02:08 PM
                              1 response
                              15 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by prdecast, Today, 06:07 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post prdecast  
                              Started by i019945nj, 12-14-2023, 06:41 AM
                              3 responses
                              60 views
                              0 likes
                              Last Post i019945nj  
                              Started by TraderBCL, Today, 04:38 AM
                              2 responses
                              18 views
                              0 likes
                              Last Post TraderBCL  
                              Working...
                              X