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

Color bars

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

    Color bars

    I hope someone can help, I have not had much luck trying to program this.
    1. i use a ema and an xma (they should be adjustable)
    2. xma comes from below the ema and the ema crosses the xma, and the price closes at least one tick above the ema, then paint the bar BLUE
    3. when the ema comes from above the ema and crosses the xma and the price closes at least one tick below the ema..then paint the bar red.

    Hope someone can help..Thanks in advance

    #2
    Hi qkracer,

    Have you tried out our Strategy Wizard? What you are trying to code is possible through the use of the point and click interface of the Strategy Wizard.

    Video Overview of the Strategy Wizard:



    Tutorials that will help you get what you want for your particular indicator:



    There are also NinjaScript consultants you can contact for coding. The list is here: http://www.ninjatrader.com/webnew/pa...injaScript.htm
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Color Bars

      Thanks..even with my limited programming, I just might be able to figure this out.

      One question though..once the conidtions are met then I want to change the color or the bar..Not sure how to do that.. If you could guide me one more time... I will have a go at it!! Once again thanks

      Comment


        #4
        Unfortunately you can't explicitly do that in the Strategy Wizard, but you can get everything else accomplished with the wizard. Once you have everything else done you can then press the "Unlock Code" button and then manually type in the necessary lines to change the bar color.

        Code:
        BarColor = Color.Blue;
        Code:
        BarColor = Color.Red;
        You want to type those lines inside the brackets for the corresponding if statements. When you get to this stage and you still need help just copy paste the code here and I can show you the exact location to input those the two lines of code.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          color bars

          Guess as simple as it looks I still cant grasp it. I thought I would do something real simple and paint a dot.. still cant get it to work.
          if (CrossAbove(EMA(Median, 4), SMA(Median, 21), 1))
          {
          DrawDot(
          "dot long" + CurrentBar, 0, 0, Color.Blue);
          }
          // Condition set 2
          if (CrossBelow(EMA(Median, 4), SMA(Median, 21), 1))
          {
          DrawDot(
          "My dot" + CurrentBar, 0, 0, Color.Crimson);
          }
          }

          Comment


            #6
            You told it to draw a dot at bar= 0, price=0 .... Your 'y' coordinate is wrong.

            Try "DrawDot("dot long" + CurrentBar, 0, Close[0], Color.Blue);"

            Or if you want to draw a dot just a bit below the bar ...

            "DrawDot("dot long" + CurrentBar, 0, Low[0]-2*TickSize, Color.Blue);"

            Don't include the quotes.

            Comment


              #7
              Thanks for the tip... Gosh I tried to make a simple example just so I could understand how this works..and so far I am having no success. No dots after making the changes that you recommended. My code looks like this now...
              protectedoverridevoid OnBarUpdate()
              {
              // Condition set 1
              if (CrossAbove(EMA(Median, 4), SMA(Median, 21), 1))
              {
              DrawDot(
              "dot long" + CurrentBar, 0, High[0]+2*TickSize, Color.Blue);
              }
              // Condition set 2
              if (CrossBelow(EMA(Median, 4), SMA(Median, 21), 1))
              {
              DrawDot(
              "dot short" + CurrentBar, 0, Low[0]-2*TickSize, Color.Red);
              }
              }

              Comment


                #8
                Try

                protectedoverridevoid OnBarUpdate()
                {
                // Condition set 1
                if (CrossAbove(EMA(Median, 4), SMA(Median, 21), 1
                ))
                {
                DrawDot(CurrentBar.ToString() +
                "dot long" + CurrentBar, 0, High[0]+2
                *TickSize, Color.Blue);
                }
                // Condition set 2
                if (CrossBelow(EMA(Median, 4), SMA(Median, 21), 1
                ))
                {
                DrawDot(CurrentBar.ToString() +
                "dot short" + CurrentBar, 0, Low[0]-2
                *TickSize, Color.Red);
                }
                }
                RayNinjaTrader Customer Service

                Comment


                  #9
                  qkracer: I just tried your code and it works fine just the way you had it.

                  Code:
                  #region Using declarations
                  using System;
                  using System.Diagnostics;
                  using System.Drawing;
                  using System.Drawing.Drawing2D;
                  using System.ComponentModel;
                  using System.Xml.Serialization;
                  using NinjaTrader.Data;
                  using NinjaTrader.Gui.Chart;
                  #endregion
                  
                  // This namespace holds all indicators and is required. Do not change it.
                  namespace NinjaTrader.Indicator
                  {
                      /// <summary>
                      /// xxtest
                      [Description("xxtest")]
                      [Gui.Design.DisplayName("xxtest")]
                      public class xxtest : Indicator
                      {
                          protected override void Initialize()
                          {
                          }
                  
                          protected override void OnBarUpdate()
                          {
                              // Condition set 1
                              if (CrossAbove(EMA(Median, 4), SMA(Median, 21), 1))
                              {
                                  DrawDot("dot long" + CurrentBar, 0, High[0]+2*TickSize, Color.Blue);
                              }
                      
                              // Condition set 2
                              if (CrossBelow(EMA(Median, 4), SMA(Median, 21), 1))
                              {
                                  DrawDot("dot short" + CurrentBar, 0, Low[0]-2*TickSize, Color.Red);
                              }
                          }
                      }
                  }
                  Attached Files

                  Comment


                    #10
                    I suspect maybe you aren't compiling your code qkracer. Hit F5 to compile your indicator.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Got it working... .Thanks everyone for your help, think i can get what I want from here. Much appreciated

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by mjairg, 07-20-2023, 11:57 PM
                      3 responses
                      213 views
                      1 like
                      Last Post PaulMohn  
                      Started by TheWhiteDragon, 01-21-2019, 12:44 PM
                      4 responses
                      544 views
                      0 likes
                      Last Post PaulMohn  
                      Started by GLFX005, Today, 03:23 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post GLFX005
                      by GLFX005
                       
                      Started by XXtrader, Yesterday, 11:30 PM
                      2 responses
                      12 views
                      0 likes
                      Last Post XXtrader  
                      Started by Waxavi, Today, 02:10 AM
                      0 responses
                      7 views
                      0 likes
                      Last Post Waxavi
                      by Waxavi
                       
                      Working...
                      X