Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Add today's value and yesterday's value and create a plot

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

    Add today's value and yesterday's value and create a plot

    My scripting skills are limited so I need a little assistance. The code below produces an error referring to to the last line, "Cannot apply indexing with [] to an expression of type 'double'".

    Code:
    			double kjmvp	= 1-(Close[0]-Low[5])/(High[5]-Low[5]);
    			double mjvmp	= 1-(Close[0]-Low[22])/(High[22]-Low[22]);
    			double lt		= (Close[0]-Low[200])/(High[200]-Low[200]);
    			double REEI	= (kjmvp+mjvmp+lt)/3;
    						
    			E2EIplot[0] = (REEI[0]*0.6)+(REEI[1]*0.4);
    A short description of what I want to do is that I want to create a plot with the result of REEI from today and yesterday.

    Any advice would be deeply appreciated.
    Last edited by chrille; 07-04-2017, 04:22 AM.

    #2
    Hello chrille,

    Thank you for your post.

    The REEI double will instead need to be a Series<double> in order to call prior values stored on each bar.

    For information on Series<T> types please visit the following link: http://ninjatrader.com/support/helpG...us/seriest.htm

    Please let me know if you have any questions.

    Comment


      #3
      Hi Patrick,

      Thanks! I added a Series<double> and it now compiles, but it's not drawing a plot, so something isn't quite right but I cant really find what and where.

      Code:
      #region Using declarations
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Gui;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.SuperDom;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      using NinjaTrader.NinjaScript.DrawingTools;
      #endregion
      
      //This namespace holds Indicators in this folder and is required. Do not change it. 
      namespace NinjaTrader.NinjaScript.Indicators
      {
      	public class E2EI : Indicator
      	{
      		private Series<double> 	REEI;
      	
      		protected override void OnStateChange()
      		{
      			if (State == State.SetDefaults)
      			{
      				Description									= @"E2 Edge Index";
      				Name										= "E2EI";
      				Calculate									= Calculate.OnBarClose;
      				IsOverlay									= false;
      				DisplayInDataBox							= true;
      				DrawOnPricePanel							= true;
      				DrawHorizontalGridLines						= true;
      				DrawVerticalGridLines						= true;
      				PaintPriceMarkers							= true;
      				ScaleJustification							= NinjaTrader.Gui.Chart.ScaleJustification.Right;
      				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
      				//See Help Guide for additional information.
      				IsSuspendedWhileInactive					= true;
      				AddPlot(Brushes.Orange, "E2EIplot");
      				AddLine(new Stroke(Brushes.Green, DashStyleHelper.Dot, 1), 0.8, "Upper");
      				AddLine(new Stroke(Brushes.Gray, DashStyleHelper.Dot, 1), 0.5, "Middle");
      				AddLine(new Stroke(Brushes.Crimson, DashStyleHelper.Dot, 1), 0.3, "Lower");
      							
      			
      			}
      			else if (State == State.Configure)
      			{
      				REEI		= new Series<double>(this);
      			}
      		}
      
      		protected override void OnBarUpdate()
      		{
      			
      			double smr	= 1-(Close[0]-Low[5])/(High[5]-Low[5]);
      			double imr	= 1-(Close[0]-Low[22])/(High[22]-Low[22]);
      			double lt	= (Close[0]-Low[200])/(High[200]-Low[200]);
      			REEI[0]		= (smr+imr+lt)/3;
      						
      			E2EIplot[0] = (REEI[0]*0.6)+(REEI[1]*0.4);
      		}
      
      		#region Properties
      
      		[Browsable(false)]
      		[XmlIgnore]
      		public Series<double> E2EIplot
      		{
      			get { return Values[0]; }
      		}
      		#endregion
      
      	}
      }
      
      #region NinjaScript generated code. Neither change nor remove.
      
      namespace NinjaTrader.NinjaScript.Indicators
      {
      	public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
      	{
      		private E2EI[] cacheE2EI;
      		public E2EI E2EI()
      		{
      			return E2EI(Input);
      		}
      
      		public E2EI E2EI(ISeries<double> input)
      		{
      			if (cacheE2EI != null)
      				for (int idx = 0; idx < cacheE2EI.Length; idx++)
      					if (cacheE2EI[idx] != null &&  cacheE2EI[idx].EqualsInput(input))
      						return cacheE2EI[idx];
      			return CacheIndicator<E2EI>(new E2EI(), input, ref cacheE2EI);
      		}
      	}
      }
      
      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
      	public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
      	{
      		public Indicators.E2EI E2EI()
      		{
      			return indicator.E2EI(Input);
      		}
      
      		public Indicators.E2EI E2EI(ISeries<double> input )
      		{
      			return indicator.E2EI(input);
      		}
      	}
      }
      
      namespace NinjaTrader.NinjaScript.Strategies
      {
      	public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
      	{
      		public Indicators.E2EI E2EI()
      		{
      			return indicator.E2EI(Input);
      		}
      
      		public Indicators.E2EI E2EI(ISeries<double> input )
      		{
      			return indicator.E2EI(input);
      		}
      	}
      }
      
      #endregion

      Comment


        #4
        Got some help and solved the problem, added if (CurrentBar < 200) return; to OnBarUpdate.

        But now there's another problem, with the logic. It should be a value between 0 and 1.

        Comment


          #5
          Hello chrille,

          Thank you for your response.

          So the "E2EIplot" is producing values other than 0 and 1? How are you ensuring the 0 or 1 is produced from your calculation?

          I look forward to your response.

          Comment


            #6
            I'm checking my calculations and research. I've made a mistake somewhere, just need to find it.

            Comment


              #7
              Got it working. A friendly developer that I met on another forum pointed out that in order to find the value for example the highest of 5 days/lowest of 5 days, I needed to use HighestBar(High, 5); / LowestBar(Low, 5). With that information and the Ninja script language reference I got my calculations right.

              One thing left though that is not working; I want the Market Analyzer to display the current value of the E2EIplot[0] put it only says 0...

              Comment


                #8
                Hello chrille,

                Thank you for your response.

                If this an indicator we could test on our end?

                If so, please send to platformsupport[at]ninjatrader[dot]com with 'ATTN: Patrick H' in the subject line and a reference to this thread in the body of the email.

                You can export your indicator by going to Tools > Export > NinjaScript Add On > Add > select your indicator > OK > Export > name the file 'NTsupport' > Save.

                The file will be located under Documents\NinjaTrader 8\bin\Custom\ExportNinjaScript. Please attach the file to your email.

                I look forward to assisting you further.

                Comment


                  #9
                  Patrick,

                  I have e-mailed the indicator as requested.

                  Thanks!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  649 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  370 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  109 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  574 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  576 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X