NexusFi: Find Your Edge


Home Menu

 





Performance Suggestions Please


Discussion in NinjaTrader

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




 
Search this Thread

Performance Suggestions Please

  #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?
Trade idea based off three indicators.
Traders Hideout
About a successful futures trader who didnt know anythin …
Psychology and Money Management
What broker to use for trading palladium futures
Commodities
REcommedations for programming help
Sierra Chart
How to apply profiles
Traders Hideout
 




Last Updated on January 22, 2013


© 2024 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 - Privacy Policy - Downloads - Top
no new posts