Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

BlockVolume

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    BlockVolume

    I'm having a little trouble with my first attempt changing the BlockVolume indicator a little. The indicator will plot a bar in the sub-panel and I want to plot a Ray on the the chart. I want to use a ray so that in the future I can attach info to the line and show the start. The trouble I have now is I have changed the IsOverlay to true and I changed the PlotStyle to Line. Now I have a error CS0101 saying the "global namespace allready contains a definition for CountType" on line 116. I have not made any changes to the OnBarUpdate yet.......I know I need to do something there. I feel once I get past this hump I can start moving forward with it.

    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
    }

    #2
    Hello Sinks,

    Thank you for your post.

    The enum 'CountType' already exists in the original file. You will need to rename the enum and it's calls in order to avoid the error.

    To draw on the price panel yet still plot on the indicator panel you actually need to have DrawOnPricePanel set to True and IsOverlay set to False.

    Please visit the following links for more information:
    Please let me know if you have any questions.

    Comment


      #3
      Thank you Patrick........thats awesome.......I felt like my arrows were just missing the target.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by WHICKED, Today, 02:02 PM
      1 response
      3 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by selu72, Today, 02:01 PM
      0 responses
      2 views
      0 likes
      Last Post selu72
      by selu72
       
      Started by f.saeidi, Today, 12:14 PM
      8 responses
      21 views
      0 likes
      Last Post f.saeidi  
      Started by Mikey_, 03-23-2024, 05:59 PM
      3 responses
      49 views
      0 likes
      Last Post Sam2515
      by Sam2515
       
      Started by Russ Moreland, Today, 12:54 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Erick  
      Working...
      X