• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

hi, need help with ninjascript of equivolume chart

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

    hi, need help with ninjascript of equivolume chart

    I am trying to compile this file in NT6.5, but it always gives me compilation error, can anybody help me with this? I appreciate your help.

    snowbird
    Attached Files

    #2
    Hello,

    I am sorry, we don't really debug scripts. I recommend commenting things out until it compiles then remove the comments until you see where the issue is. Then if you can't sort it out post the code here.
    BenNinjaTrader Customer Service

    Comment


      #3
      here is code

      //
      // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
      //
      #region Using declarations
      using System;
      using System.ComponentModel;
      using System.Drawing;
      using System.Xml.Serialization;
      #endregion
      // This namespace holds all chart styles. Do not change it.
      namespace NinjaTrader.Gui.Chart
      {
      /// <summary>
      /// </summary>
      public class CandleVolStyle : ChartStyles
      {
      private static bool registered = Chart.ChartStyle.Register(new CandleVolStyle());
      private SolidBrush downBrush = new SolidBrush(Color.Red);
      private SolidBrush upBrush = new SolidBrush(Color.LightGreen);
      /// <summary>
      /// </summary>
      public CandleVolStyle()
      : base(ChartStyleType.CandleStick)
      {
      this.DownColor = Color.Red;
      this.UpColor = Color.LightGreen;
      }
      /// <summary>
      /// </summary>
      /// <returns></returns>
      public override object Clone()
      {
      CandleVolStyle ret = new CandleVolStyle();
      ret.BarWidth = BarWidth;
      ret.DownColor = DownColor;
      ret.Pen = Gui.Globals.Clone(Pen);
      ret.Pen2 = Gui.Globals.Clone(Pen2);
      ret.UpColor = UpColor;
      return ret;
      }
      /// <summary>
      /// </summary>
      /// <returns></returns>
      public override string DisplayName
      {
      get { return "CandlestickVol"; }
      }
      /// <summary>
      /// </summary>
      public override void Dispose()
      {
      base.Dispose();
      downBrush.Dispose();
      upBrush.Dispose();
      }
      /// <summary>
      /// </summary>
      /// <param name="barWidth"></param>
      /// <returns></returns>
      public override int GetBarPaintWidth(int barWidth)
      {
      // middle line + 2 * half of the body width + 2 * border line
      return (int)(1 + 2 * (barWidth) + 2 * Pen.Width);
      }
      /// <summary>
      /// </summary>
      /// <param name="propertyDescriptor"></param>
      /// <param name="chartStyle"></param>
      /// <param name="attributes"></param>
      /// <returns></returns>
      public override PropertyDescriptorCollection GetProperties(PropertyDescriptor propertyDescriptor, ChartStyle chartStyle, Attribute[] attributes)
      {
      PropertyDescriptorCollection properties = base.GetProperties(propertyDescriptor, chartStyle, attributes);
      // here is how you change the display name of the property on the properties grid
      Gui.Design.DisplayNameAttribute.SetDisplayName(pro perties, "BarWidthUI", "\r\r\rBar width");
      Gui.Design.DisplayNameAttribute.SetDisplayName(pro perties, "DownColor", "\r\r\rColor for down bars");
      Gui.Design.DisplayNameAttribute.SetDisplayName(pro perties, "Pen", "\r\r\rCandle outline");
      Gui.Design.DisplayNameAttribute.SetDisplayName(pro perties, "Pen2", "\r\r\rWick");
      Gui.Design.DisplayNameAttribute.SetDisplayName(pro perties, "UpColor", "\r\r\rColor for up bars");
      return properties;
      }
      /// <summary>
      /// </summary>
      public override bool IsTransparent
      {
      get { return UpColor == Color.Transparent && DownColor == Color.Transparent && Pen.Color == Color.Transparent; }
      }
      /// <summary>
      /// </summary>
      /// <param name="chartControl"></param>
      /// <param name="graphics"></param>
      /// <param name="bars"></param>
      /// <param name="panelIdx"></param>
      /// <param name="fromIdx"></param>
      /// <param name="toIdx"></param>
      /// <param name="bounds"></param>
      /// <param name="max"></param>
      /// <param name="min"></param>
      public override void PaintBars(ChartControl chartControl, Graphics graphics, Data.Bars bars, int panelIdx, int fromIdx, int toIdx, Rectangle bounds, double max, double min)
      {
      if (downBrush.Color != DownColor)
      downBrush.Color = DownColor;
      if (upBrush.Color != UpColor)
      upBrush.Color = UpColor;
      Color barColor;
      int barWidthValue = bars.BarsData.ChartStyle.BarWidthUI;
      int barWidth;
      SolidBrush brush = upBrush;
      int close;
      double closeValue;
      int high;
      int low;
      Color oldPenColor = Pen.Color;
      Color pen2Color = Pen2.Color;
      int open;
      double openValue;
      int x;
      //get avg vol
      double avgVol = 0;
      double maxVol = 0;
      double minVol = 0;
      for (int idx = fromIdx; idx <= toIdx; idx++)
      {
      if (maxVol < bars.GetVolume(idx))
      {
      maxVol = bars.GetVolume(idx);
      }
      if (minVol > bars.GetVolume(idx))
      {
      minVol = bars.GetVolume(idx);
      }
      avgVol = avgVol + bars.GetVolume(idx);
      }
      avgVol = avgVol / (double)toIdx;

      //*********************
      //scale bar width linearly with the volume
      //y = k * x + m
      //k=(y1-y2)/(x1-x2)
      //m=y-k*x
      //y=barwidth
      //x=volume
      //k=deltaBarwidth/deltaVol
      double maxBarWidthDbl = (double)barWidthValue;
      double minBarWidthDbl = 4.0;
      double deltaBarWidth = maxBarWidthDbl - minBarWidthDbl;
      double deltaVol = maxVol - minVol;
      double k = deltaBarWidth / deltaVol;
      //find m, plug in (minVol, minBarWidthDbl)
      double m = minBarWidthDbl - k * minVol;
      //done, now we can plug in any vol to get the bar width, y(x)=k*x+m
      double dblBarwidth;

      for (int idx = fromIdx; idx <= toIdx; idx++)
      {
      //calc dynamic bar width
      dblBarwidth = k * bars.GetVolume(idx) + m;
      barWidth = (int)(Math.Round(dblBarwidth, 0));
      barColor = chartControl.GetBarColor(bars, idx);
      // barWidth = GetBarPaintWidth(barWidthValue);
      closeValue = bars.GetClose(idx);
      close = chartControl.GetYByValue(bars, closeValue);
      high = chartControl.GetYByValue(bars, bars.GetHigh(idx));
      low = chartControl.GetYByValue(bars, bars.GetLow(idx));
      openValue = bars.GetOpen(idx);
      open = chartControl.GetYByValue(bars, openValue);
      x = chartControl.GetXByBarIdx(bars, idx);
      Color candleOutlineColorScript = chartControl.GetCandleOutlineColor(bars, idx);
      bool isCandleOutlineColorScriptSet = (chartControl.GetCandleOutlineColor(bars, idx) != Color.Empty);
      Pen.Color = oldPenColor;
      if (barColor != Color.Empty)
      Pen.Color = (candleOutlineColorScript != Color.Empty ? candleOutlineColorScript : barColor);
      else if (candleOutlineColorScript != Color.Empty)
      Pen.Color = candleOutlineColorScript;
      if (open == close)
      graphics.DrawLine(Pen, x - barWidth / 2, close, x + barWidth / 2, close);
      else
      {
      brush = closeValue >= openValue ? upBrush : downBrush;
      Color oldColor = brush.Color;
      if (barColor != Color.Empty)
      brush.Color = barColor;
      graphics.FillRectangle(brush, x - barWidth / 2 + 1, Math.Min(close, open) + 1,
      barWidth - 1, Math.Max(open, close) - Math.Min(close, open) - 1);
      if (barColor != Color.Empty)
      brush.Color = oldColor;
      graphics.DrawRectangle(Pen, x - (barWidth / 2) + (Pen.Width / 2), Math.Min(close, open), barWidth - Pen.Width, Math.Max(open, close) - Math.Min(close, open));
      }
      Pen2.Color = isCandleOutlineColorScriptSet ? candleOutlineColorScript : pen2Color;
      if (high < Math.Min(open, close))
      graphics.DrawLine(Pen2, x, high, x, Math.Min(open, close));
      if (low > Math.Max(open, close))
      graphics.DrawLine(Pen2, x, low, x, Math.Max(open, close));
      }
      Pen.Color = oldPenColor;
      Pen2.Color = pen2Color;
      }
      }
      }

      Comment


        #4
        Hello,

        Can you narrow it down as mentioned in my last post? We don't debug really, we provide assistance on specific questions. Like "what is wrong with the way I am using x method", etc.

        This link might help:
        http://www.ninjatrader-support2.com/...ead.php?t=3418
        BenNinjaTrader Customer Service

        Comment


          #5
          Regarding the script posted, does it work in NT7? It seems it was developed by Ninja, based on the comments. If not, where can an updated version be found?

          Thanks!
          Daniel

          Comment


            #6
            Hello neoikon,

            The posted NinjaScript above will not work in NT7 as it is right now as it has compiling errors that need to be resolved.

            This script was not developed by NinjaTrader, and I am not aware of any updated version of the script as well. I will leave this forum open for any members of the community or author has more information.
            JCNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_JC View Post
              The posted NinjaScript above will not work in NT7 as it is right now as it has compiling errors that need to be resolved.

              This script was not developed by NinjaTrader, and I am not aware of any updated version of the script as well. I will leave this forum open for any members of the community or author has more information.
              Attached is the version that I found that seems to compile in NT7. I believe it is a "type", so I put it in the \NinjaTrader 7\bin\Custom\Type folder, then opened up a random indicator, compiled (F5, no errors), restarted NinjaTrader, but I don't see any new "types". Is that process correct? Where should I see the new "type"? When I go into Data Series and look at the "Type" dropdown, is that not where I should see a new item? (sorry, this is my first time dealing with custom "types")

              So when it says "Copyright NinjaTrader" on the top, it doesn't necessarily mean it was developed by NT?

              Thanks in advance for any help!
              Daniel
              Attached Files

              Comment


                #8
                Hello neoikon,

                It could have been created using the @ChartStyles.cs file in the Type folder which could explain why it has the Copyright NinjaTrader at the top of the code.

                That is correct on where you put the file, and I can confirm with that ".cs" file that you attached can compile. It is a chart style so it would be under the Chart style just below the Type. I have imported it in and it appears that it overrides the normal CandleStick Chart style as well so be wary of that when you are import in that file.

                Let me know if I can be of further assistance.
                JCNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by percma, Today, 03:44 AM
                0 responses
                1 view
                0 likes
                Last Post percma
                by percma
                 
                Started by mrzz93, Today, 03:06 AM
                0 responses
                6 views
                0 likes
                Last Post mrzz93
                by mrzz93
                 
                Started by HighTrade, Yesterday, 06:37 PM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_ChrisSch  
                Started by BarzTrading, Yesterday, 09:30 PM
                0 responses
                1 view
                0 likes
                Last Post BarzTrading  
                Started by waverider, Yesterday, 05:37 PM
                0 responses
                5 views
                0 likes
                Last Post waverider  
                Working...
                X