NinjaTrader API Guide

This is an API guide for how to access the MBoxWave indicators in NinjaTrader 8. You can use this guide to create custom strategies. The examples below show how to do this.

You also need to download the export file MBoxWaveExport.cs, which contains the export definitions and place it into:
"Documents\NinjaTrader 8 \bin\Custom\Indicators" folder.

 

Output of MApiMWaveChartStrategy.cs

 

MApiMWaveChartStrategy.cs - Sample Strategy Code

// This template is for creating a Strategy that accesses MPaceHist

/*
Function Definitions

// Returns Wave Total Volume at index i
double getVolume(int i)

// Returns Wave Bid Volume at index i
double getBidVolume(int i)

// Returns Wave Ask Volume at index i
double getAskVolume(int i)

// Returns Wave Delta Volume at index i
double getDeltaVolume(int i)

// Returns Wave Delta Percent at index i
double getDeltaPercent(int i)

// Returns Wave Length at index i
double getLength(int i)

// Returns Wave Time index i
double getTime(int i)

//  Returns Wave Width Volume at index i
int getWidth(int i)

//  Returns if swing end point occurred at index i
//  1 if up swing end point
// -1 if down swing end point
//  0 if not an end point
int getSwing(int i)

//   Returns if algorithmic signal occured at index i
//	 1 if on up swing
//	-1 if on down swing
//	 2 if on up swing with trend (If trend going down, lower highs, lower lows)
//	-2 if on down swing with trend ( If trend going up, higher highs, higher lows)
int getSignal(int i)
*/

#region Using declarations
using System;
using NinjaTrader.NinjaScript.Indicators;
#endregion

namespace NinjaTrader.NinjaScript.Strategies
{
	public class MApiMWaveChartStrategy : Strategy
	{
		MWaveChart myWave;

		protected override void OnStateChange()
		{
			if (State == State.SetDefaults)
			{
				Calculate = Calculate.OnEachTick;
			}
			
			else if (State == State.Configure)
			{				
				myWave = MWaveChart
				(
					// SwingBase: FirstClose, LastClose, HighLow
					SwingBase.FirstClose,
					
					// Calculation Mode: Ticks, Percent
					CalculationMode1.Ticks,
					
					// Reversal amount: Enter an integer
					3,
					
					// Algorithm: ThreeStoogesVolume,ThreeStoogesDelta,EffortResultPullback,SpringsUpThrusts};
					AlgoSelected.ThreeStoogesDelta
				);
			}
		}

		protected override void OnBarUpdate()
		{		
			// Wait for at least 100 bars before doing anything
			if (CurrentBar < 100) return;
			
			// This is required to sync with our indicator instance
			myWave.Update();
			
			// Get Wave Swing Index for last 5 waves
			int SI0 = 0;
			int SI1 = SI0 + myWave.getWidth(SI0);
			int SI2 = SI1 + myWave.getWidth(SI1);
			int SI3 = SI2 + myWave.getWidth(SI2);
			int SI4 = SI3 + myWave.getWidth(SI3);
			
			// Get Wave Direction for last 5 waves
			int WD0 = myWave.getSwing(SI1) * -1;
			int WD1 = myWave.getSwing(SI1);
			int WD2 = myWave.getSwing(SI2);
			int WD3 = myWave.getSwing(SI3);
			int WD4 = myWave.getSwing(SI4);

			// Get Total Wave Volume for last 5 waves
			double TV0 = myWave.getVolume(SI0);
			double TV1 = myWave.getVolume(SI1);
			double TV2 = myWave.getVolume(SI2);
			double TV3 = myWave.getVolume(SI3);
			double TV4 = myWave.getVolume(SI4);
			
			// Get Delta Wave Volume for last 5 waves
			double DV0 = myWave.getDeltaVolume(SI0);
			double DV1 = myWave.getDeltaVolume(SI1);
			double DV2 = myWave.getDeltaVolume(SI2);
			double DV3 = myWave.getDeltaVolume(SI3);
			double DV4 = myWave.getDeltaVolume(SI4);
			
			
			Print("###### WAVE 0 ######");
			Print("Direction: "    + WD0);
			Print("Total Volume: " + TV0);
			Print("Delta Volume: " + DV0);
			
			Print("###### WAVE 1 ######");
			Print("Direction: "    + WD1);
			Print("Total Volume: " + TV1);
			Print("Delta Volume: " + DV1);
			
			Print("###### WAVE 2 ######");
			Print("Direction: "    + WD2);
			Print("Total Volume: " + TV2);
			Print("Delta Volume: " + DV2);
			
			Print("###### WAVE 3 ######");
			Print("Direction: "    + WD3);
			Print("Total Volume: " + TV3);
			Print("Delta Volume: " + DV3);
			
			Print("###### WAVE 4 ######");
			Print("Direction: "    + WD4);
			Print("Total Volume: " + TV4);
			Print("Delta Volume: " + DV4);
		}
	}
}

 

 

MApiMCumulativeDeltaStrategy.cs - Sample Strategy Code

// This template is for creating a Strategy that accesses MCumulativeDelta

/*
Function Definitions

// Returns value of MCumulativeDelta at index i
public double getCumDelta(int i)

*/

#region Using declarations
using System;
using NinjaTrader.NinjaScript.Indicators;
#endregion

namespace NinjaTrader.NinjaScript.Strategies
{
	public class MApiMCumulativeDeltaStrategy : Strategy
	{
		MCumulativeDelta myCumDelta;

		protected override void OnStateChange()
		{
			if (State == State.SetDefaults)
			{
				Calculate = Calculate.OnEachTick;
			}
			
			else if (State == State.Configure)
			{
				// Set Cumulative Delta with Period
				myCumDelta = MCumulativeDelta(20);
			}
		}

		protected override void OnBarUpdate()
		{
			// Sync with our indicator instance
			myCumDelta.Update();

			Print("MApiMCumulativeDeltaStrategy: " + myCumDelta.getCumDelta(0));
		}
	}
}

 

 

MApiMPaceHistIndicator.cs - Sample Strategy Code

// This template is for creating a Strategy that accesses MPaceHist

/*
Function Definitions

// Returns value of MPace at index i
double getPace(int i)

*/

#region Using declarations
using System;
using NinjaTrader.NinjaScript.Indicators;
#endregion

namespace NinjaTrader.NinjaScript.Strategies
{
	public class MApiMPaceHistIndicator : Strategy
	{
		MPaceHist myPace;

		protected override void OnStateChange()
		{
			if (State == State.SetDefaults)
			{
				Calculate = Calculate.OnEachTick;
			}
			
			else if (State == State.Configure)
			{
				// Set Pace Basis to Volume
				myPace = MPaceHist("Volume");
				
				// Set Pace Basis to Delta Volume
				//myPace = MPaceHist("DeltaVolume");
			}
		}

		protected override void OnBarUpdate()
		{
			// Sync with our indicator instance
			myPace.Update();

			Print("MApiMPaceHistStrategy: " + myPace.getPace(0));
		}
	}
}