//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
/// <summary>
/// The Money Flow Oscillator measures the amount of money flow volume over a specific period. A move into positive territory indicates buying pressure while a move into negative territory indicates selling pressure.
/// </summary>
public class MoneyFlowOscillator : Indicator
{
private Series<double> mfv;
private double dvs, mltp;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionMoneyFlowOscillator;
Name = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meMoneyFlowOscillator;
IsOverlay = false;
DrawOnPricePanel = false;
IsSuspendedWhileInactive = true;
Period = 20;
AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.NinjaScriptIndicatorMo neyFlowLine);
AddLine(Brushes.DarkGray, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZe roLine);
}
else if (State == State.DataLoaded)
{
mfv = new Series<double>(this);
}
}
protected override void OnBarUpdate()
{
if(CurrentBar > 0)
{
dvs = (High[0] - Low[1]) + (High[1] - Low[0]) == 0 ? 0.00001 : (High[0] - Low[1]) + (High[1] - Low[0]);
mltp = Math.Round(High[0] < Low[1] ? -1: Low[0] > High[1] ? 1 : ((High[0] - Low[1]) - (High[1] - Low[0])) / dvs, 2);
mfv[0] = mltp * (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0]);
if (CurrentBar >= Period)
{
double sumVolume = SUM(Volume, Period)[0];
if (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency)
sumVolume = Core.Globals.ToCryptocurrencyVolume((long)sumVolum e);
Values[0][0] = Math.Round(SUM(mfv, Period)[0] / sumVolume, 3);
}
// Below are my 2 trys to get the color to change.
/*
if( mfv[0] > 0.0 )
PlotBrushes[0][0] = Brushes.Green;
if( mfv[0] < 0.0 )
PlotBrushes[0][0] = Brushes.Red;
if( mfv[0] = 0.0 )
PlotBrushes[0][0] = Brushes.Yellow;
*/
if( Values[0][0] > 0.0 )
PlotBrushes[0][0] = Brushes.Green;
if( Values[0][0] < 0.0 )
PlotBrushes[0][0] = Brushes.Red;
if( Values[0][0] = 0.0 )
PlotBrushes[0][0] = Brushes.Yellow;
}
else
mfv[0] = 0;
}
Comment