NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript File Sharing > NinjaScript File Sharing Discussion

NinjaScript File Sharing Discussion Discussion for shared NinjaScript files.

Reply
 
Thread Tools Display Modes
Old 02-13-2010, 01:56 PM   #1
supermht
Member
 
Join Date: Feb 2010
Posts: 86
Thanks: 1
Thanked 0 times in 0 posts
Default 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
File Type: cs CandleVol.cs (8.6 KB, 37 views)
supermht is offline  
Reply With Quote
Old 02-13-2010, 05:59 PM   #2
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

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.
NinjaTrader_Ben is offline  
Reply With Quote
Old 02-14-2010, 08:54 AM   #3
supermht
Member
 
Join Date: Feb 2010
Posts: 86
Thanks: 1
Thanked 0 times in 0 posts
Default 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;
}
}
}
supermht is offline  
Reply With Quote
Old 02-14-2010, 09:23 AM   #4
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

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
NinjaTrader_Ben is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Ben for this post:
Old 08-17-2012, 08:26 AM   #5
neoikon
Senior Member
 
Join Date: Oct 2008
Location: Austin, TX
Posts: 119
Thanks: 44
Thanked 5 times in 4 posts
Default

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
neoikon is offline  
Reply With Quote
Old 08-17-2012, 08:45 AM   #6
NinjaTrader_JC
NinjaTrader Customer Service
 
NinjaTrader_JC's Avatar
 
Join Date: Mar 2012
Location: Denver, CO
Posts: 1,199
Thanks: 135
Thanked 182 times in 181 posts
Default

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.
NinjaTrader_JC is offline  
Reply With Quote
The following user says thank you to NinjaTrader_JC for this post:
Old 08-17-2012, 08:55 AM   #7
neoikon
Senior Member
 
Join Date: Oct 2008
Location: Austin, TX
Posts: 119
Thanks: 44
Thanked 5 times in 4 posts
Default

Quote:
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
File Type: cs CandleVol.cs (8.6 KB, 17 views)
neoikon is offline  
Reply With Quote
Old 08-17-2012, 11:02 AM   #8
NinjaTrader_JC
NinjaTrader Customer Service
 
NinjaTrader_JC's Avatar
 
Join Date: Mar 2012
Location: Denver, CO
Posts: 1,199
Thanks: 135
Thanked 182 times in 181 posts
Default

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.
NinjaTrader_JC is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -6. The time now is 01:26 AM.