
//
// Copyright (C) 2019, Order Flow Analytics Inc <www.orderflowanalytics.com>.
// OFA reserves the right to modify or overwrite this NinjaScript component with each release.
//
// By installing, using in whole or in part any sample code from Order Flow Analytics you agree to fully indemnify and hold harmless OrderFlowAnalytics, Inc 
// and its affiliates from and against any claims, losses, liabilities and expenses that may be incurred 
// as a result having downloaded and/or used any or all of the available code.
// Do thoroughly test any code & modifications for indicators and strategies in Replay Test mode

#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;
using NinjaTrader.OFA;
#endregion

//This namespace holds Indicators in this folder and is required. Do not change it. 
namespace NinjaTrader.NinjaScript.Indicators
{
	public class OFASampleCDeltaMomentum : Indicator
	{
		//private OFASampleCalcCumDeltaBH OFACumDelta;
		
		private OFAIndicatorSTCORE OFAIndicatorSTCORE1;
		//private Series<double>	POCCalculation;    // Data series to store any calculation on the OFA data.
		
		protected override void OnStateChange()
		{
			if (State == State.SetDefaults)
			{
				Description									= @"Enter the description for your new custom Indicator here.";
				Name										= "OFASampleCDeltaMomentum";
				Calculate									= Calculate.OnBarClose;
				IsOverlay									= false;
				DisplayInDataBox							= true;
				DrawOnPricePanel							= false;
				DrawHorizontalGridLines						= false;
				DrawVerticalGridLines						= false;
				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					= false;
				
				//AddPlot(Brushes.Cyan, "HLTicksline");
				
				AddPlot(new Stroke(Brushes.LawnGreen, 6), PlotStyle.Bar, "UpMomentum");
				AddPlot(new Stroke(Brushes.Red, 6), PlotStyle.Bar, "DownMomentum");
				AddPlot(Brushes.Transparent, "DeltaMomentum");
			}
			else if (State == State.Configure)
			{
				
				//POCCalculation = new Series<double>(this);
			}
			
			else if (State == State.DataLoaded)
			{				
				
				//OFACumDelta				= OFASampleCalcCumDeltaBH();
				OFAIndicatorSTCORE1				= OFAIndicatorSTCORE(Close, 30, 70, NinjaTrader.OFA.OFAColorLogic.POC);
				
			}
		}

		protected override void OnBarUpdate()
		{
			//Add your custom indicator logic here
//			if (BarsInProgress != 0) 
//				return;  

			if (CurrentBars[0] < 1)
				return;
			
			// Option if user wants to do any calculation on the POC price ...
			// commented out for now ..
			
			// POCCalculation[0] = OFAIndicatorSTCORE1.OFAPocPrice[0];
			
			
			//Ticksline[0] = OFAIndicatorSTCORE1.OFABarTicks[0];
			//HLTicksline[0] = OFAIndicatorSTCORE1.OFABarHighLowTicks[0];
			//Ticksline[0] = OFAIndicatorSTCORE1.OFABarOpenCloseBodyTicks[0];
			
			if (OFAIndicatorSTCORE1.OFABarDeltaVolume[0] > 0)
			{
				DownMomentum[0] = 0;
				if (DeltaMomentum[1] > 0)
					DeltaMomentum[0] = DeltaMomentum[1] + OFAIndicatorSTCORE1.OFABarDeltaVolume[0];
				else
					DeltaMomentum[0] = OFAIndicatorSTCORE1.OFABarDeltaVolume[0];
				
				UpMomentum[0] = DeltaMomentum[0];
			}

			if (OFAIndicatorSTCORE1.OFABarDeltaVolume[0] < 0)
			{
				UpMomentum[0] = 0;
				if (DeltaMomentum[1] < 0)
					DeltaMomentum[0] = DeltaMomentum[1] + OFAIndicatorSTCORE1.OFABarDeltaVolume[0];
				else
					DeltaMomentum[0] = OFAIndicatorSTCORE1.OFABarDeltaVolume[0];
				
				DownMomentum[0] = -1*DeltaMomentum[0];
			}
			
//			if (OFAIndicatorSTCORE1.OFABarDirectionValue[0] == 1)
//				PlotBrushes[0][0] = Brushes.Green;
//			if (OFAIndicatorSTCORE1.OFABarDirectionValue[0] == -1)
//				PlotBrushes[0][0] = Brushes.Red;
				
			
		}

		#region Properties

//		[Browsable(false)]
//		[XmlIgnore]
//		public Series<double> HLTicksline
//		{
//			get { return Values[0]; }
//		}
		
		[Browsable(false)]
		[XmlIgnore]
		public Series<double> UpMomentum
		{
			get { return Values[0]; }
		}

		[Browsable(false)]
		[XmlIgnore]
		public Series<double> DownMomentum
		{
			get { return Values[1]; }
		}

		[Browsable(false)]
		[XmlIgnore]
		public Series<double> DeltaMomentum
		{
			get { return Values[2]; }
		}
		
		
		#endregion
		

	}
}

#region NinjaScript generated code. Neither change nor remove.

namespace NinjaTrader.NinjaScript.Indicators
{
	public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
	{
		private OFASampleCDeltaMomentum[] cacheOFASampleCDeltaMomentum;
		public OFASampleCDeltaMomentum OFASampleCDeltaMomentum()
		{
			return OFASampleCDeltaMomentum(Input);
		}

		public OFASampleCDeltaMomentum OFASampleCDeltaMomentum(ISeries<double> input)
		{
			if (cacheOFASampleCDeltaMomentum != null)
				for (int idx = 0; idx < cacheOFASampleCDeltaMomentum.Length; idx++)
					if (cacheOFASampleCDeltaMomentum[idx] != null &&  cacheOFASampleCDeltaMomentum[idx].EqualsInput(input))
						return cacheOFASampleCDeltaMomentum[idx];
			return CacheIndicator<OFASampleCDeltaMomentum>(new OFASampleCDeltaMomentum(), input, ref cacheOFASampleCDeltaMomentum);
		}
	}
}

namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
	public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
	{
		public Indicators.OFASampleCDeltaMomentum OFASampleCDeltaMomentum()
		{
			return indicator.OFASampleCDeltaMomentum(Input);
		}

		public Indicators.OFASampleCDeltaMomentum OFASampleCDeltaMomentum(ISeries<double> input )
		{
			return indicator.OFASampleCDeltaMomentum(input);
		}
	}
}

namespace NinjaTrader.NinjaScript.Strategies
{
	public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
	{
		public Indicators.OFASampleCDeltaMomentum OFASampleCDeltaMomentum()
		{
			return indicator.OFASampleCDeltaMomentum(Input);
		}

		public Indicators.OFASampleCDeltaMomentum OFASampleCDeltaMomentum(ISeries<double> input )
		{
			return indicator.OFASampleCDeltaMomentum(input);
		}
	}
}

#endregion
