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

NinjaScript File Sharing Discussion Discussion for shared NinjaScript files.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 02-13-2010, 02:56 PM   #1
supermht
Senior Member
 
Join Date: Feb 2010
Posts: 140
Thanks: 4
Thanked 2 times in 1 post
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, 41 views)
supermht is offline  
Reply With Quote
Old 02-13-2010, 06: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 6 times in 6 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, 09:54 AM   #3
supermht
Senior Member
 
Join Date: Feb 2010
Posts: 140
Thanks: 4
Thanked 2 times in 1 post
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, 10: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 6 times in 6 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: 312
Thanks: 129
Thanked 23 times in 20 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: 2,611
Thanks: 261
Thanked 480 times in 468 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: 312
Thanks: 129
Thanked 23 times in 20 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, 40 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: 2,611
Thanks: 261
Thanked 480 times in 468 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 57 09-22-2016 08:53 AM
Default Account while Running a NinjaScript Strategy from a Chart Joerg Platform Technical Support 7 06-03-2011 09:10 AM
Indicators in NinjaScript, but not in Chart watchhillian Platform Technical Support 3 11-03-2009 11:23 AM
The focus of the chart changes after reloading ninjascript clearpicks Platform Technical Support 9 04-26-2008 03:21 AM


All times are GMT -6. The time now is 03:39 PM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.