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

Drawing a smooth band

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

    Drawing a smooth band

    Hello, to draw a band off of the EMA, I am using the "DrawRegion" command. For example, I will draw 10 ticks above and 10 ticks below the EMA, creating the band. This works ok but I would like for the outer edges of my band to be smooth. Using the DrawRegion command causes the edges to be jagged. Is there a way I can achieve this?

    thanks

    #2
    So I can get a better idea, can you provide a screen shot of the 'jagged' edges?

    Is this a multi-series script or single series?
    MatthewNinjaTrader Product Management

    Comment


      #3
      Drawing a smooth band

      Sure, see attached. Not sure what you mean by 'series' ... sorry.
      Last edited by pman777; 11-12-2012, 04:55 PM.

      Comment


        #4
        Originally posted by pman777 View Post
        Sure, see attached. Not sure what you mean by 'series' ... sorry.
        That looks like you have a separate DrawRegion() for each bar. If you want a smooth curve, you will have to draw the region from start to finish as one region, not a series of regions that are pairwise abutting each other.

        Comment


          #5
          thank you for your feedback. I understand what you are saying but being sort of new to ninjascrpt, I'm not sure how to modify my code to get the desired result. Below are my DrawRegion statements, which are executed OnBarUpdate. The upper and lower boundaries are calculated from the center EMA for that given bar. Can you suggest any modifications? thanks in advance.

          DrawRegion("tag1" + CurrentBar , 0, 1, EMA(myEMA), (EMA(myEMA)[0] + (myBand * TickSize)) , Color.Transparent, trendColorUp, 3);

          DrawRegion("tag2" + CurrentBar , 0, 1, EMA(myEMA), (EMA(myEMA)[0] - (myBand * TickSize)) , Color.Transparent, trendColorUp, 3);

          Comment


            #6
            Originally posted by pman777 View Post
            thank you for your feedback. I understand what you are saying but being sort of new to ninjascrpt, I'm not sure how to modify my code to get the desired result. Below are my DrawRegion statements, which are executed OnBarUpdate. The upper and lower boundaries are calculated from the center EMA for that given bar. Can you suggest any modifications? thanks in advance.

            DrawRegion("tag1" + CurrentBar , 0, 1, EMA(myEMA), (EMA(myEMA)[0] + (myBand * TickSize)) , Color.Transparent, trendColorUp, 3);

            DrawRegion("tag2" + CurrentBar , 0, 1, EMA(myEMA), (EMA(myEMA)[0] - (myBand * TickSize)) , Color.Transparent, trendColorUp, 3);
            Turn your upper and lower edges into Plots, then use DrawRegion() to color between them, using a single fixed tag, ending at the CurrentBar, and starting from however far back you want to start.

            Code:
             
            Plot1.Set(EMA(myEMA)[0] + (myBand * TickSize));
            Plot2.Set(EMA(myEMA)[0] - (myBand * TickSize));
             
            DrawRegion("RegionTag", CurrentBar, 0, Plot1, Plot2, Color.Empty, trendColorUp, 3);
            You might prefer to use DataSeries instead of Plots, as the DataSeries will not be shown in the config GUI, whereas Plots will be by default.

            Comment


              #7
              thank you!!!

              Comment


                #8
                Ok ... I was able to get the band to be smooth! However, I'm having one issue regarding the color of the band. If the EMA is rising, I want the band color to be green; conversely when the EMA is falling, I want the band color to be red. Below is my code. Currently it only paints the band one color regardless of the direction of the EMA. What am I doing wrong?

                thanks again!

                Plot0.Set(EMA(myEMA)[0] + (myBand * TickSize));
                Plot1.Set(EMA(myEMA)[0] - (myBand * TickSize));

                if (Rising(EMA(myEMA))) DrawRegion("RegionTag", CurrentBar, 0, Plot0, Plot1, Color.Empty, trendColorUp, 3);
                else DrawRegion("RegionTag", CurrentBar, 0, Plot0, Plot1, Color.Empty, trendColorDn, 3);

                Comment


                  #9
                  Hello pman777,
                  If you try the below code then are you able to get the correct color.

                  Code:
                  if (CurrentBar < 1 ) return;
                  Plot0.Set(EMA(myEMA)[0] + (myBand * TickSize));
                  Plot1.Set(EMA(myEMA)[0] - (myBand * TickSize));
                  
                  if (Rising(EMA(myEMA))) DrawRegion("RegionTag" + CurrentBar, 0, 1, Plot0, Plot1, Color.Empty, Color.Blue, 3);
                  else DrawRegion("RegionTag" + CurrentBar, 0, 1, Plot0, Plot1, Color.Empty, Color.Red, 3);
                  JoydeepNinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by pman777 View Post
                    Ok ... I was able to get the band to be smooth! However, I'm having one issue regarding the color of the band. If the EMA is rising, I want the band color to be green; conversely when the EMA is falling, I want the band color to be red. Below is my code. Currently it only paints the band one color regardless of the direction of the EMA. What am I doing wrong?

                    thanks again!

                    Plot0.Set(EMA(myEMA)[0] + (myBand * TickSize));
                    Plot1.Set(EMA(myEMA)[0] - (myBand * TickSize));

                    if (Rising(EMA(myEMA))) DrawRegion("RegionTag", CurrentBar, 0, Plot0, Plot1, Color.Empty, trendColorUp, 3);
                    else DrawRegion("RegionTag", CurrentBar, 0, Plot0, Plot1, Color.Empty, trendColorDn, 3);
                    I cannot see anything wrong with your syntax. Are you sure that after editing your code, you compiled the indicator and reloaded the chart?

                    Comment


                      #11
                      Originally posted by NinjaTrader_Joydeep View Post
                      Hello pman777,
                      If you try the below code then are you able to get the correct color.

                      Code:
                      if (CurrentBar < 1 ) return;
                      Plot0.Set(EMA(myEMA)[0] + (myBand * TickSize));
                      Plot1.Set(EMA(myEMA)[0] - (myBand * TickSize));
                       
                      if (Rising(EMA(myEMA))) DrawRegion("RegionTag" + CurrentBar, 0, 1, Plot0, Plot1, Color.Empty, Color.Blue, 3);
                      else DrawRegion("RegionTag" + CurrentBar, 0, 1, Plot0, Plot1, Color.Empty, Color.Red, 3);
                      Your code takes him back to creating a jagged region, which was the problem that he initially wanted to solve.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by bortz, 11-06-2023, 08:04 AM
                      47 responses
                      1,603 views
                      0 likes
                      Last Post aligator  
                      Started by jaybedreamin, Today, 05:56 PM
                      0 responses
                      8 views
                      0 likes
                      Last Post jaybedreamin  
                      Started by DJ888, 04-16-2024, 06:09 PM
                      6 responses
                      18 views
                      0 likes
                      Last Post DJ888
                      by DJ888
                       
                      Started by Jon17, Today, 04:33 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post Jon17
                      by Jon17
                       
                      Started by Javierw.ok, Today, 04:12 PM
                      0 responses
                      12 views
                      0 likes
                      Last Post Javierw.ok  
                      Working...
                      X