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

SMA crossover paintbars

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

    SMA crossover paintbars

    Hi,

    please tell me how to painting bars when my SMA = 5 crosses SMA = 20 line. i want all bars painting. i tried my level best but i get only one starting bar painting.but i want all bars painting.

    if (CrossAbove(FastPlot, SlowPlot, 1))

    {
    DrawArrowUp("up arrow" + CurrentBar, false, 0, SlowPlot[0] - 2 * TickSize, Color.Green);


    BarColor=Color.Green;


    }


    Thankyou.

    #2
    Hello paruchuriphani,

    Thank you for your post.

    You are looking to have every bar after the CrossAbove condition is true to be painted, correct?

    As you currently, have your code setup the bars are only colored when on the bar the CrossAbove condition is true and not every bar after that.

    You need to setup a bool such as the following:
    Code:
    if (CrossAbove(FastPlot, SlowPlot, 1))
    {	
    DrawArrowUp("up arrow" + CurrentBar, false, 0, SlowPlot[0] - 2 * TickSize, Color.Green);
    BarColor=Color.Green;	
    bool colorBar = true;
    }
    
    if(colorBar)
    {
    BarColor=Color.Green;
    }
    Please let me know if I may be of further assistance.

    Comment


      #3
      hi,

      Thank you so much for your reply

      Yes I am looking for every bar after the SMA 20 CrossAbove SMA 5 condition is true to be painted Green color. vice versa SMA 5 Crossbelow Condition is true to be painted Red color
      from that bar.


      "The name 'colorBar' does not exist in the corrent context" this is error message came when i Compile code...
      Last edited by paruchuriphani; 02-25-2013, 10:18 AM.

      Comment


        #4
        Hello paruchuriphani,

        Thank you for your response.

        My mistake there as we will need to define this in the Variables section:
        Code:
                #region Variables
        		private bool colorBar = false;
        And then use this in our code in the following manner:
        Code:
        if (CrossAbove(FastPlot, SlowPlot, 1))
        {	
        DrawArrowUp("up arrow" + CurrentBar, false, 0, SlowPlot[0] - 2 * TickSize, Color.Green);
        BarColor=Color.Green;	
        colorBar = true;
        }
        
        if(colorBar)
        {
        BarColor=Color.Green;
        }
        We will also need to set the coloBar bool back to false within the code at some point, such as when CrossBelow(FastPlot, SlowPlot, 1).

        Please let me know if I may be of further assistance.

        Comment


          #5
          Hi,

          Thanks for your reply

          code is not working properly please look at this code. when i Compile this code i get only red painted bars in my chat. i want Green bars in bullish trend & Red in bearish trend... please help me.

          private int fast_Period = 4;
          private int slow_Period = 20;
          private bool colorBar = true;





          if (CrossAbove(FastPlot, SlowPlot, 1))
          {
          DrawArrowUp("up arrow" + CurrentBar, false, 0, SlowPlot[0] - 2 * TickSize, Color.Green);
          BarColor=Color.Green;
          colorBar = true;
          }

          if(colorBar)
          {
          BarColor=Color.Green;
          }


          if (CrossBelow( SlowPlot,FastPlot, 1))
          {
          DrawArrowDown("up arrow" + CurrentBar, false, 0, SlowPlot[0] - 2 * TickSize, Color.Red);
          BarColor=Color.Red;
          colorBar = true;
          }

          if(colorBar)
          {
          BarColor=Color.Red;
          }
          Last edited by paruchuriphani; 02-25-2013, 11:00 AM.

          Comment


            #6
            Hello paruchuriphani,

            Thank you for your response.

            You will need two bools in this case, one for the Red and one for the Green and make sure to set them to false in the variables section first.

            The code below shows how to use these two bools together, make sure you set them to false when the other is true:
            Code:
            private int fast_Period = 4; 
            private int slow_Period = 20;
            private bool colorBarRed = false;
            private bool colorBarGreen = false;
            
            
            
            
            if (CrossAbove(FastPlot, SlowPlot, 1))
            {	
            DrawArrowUp("up arrow" + CurrentBar, false, 0, SlowPlot[0] - 2 * TickSize, Color.Green);
            BarColor=Color.Green;	
            colorBarGreen = true;
            colorBarRed = false;
            }
            
            if(colorBarGreen)
            {
            BarColor=Color.Green;
            }
            
            
            if (CrossBelow( SlowPlot,FastPlot, 1))
            {	
            DrawArrowDown("up arrow" + CurrentBar, false, 0, SlowPlot[0] - 2 * TickSize, Color.Red);
            BarColor=Color.Red;	
            colorBarRed = true;
            colorBarGreen = false;
            }
            
            if(colorBarRed)
            {
            BarColor=Color.Red;
            }
            Please let me know if I may be of further assistance.

            Comment


              #7
              Hi,

              Thankyou so much PatrickH

              your code is working very well thank you so much....

              Comment


                #8
                Hi, PatrickH

                I test our (SMA)code in another indicator. I want same result what we get in SMA crossover indicator. when my indicator shows green Up arrow i want only green bars. vice versa for red arrows.

                I alredy tryed for this result but i can't. i get only one starting candel change. please help me.



                if(Trend[0] && !Trend[1])
                {

                UpTrend.Set(Median[0] - ATR(Lenght)[0]*Multiplier);
                UpTrend.Set(1, DownTrend[1]);


                if (ShowArrows)
                {
                DrawArrowUp(CurrentBar.ToString(), true, 0, UpTrend[0] - TickSize, Color.Blue);
                }
                BarColor=Color.Yellow;
                colorBar = true;


                if(colorBar)
                {
                BarColor=Color.Yellow;
                }

                }
                else
                if (!Trend[0] && Trend[1])

                {
                DownTrend.Set(Median[0] + ATR(Lenght)[0]*Multiplier);
                DownTrend.Set(1, UpTrend[1]);

                if (ShowArrows)
                {
                DrawArrowDown(CurrentBar.ToString(), true, 0, DownTrend[0] + TickSize, Color.Red);
                }


                BarColor=Color.Red;
                colorBar = true;

                if(colorBar)
                {
                BarColor=Color.Red;
                }
                }
                Attached Files
                Last edited by paruchuriphani; 02-25-2013, 02:27 PM.

                Comment


                  #9
                  Hello paruchuriphani,

                  Thank you for your update.

                  Please try the following:
                  Code:
                  private bool colorBarRed = false;
                  private bool colorBarYellow = false;
                  
                  if(Trend[0] && !Trend[1])
                  {
                  
                  UpTrend.Set(Median[0] - ATR(Lenght)[0]*Multiplier);
                  UpTrend.Set(1, DownTrend[1]);
                  
                  
                  if (ShowArrows)
                  {
                  DrawArrowUp(CurrentBar.ToString(), true, 0, UpTrend[0] - TickSize, Color.Blue);
                  BarColor=Color.Yellow;
                  colorBarGreen = true;
                  colorBarRed = false;
                  }
                  if(colorBarYellow)
                  {
                  BarColor=Color.Yellow;
                  }
                  
                  }
                  else
                  if (!Trend[0] && Trend[1])
                  
                  {
                  DownTrend.Set(Median[0] + ATR(Lenght)[0]*Multiplier);
                  DownTrend.Set(1, UpTrend[1]);
                  
                  if (ShowArrows)
                  {
                  DrawArrowDown(CurrentBar.ToString(), true, 0, DownTrend[0] + TickSize, Color.Red);
                  BarColor=Color.Red;
                  colorBarRed = true;	
                  colorBarYellow = false;
                  }
                  if(colorBarRed)
                  {
                  BarColor=Color.Red;
                  }
                  }
                  Please let me know if I may be of further assistance.

                  Comment


                    #10
                    HI PatrickH,

                    Thank you so much for your reply...

                    But code is not working. when i Compile this code i get only one Yellow painted bars in my chat.


                    this is my complete please help me...

                    #region Variables

                    private int lenght = 20;
                    private double multiplier = 2.618;
                    private bool showArrows = false;
                    private bool colorBarRed = true;
                    private bool colorBarYellow = true;


                    protected override void Initialize()
                    {
                    Add(new Plot(Color.Green, PlotStyle.Line, "UpTrend"));
                    Add(new Plot(Color.Red, PlotStyle.Line, "DownTrend"));
                    CalculateOnBarClose = true;
                    Overlay = true;
                    PriceTypeSupported = false;
                    Trend = new BoolSeries(this);
                    }


                    protected override void OnBarUpdate()
                    {
                    if (CurrentBar < Lenght)
                    {
                    Trend.Set(true);
                    UpTrend.Set (Close[0]);
                    DownTrend.Set(Close[0]);
                    return;
                    };
                    if (Close[0]>DownTrend[1])
                    Trend.Set(true);
                    else
                    if (Close[0]<UpTrend[1])
                    Trend.Set(false);
                    else
                    Trend.Set(Trend[1]);

                    if(Trend[0] && !Trend[1])

                    {

                    UpTrend.Set(Median[0] - ATR(Lenght)[0]*Multiplier);
                    UpTrend.Set(1, DownTrend[1]);

                    {
                    BarColor=Color.Yellow;
                    colorBarYellow = false;
                    colorBarRed = true;
                    }

                    if(colorBarYellow)
                    {
                    BarColor=Color.Yellow;
                    }
                    }


                    else
                    if (!Trend[0] && Trend[1])
                    {

                    DownTrend.Set(Median[0] + ATR(Lenght)[0]*Multiplier);
                    DownTrend.Set(1, UpTrend[1]);

                    {
                    BarColor=Color.Red;
                    colorBarRed = true;
                    colorBarYellow = false;
                    }

                    if(colorBarRed)
                    {
                    BarColor=Color.Red;
                    }
                    }

                    else
                    if (Trend[0])
                    UpTrend.Set((Median[0] - ATR(Lenght)[0]*Multiplier) > UpTrend[1] ? (Median[0] - ATR(Lenght)[0]*Multiplier) : UpTrend[1]);
                    else
                    DownTrend.Set((Median[0] + ATR(Lenght)[0]*Multiplier) < DownTrend[1] ? (Median[0] + ATR(Lenght)[0]*Multiplier) : DownTrend[1]);
                    }
                    Last edited by paruchuriphani; 02-26-2013, 08:15 AM.

                    Comment


                      #11
                      Hello paruchuriphani,

                      Thank you for your response.

                      Please send me your full indicator file or a toy version in it's .cs format to support[at]ninjatrader[dot]com with 'ATTN: Patrick' in the subject line and a reference to ticket number 798177 in the body of the e-mail.

                      For information on exporting NinjaScript files please visit the following link: http://www.ninjatrader.com/support/h...nt7/export.htm

                      I look forward to your response.

                      Comment


                        #12
                        Hello paruchuriphani,

                        Thank you for your response.

                        Take the colorBarRed and colorBarYellow conditions out of the other conditions and paste them under all other conditions in the following manner:
                        Code:
                        if (CurrentBar < Lenght)
                        {
                        Trend.Set(true);
                        UpTrend.Set (Close[0]);
                        DownTrend.Set(Close[0]);
                        return;
                        };
                        if (Close[0]>DownTrend[1])
                        Trend.Set(true);
                        else
                        if (Close[0] Trend.Set(false);
                        else
                        Trend.Set(Trend[1]);
                        
                        if(Trend[0] && !Trend[1])
                        
                        {
                        
                        UpTrend.Set(Median[0] - ATR(Lenght)[0]*Multiplier);
                        UpTrend.Set(1, DownTrend[1]);
                        
                        {
                        BarColor=Color.Yellow;
                        colorBarYellow = false;
                        colorBarRed = true;
                        }
                        
                        }
                        
                        else
                        if (!Trend[0] && Trend[1])
                        {
                        
                        DownTrend.Set(Median[0] + ATR(Lenght)[0]*Multiplier);
                        DownTrend.Set(1, UpTrend[1]);
                        
                        {
                        BarColor=Color.Red;
                        colorBarRed = true;
                        colorBarYellow = false;
                        }
                        
                        }
                        
                        else
                        if (Trend[0])
                        UpTrend.Set((Median[0] - ATR(Lenght)[0]*Multiplier) > UpTrend[1] ? (Median[0] - ATR(Lenght)[0]*Multiplier) : UpTrend[1]);
                        else
                        DownTrend.Set((Median[0] + ATR(Lenght)[0]*Multiplier) < DownTrend[1] ? (Median[0] + ATR(Lenght)[0]*Multiplier) : DownTrend[1]);
                        [B]if(colorBarYellow)
                        {
                        BarColor=Color.Yellow;
                        }
                        if(colorBarRed)
                        {
                        BarColor=Color.Red;
                        }[/B]
                        Please let me know if I may be of further assistance.

                        Comment


                          #13
                          Hi Patrick,

                          wow

                          now my indicator is working very well

                          thank you so much.
                          Last edited by paruchuriphani; 02-27-2013, 09:29 AM.

                          Comment


                            #14
                            Hi PatrickH,

                            i have one more small doubt

                            please give me Ticket number . i will send my code to you through email .

                            thank you,

                            Comment


                              #15
                              Hello paruchuriphani,

                              Thank you for your response.

                              Please send your screenshot to support[at]ninjatrader[dot]com with 'ATTN: Patrick - 798177' in the subject and a reference to this thread in the body of the e-mail: http://www.ninjatrader.com/support/f...ad.php?t=56159

                              I look forward to your response.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by PaulMohn, Today, 02:06 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post PaulMohn  
                              Started by Mindset, Today, 01:27 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by EB Worx, 03-07-2023, 05:05 AM
                              4 responses
                              97 views
                              1 like
                              Last Post cls71
                              by cls71
                               
                              Started by patricia70, 11-23-2020, 10:17 AM
                              17 responses
                              546 views
                              1 like
                              Last Post PaulMohn  
                              Started by Jltarrau, 04-28-2024, 10:18 PM
                              1 response
                              14 views
                              0 likes
                              Last Post brucerobinson  
                              Working...
                              X