NexusFi: Find Your Edge


Home Menu

 





Performance Suggestions Please


Discussion in NinjaTrader

Updated
    1. trending_up 1,438 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 1 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 tornadoatc 
Ft. Lauderdale Florida
 
Experience: Intermediate
Platform: Tradestation
Posts: 17 since Apr 2010
Thanks Given: 31
Thanks Received: 3

Hello All,

I have recently left the TS realm and I now attemting to code some indicators in NT7. I have read through many of the threads regarding NT7 performance suggestions and I don't quite have a grasp of the OOP aspects enough to make my code most efficient. I am still having problems understanding how best to use other indicator classes in my indicator.

In my code I am calling Bollinger(Close, .25, iWaveRiderLen).Middle[0] several times in the logic of OnBarUpdate(). I don't believe this is most efficient. I believe the best way is to declare a variable of type Bollinger in the Variables section (ie. Bollinger myBoll) and then instantiate a new object in the Initialize() (Bollinger myBool = new Bollinger()). But I was not able to get that working.

Ur help is greatly appreciated as I attempt to get up on the learning curve of C#.

Here is my indicator:
 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    /// <summary>
    /// Momentum Weitghted Avg Price 
    /// </summary>
    [Description("Momentum Weitghted Avg Price ")]
    public class IBDMWAP1 : Indicator
    {
        #region Variables
        // Wizard generated variables
            private int iWaveRiderLen = 14; // Default setting for IWaveRiderLen
        // User defined variables (add any user defined variables below)
		
			private double movavg = 0 ; 
			//double xavg = 0 ; 
			//EMA myEMA = new EMA() ; 
			//Bollinger myBoll = new Bollinger() ; 
			//double bollUpper = 0 ; 
			//double bollMiddle = 0 ; 
			//double bollLower = 0 ; 
			
			private BoolSeries isGreenWave ; 
			private BoolSeries isRedWave ; 
			private bool isStartGreenWave = false ; 
			private bool isStartRedWave = false ; 
			private bool isContGreenWave = false ; 
			private bool isContRedWave = false ; 

			private double currWaveHigh = 0 ; 
			private double currWaveLow  = 999999.00 ; 
			private double redWaveLow = 999999.00 ; 
			private double greenWaveHigh = 0 ; 
			private double MWAP1 = 0 ; 
		
		#endregion

        /// <summary>
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        /// </summary>
        protected override void Initialize()
        {
            Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Dot, "Plot0"));
            Overlay				= true ;
			CalculateOnBarClose = true ; 
	
			isGreenWave = new BoolSeries(this) ; 
			isRedWave   = new BoolSeries(this) ; 
			
		}

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
			//myEMA = EMA(4);						
			//myBoll = Bollinger(Close, .25, iWaveRiderLen) ; 
			//double bollLower = myBoll.Lower() ; 
			//bollMiddle = myBoll.Middle[0] ; 
			//bollUpper = myBoll.Upper[0] ; 
			
			// isPriorBarGreenWave = 
			if (EMA(4)[0] >= Bollinger(Close, .25, iWaveRiderLen).Middle[0] && Close[0] > Bollinger(Close, .25, iWaveRiderLen).Upper[0]) 
			{
				isGreenWave.Set(true) ; 
				isRedWave.Set(false) ;
			}
			else if (EMA(4)[0] <= Bollinger(Close, .25, iWaveRiderLen).Middle[0] && Close[0] < Bollinger(Close, .25, iWaveRiderLen).Lower[0]) 
			{
				isRedWave.Set(true) ; 
				isGreenWave.Set(false) ;
			} 
			Print("Date " + Time[0].ToString("yyyyMMdd HH:mm:ss") + " isGreenWave: " + isGreenWave + " isRedWave: " + isRedWave) ; 

			bool isStartGreenWave = isGreenWave[0] && isGreenWave[1] == false ; 
			bool isStartRedWave   = isRedWave[0] && isRedWave[1] == false ; 
			bool isContGreenWave  = isGreenWave[0] && isGreenWave[1]; 
			bool isContRedWave    = isRedWave[0] && isRedWave[1]; 
			
			if (isStartGreenWave) 
			{
				redWaveLow = currWaveLow ; 
				currWaveHigh = High[0] ; 
				currWaveLow  = Low[0] ; 
			
			}
			else if (isStartRedWave) 
			{
				greenWaveHigh = currWaveHigh ; 
				currWaveHigh = High[0] ; 
				currWaveLow = Low[0] ; 
			}
			else if (isContGreenWave) 
			{
				if (High[0] > currWaveHigh) 
					currWaveHigh = High[0] ; 
			}
			else if (isContRedWave) 
			{
				if (Low[0] < currWaveLow) 
					currWaveLow = Low[0] ; 
			}
			
			if (isStartGreenWave || isStartRedWave) 
				MWAP1 = (greenWaveHigh + redWaveLow) * 0.5 ; 
			
            Plot0.Set(MWAP1);
        }

        #region Properties
        [Browsable(false)]	// this line prevents the data series from being displayed in the indicator properties dialog, do not remove
        [XmlIgnore()]		// this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
        public DataSeries Plot0
        {
            get { return Values[0]; }
        }

        [Description("Wave Rider Length")]
        [GridCategory("Parameters")]
        public int IWaveRiderLen
        {
            get { return iWaveRiderLen; }
            set { iWaveRiderLen = Math.Max(1, value); }
        }
        #endregion
    }
}
Thanks,
ATC


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Iran Ceasefire Surges to 19.5% on US 15-Point Plan -- 82 …
Prediction Markets & Event Contracts
Penalties in Budapest, Peace Deadline in Tehran: Arsenal …
Prediction Markets & Event Contracts
Trump Truth Social Fires Hormuz From 10% to 59% -- Arsen …
Prediction Markets & Event Contracts
Topstep Acquires The Futures Desk -- Prop Firm Consolida …
Funded Trading Evaluation Firms
Tradeify 3.0 Overhauls Futures Prop Firm Model -- One-Ti …
Funded Trading Evaluation Firms
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Lady Vols Primer: Trading Volatility Journal
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Trying to learn Volume and price action correlation
5 thanks




Last Updated on January 22, 2013


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts