Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need Code Help for MA

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

    Need Code Help for MA

    I am looking to make the MA scan for stocks off the narrowest range indicator,

    I need to add a line of code to the indicator so that if the bar is a NR inside the MA can create a alert or filter for it.

    So when the indicator plots on the chart or is "true" it has a value which I can then create the condition for scanning in MA.

    does anyone know the line of code I need to add? I would assume something like "if true value = 1" or something like this or

    "The indicator could plot 1 when conditions are true and 0 otherwise. You could then filter for when this custom indicator is 1"

    if anyone knows the code I need to add I would appreciate it..

    TIA
    Reed

    #2
    Hi tshirtdeal,

    You may want to consider editing the indicator itself and adding a plot within the same condition that colors the background.

    Unfortunately, I cannot write this for you (copying this verbatim will cause errors without the proper plot setup in Initialize() and Properties ), but perhaps something like...
    Code:
    if (nrbar==0)
        {
    				
            BackColor = nr7color;
            PlotName.Set(1);
        }
    else
        {
            PlotName.Set(0);
        }
    TimNinjaTrader Customer Service

    Comment


      #3
      Thanks Tim

      it's actually not the NR7 indicator (which paints the entire background to signal the candle) it is the narrowest range of X period, it actually paints the candle


      it also has the option to make "inside candle" = true which is what I need MA to be able and scan my list for...

      Here is the basics main code, if you have any ideas or how to do it I would really appreciate it, I know it has to be simple... but then again maybe not for all I know..

      P.S - and "inside bar" would be defined as one in which the high and low are within the previous bar, I would actually like to change the code so that the bars range could be less than or equal to as well...

      ----------------------------------------

      if (CurrentBar < period)
      return;

      if (insidePattern && High[0] >= High[1] || Low[0] <= Low[1])
      return;

      for (int index = 0; index < period; index++)
      {
      if (Range()[0] > Range()[index])
      break;

      if (index == period - 1)
      BarColor = patternColor;

      Comment


        #4
        Hi tshirtdeal,

        If you are not a programmer yourself, any of our NinjaScript consultants could assist.
        More info at - http://www.ninjatrader.com/webnew/pa...injaScript.htm

        If you want more info on getting started with NinjaScript I can supply that info as well.
        TimNinjaTrader Customer Service

        Comment


          #5
          hey

          okay, can you point me in the direction of creating and defining plots?

          Thanks,

          Comment


            #6
            Hi tshirtdeal,

            This tutorial will guide you through creating a plot in the wizard (doing this will setup much of the process for you), and then show you how to set that plot to different values.

            Tutorial at - http://www.ninjatrader-support.com/H...tml?Overview23
            TimNinjaTrader Customer Service

            Comment


              #7
              One Last Try

              Hi Tim, thanks, can you do me one last favor and look at this code and see what I am doing wrong? What should my plot values be for the "inside bar?
              --------------------

              {
              Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Bar, "Plot0"));
              CalculateOnBarClose = true;
              Overlay = true;
              PriceTypeSupported = false;
              upcolor = Color.Yellow;
              insidebar = new DataSeries(this);
              soundon = false;


              }

              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
              // Use this method for calculating your indicator values. Assign a value to each
              // plot below by replacing 'Close[0]' with your own formula.
              Plot0.Set(insidebar[1]);

              if (CurrentBar < 1) return;

              range1 = Math.Abs(Close[0]-Open[0]);
              range2 = Math.Abs(Close[1]-Open[1]);


              // Check for InsideBar pattern

              if(High[0] <= High[1] && Low[0] >= Low[1])

              {
              BarColor = upcolor;
              insidebar.Set(1);
              Plot0.Set(1);
              if(soundon)
              {
              if (!Historical)
              PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\Alert4.wav");
              }
              }
              else
              insidebar.Set(0);
              Plot0.Set(1);
              }

              #region Properties
              [CategoryAttribute("Plots")]
              [DescriptionAttribute("Inside BAr Color")]
              [XmlIgnoreAttribute()]
              [NinjaTrader.Gui.Design.DisplayNameAttribute("Insid e BAr Color")]
              public Color UpColor

              {
              get { return upcolor; }
              set { upcolor = value; }
              }

              [BrowsableAttribute(false)]
              public string UpColorSerialize


              {
              get { return NinjaTrader.Gui.Design.SerializableColor.ToString( upcolor); }
              set { upcolor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
              }

              [Browsable(false)]
              [XmlIgnore()]
              public DataSeries Insidebar
              {
              get
              {
              Update();
              return insidebar;

              }
              }

              [NinjaTrader.Gui.Design.DisplayNameAttribute("Sound on?")]
              [DescriptionAttribute("Sound on?")]
              [CategoryAttribute("Parameters")]
              public bool SoundOn

              {
              get { return soundon ; }
              set { soundon = value; }
              }
              #endregion
              }
              }

              Comment


                #8
                Hello tshirtdeal,

                The market analyzer is looking for only Plot components of indicators. You can't select a non-plotted data series from the market analyzer.

                Below is just the part of your code that will assign a value of 1 when conditions are true and a zero otherwise. It assigns this to the only plot: Plot0. If you don't have a need for a second plot, then you can remove all the InsideBar references.

                Code:
                 
                if(High[0] <= High[1] && Low[0] >= Low[1]) 
                {
                Plot0.Set(1);
                }
                 
                else
                {
                Plot0.Set(0);
                }

                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Don't Know

                  I dont't know seems easy enough but it won't work, just error after erro,

                  can't I just create an inside bar formula with :

                  (High[0] <= High[1] && Low[0] >= Low[1])

                  or:

                  Plot0.Set(High[0] <= High[1] && Low[0] >= Low[1] ? 1 : 0);

                  i just need this simple thing to plot when a bar is inside (or equal) to the previous range for MA,

                  TIA

                  Comment


                    #10
                    code:

                    can you explain to me what is wrong with this code? It creates the indicator and puts the indicator on my chart but does not work (it shows no bars for the inside candles, )

                    {
                    Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Bar, "Plot0"));
                    CalculateOnBarClose = true;
                    Overlay = false;
                    PriceTypeSupported = false;
                    }

                    /// <summary>
                    /// Called on each bar update event (incoming tick)
                    /// </summary>
                    protected override void OnBarUpdate()
                    {
                    // Use this method for calculating your indicator values. Assign a value to each
                    // plot below by replacing 'Close[0]' with your own formula.
                    Plot0.Set(High[0] <= High[1] && Low[0] >= Low[1] ? 1 : 0);
                    }

                    Comment


                      #11
                      Some Problems Here

                      I just had a guy who does very great coding for big people make the code, it works for him but not for me...

                      very frustrating .... is it a problem with my NT platform?

                      what do I need to do?
                      Last edited by tshirtdeal; 06-15-2010, 11:44 PM.

                      Comment


                        #12
                        Hi tshirtdeal,

                        Are you getting any errors in the Log tab of the control center when applying this indicator?
                        TimNinjaTrader Customer Service

                        Comment


                          #13
                          hey

                          Hi Tim,

                          no errors, everything I have tried complies without errors and my friend who is a great NT script guy create something and sent me a grid pic of it working as well...

                          the indicators will not plot on the chart and I cannot get the MA to show a 1 if inside bar is true or 0 if not and be able to run condistions which is all I need, this really should be very simple, I am not a pro script guy but have made many of these simple type scripts, don't get it...

                          thanks for any help

                          Comment


                            #14
                            Hi tshirtdeal,

                            Can you export this using "File>Utilities>Export" so that I can briefly test it on my end.
                            TimNinjaTrader Customer Service

                            Comment


                              #15
                              Here is the one my friend did

                              GMInsidebar.zip


                              thanks for the help!

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Today, 05:17 AM
                              0 responses
                              20 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              119 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              63 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              41 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              45 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X