Any help would be awesome........thank you
// Copyright (C) 2018, NinjaTrader LLC <www.ninjatrader.com>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//
#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.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
// This namespace holds indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class MyBlockVolumeTest001 : Indicator
{
private double blockValue;
private int lastCurrentBar;
private bool hasCarriedOverTransitionTick;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionBlockVolume;
Name = "MyBlockVolumeTest001";
Calculate = Calculate.OnBarClose;
IsOverlay = true; //Changed to true
CountType = CountType.Volume;
BlockSize = 80;
//PlotStyle changed to Line from Bar
AddPlot(new Stroke(Brushes.DarkRed, 2), PlotStyle.Line, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meBlockVolume);
}
else if (State == State.Configure)
AddDataSeries(BarsPeriodType.Tick, 1);
}
private void CalculateBlockVolume(bool forceCurrentBar)
{
if ((Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0]) >= BlockSize)
{
bool inTransition = State == State.Realtime && BarsArray[1].Count - 1 - CurrentBars[1] > 1;
if (!inTransition && hasCarriedOverTransitionTick && !forceCurrentBar && Calculate == Calculate.OnBarClose)
CalculateBlockVolume(true);
int whatBar = State == State.Historical || inTransition || Calculate != Calculate.OnBarClose || forceCurrentBar ? CurrentBars[1] : Math.Min(CurrentBars[1] + 1, BarsArray[1].Count - 1);
hasCarriedOverTransitionTick = inTransition;
blockValue += CountType == CountType.Volume ? (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volumes[1].GetValueAt(whatBar)) : Volumes[1].GetValueAt(whatBar)) : 1;
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress == 0)
{
if (lastCurrentBar <= CurrentBars[0])
{
int indexOffset = BarsArray[1].Count - 1 - CurrentBars[1];
if (lastCurrentBar < CurrentBars[0] && Calculate != Calculate.OnBarClose && (State == State.Realtime || BarsArray[0].IsTickReplay))
{
if (CurrentBars[0] > 0)
Value[1] = blockValue;
if (BarsArray[0].IsTickReplay || State == State.Realtime && indexOffset == 0)
blockValue = 0;
}
Value[0] = blockValue;
if (Calculate == Calculate.OnBarClose || lastCurrentBar < CurrentBars[0] && BarsArray[0].BarsType.IsIntraday && (State == State.Historical && BarsArray[0].Count - 1 - CurrentBars[0] > 0 || State == State.Realtime && indexOffset > 0))
blockValue = 0;
}
lastCurrentBar = lastCurrentBar < CurrentBars[0] ? CurrentBars[0] : lastCurrentBar;
}
else
{
if (BarsArray[1].IsFirstBarOfSession && (Calculate != Calculate.OnBarClose || BarsArray[0].BarsType.IsIntraday))
blockValue = 0;
CalculateBlockVolume(false);
}
}
#region Properties
[Range(0.00000001, double.MaxValue), NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "BlockTradeSize", GroupName = "NinjaScriptParameters", Order = 0)]
public double BlockSize { get; set; }
[NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "NinjaScriptIndicatorCount", GroupName = "NinjaScriptParameters", Order = 0)]
public CountType CountType
{ get; set; }
#endregion
}
}
public enum CountType
{
Trades,
Volume
}
Comment