![]() |
|
|||||||
| NinjaScript File Sharing Discussion Discussion for shared NinjaScript files. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Feb 2010
Posts: 86
Thanks: 1
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
|
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.
Ben
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Feb 2010
Posts: 86
Thanks: 1
Thanked 0 times in 0 posts
|
//
// 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; } } } |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
|
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
Ben
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_Ben for this post: |
|
|
|
#5 |
|
Senior Member
Join Date: Oct 2008
Location: Austin, TX
Posts: 119
Thanks: 44
Thanked 5 times in 4 posts
|
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 |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Mar 2012
Location: Denver, CO
Posts: 1,192
Thanks: 134
Thanked 181 times in 180 posts
|
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.
JC
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_JC for this post: |
|
|
|
#7 | |
|
Senior Member
Join Date: Oct 2008
Location: Austin, TX
Posts: 119
Thanks: 44
Thanked 5 times in 4 posts
|
Quote:
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 |
|
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Mar 2012
Location: Denver, CO
Posts: 1,192
Thanks: 134
Thanked 181 times in 180 posts
|
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.
JC
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Equivolume Candles? | funk101 | Suggestions And Feedback | 46 | 04-04-2013 05:00 PM |
| Default Account while Running a NinjaScript Strategy from a Chart | Joerg | Automated Trading | 7 | 06-03-2011 09:10 AM |
| NT7: Reference Chart Instrument List via Ninjascript | bethewater | Version 7 Beta General Questions & Bug Reports | 1 | 12-16-2009 06:04 AM |
| Indicators in NinjaScript, but not in Chart | watchhillian | Installation and Licensing | 3 | 11-03-2009 10:23 AM |
| The focus of the chart changes after reloading ninjascript | clearpicks | Charting | 9 | 04-26-2008 03:21 AM |