Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DrawArrowUp on custom indicator

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

    DrawArrowUp on custom indicator

    Hello,

    I made a very simple double EMA indicator and am attempting to have it draw arrows upon a crossover. The following freezes and shuts me down every time. It works fine without the Arrow code:

    PHP Code:
    protected override void OnBarUpdate()
            {
                fastEma.Set(CurrentBar == 0 ? Input[0] : Input[0] * 2.0 / (1 + Fast) + (1 - (2.0 / (1 + Fast))) * fastEma[1]);
                slowEma.Set(CurrentBar == 0 ? Input[0] : Input[0] * 2.0 / (1 + Slow) + (1 - (2.0 / (1 + Slow))) * slowEma[1]);
                
                double FastEMA = fastEma[0];
                double SlowEMA = slowEma[0];
                
                FastEma.Set(FastEMA);
                SlowEma.Set(SlowEMA);
                
                if(CrossAbove(RaiderEMACross(Close, 12, 26).FastEma, RaiderEMACross(Close, 12, 26).SlowEma, 1));
                {
                    DrawArrowUp("CurrentBar", 0, RaiderEMACross(Close, fast, slow)[0] - 1, Color.Lime);
                }
                
            } 
    
    Any help would be appreciated - thanks.
    Last edited by dsraider; 06-02-2012, 10:25 AM.

    #2
    dsraider,

    Are there any error messages in your Control Center > Log tab?
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Hi Adam,

      Afraid not. It just freezes and Windows shuts it down. When I boot up again, the log is wiped clean.

      Comment


        #4
        why not attach it a different way like this:

        Add(new Plot(Color.Red, PlotStyle.ArrowDown, "Down"));

        Comment


          #5
          Hey zoom,

          Unfortunately, that shut me down as well. The good news, I guess, is that I now know it's the condition that's doing it and not the arrow.

          Odd. It's almost as if I've created an endless loop somehow. Any ideas?

          Comment


            #6
            dsraider,

            If you replace the RaiderEMA with something else like a standard EMA does the issue persist?
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Hey Adam,

              I get what you're saying but I'm not sure it would make a difference. PLEASE correct me if I'm wrong.

              The code is I used is the standard EMA code. However, in order to code for a cross, I used two and simply changed their names to fast and slow. So, I'm not even sure how I could try two standard EMAs without making a custom indicator, since this isn't a strategy.

              Thanks,
              DS

              Comment


                #8
                dsraider,

                You can just use CrossAbove(EMA(FastPeriod), EMA(SlowPeriod) ); with FastPeriod and SlowPeriod being user defined input.

                I suggested that you try something else there to ensure that the RaiderEMA doesn't have any errors in it. It may be your strategy is fine but the indicator has an issue.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  This is an indicator; not a strategy. I'm not sure how I can use two EMAs in an indicator, without giving them two different names under a new indicator name.

                  Comment


                    #10
                    dsraider,

                    If you call EMA(10) and EMA(12) these are two different EMA's. How are you trying to use the EMAs? I can see you are using a cross.
                    Adam P.NinjaTrader Customer Service

                    Comment


                      #11
                      I think this is what you mean...

                      I'm plotting a fast and slow EMA based on Input. This way, I can use it on price or on another indicator. That part of the code works fine. I just want to plot an arrow as well for a visual signal.

                      Comment


                        #12
                        Hello dsraider,
                        Please try this code

                        Code:
                        protected override void OnBarUpdate() 
                                { 
                                    fastEma.Set(CurrentBar == 0 ? Input[0] : Input[0] * 2.0 / (1 + Fast) + (1 - (2.0 / (1 + Fast))) * fastEma[1]); 
                                    slowEma.Set(CurrentBar == 0 ? Input[0] : Input[0] * 2.0 / (1 + Slow) + (1 - (2.0 / (1 + Slow))) * slowEma[1]); 
                                     
                                    double FastEMA = fastEma[0]; 
                                    double SlowEMA = slowEma[0]; 
                                     
                                    FastEma.Set(FastEMA); 
                                    SlowEma.Set(SlowEMA); 
                                     
                                  [B]  if(CrossAbove(FastEma, SlowEma, 1)); [/B]
                                    { 
                                        [B]DrawArrowUp("up" + CurrentBar, 0, FastEma[0] - TickSize, Color.Lime); [/B]
                                    } 
                                     
                                }
                        Please let me know if I can assist you any further.
                        Last edited by NinjaTrader_Joydeep; 06-04-2012, 06:49 AM.
                        JoydeepNinjaTrader Customer Service

                        Comment


                          #13
                          Hey Joydeep,

                          It works! I'm not sure if it's your code, the fact that I left a semi-colon after my if statement, or both. But it works. Thanks.

                          One more question, though. The arrow is plotting on the price panel. My indicator is in a separate one down below. Am I missing a piece of code?

                          Thanks again,
                          DS

                          Comment


                            #14
                            Hello dsraider,
                            Glad you could work it out.

                            To draw the arrow on the indicator panels please set DrawOnPricePanel to false.


                            Please let me know if I can assist you any further.
                            JoydeepNinjaTrader Customer Service

                            Comment


                              #15
                              That did it. Thanks again for all your help.

                              DS

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              605 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              351 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              560 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              561 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X