PDA

View Full Version : Time histogram for tic, volume or range charts


dwalls
01-16-2008, 01:17 PM
I was hoping someone could transfer this eSignal code to Ninja.
It appears simple.
It looks like a volume histogram on a time chart but shows a histogram of the time it takes for a bar to complete. Zero to 60 seconds is one color, 60 to 120 seconds is another color, 120 to 180 seconds is yet another color and so on.
The code could be edited to any time intervals you wanted to use based on the size of charts you use.
Its a nice visual indicator to have when using tic, volume or range bars

Thanks

/************************************************** *******
Opstock © September 2005
Use and/or modify this code freely. If you redistribute it
please include this and/or any other comment blocks and a
description of any changes you make.
************************************************** ********/
function preMain() {
setPriceStudy(false);
setStudyTitle("Time Histogram for T&V charts")
setShowCursorLabel(true);
setDefaultBarFgColor(Color.magenta,0);
setDefaultBarThickness(5,0);
setPlotType(PLOTTYPE_HISTOGRAM);
setStudyMax(300);
//addBand(120, PS_SOLID, 1, Color.aqua);
}
function main() {
var TimeDiff = rawtime(0)-rawtime(-1);

if(TimeDiff > 0 && TimeDiff <= 60) {
setBar(Bar.FgColor, -1, Color.green);
}
if(TimeDiff > 60 && TimeDiff <= 120) {
setBar(Bar.FgColor, -1, Color.lime);
}
if(TimeDiff > 120 && TimeDiff <= 180) {
setBar(Bar.FgColor, -1, Color.yellow);
}
if(TimeDiff > 180 && TimeDiff <= 240) {
setBar(Bar.FgColor, -1, Color.RGB(255,128,0));
}
if(TimeDiff > 240 && TimeDiff <= 300) {
setBar(Bar.FgColor, -1, Color.red);
}

//return TimeDiff;

setBar(Bar.Value, -1, TimeDiff);
return null;

}

NinjaTrader_Dierk
01-16-2008, 01:19 PM
If you'd find nobody from the community contributing you still could contact any of the certified NinjaScript consultants: http://www.ninjatrader.com/webnew/partners_onlinetrading_NinjaScript.htm

Gumphrie
01-16-2008, 08:10 PM
Here you go!

I noticed that particularly on weekends you may get a bar that dwarfs the other bars in the histogram. If that happens set the color to Transparent which not only hides the bar but also resets the scale.

To import:

- Download the file contained in this thread to your desktop
- From the Control Center window select the menu File > Utilities > Import NinjaScript
- Select the downloaded file

dwalls
01-16-2008, 08:44 PM
Thanks Gumphrie....I appreciate your time...your the best.

dwalls

samiam30
01-26-2008, 02:48 PM
Is anyone else having a problem with this indicator not being ploted in the new (v. 8) beta (no errors are reported in the log and the indicator worked perfectly before i updated form v. 6 to v. 8)?

Also many thanks to Gumphrie for coding this useful indicator.

dwalls
11-12-2008, 02:28 PM
Hello,
I'm now trying to add an Alert Sound to this Time Histogram.
I would like an Alert Sound if the time does not exceed boundary1.
Example: If boundary1 is set to 60 and the time histogram bar closes at 52 (or any number less than 60) play an Alert Sound.
I tried this but not compiling:

if ((TimeHistogram(Close,boundary1)[0])< boundary1[0]){
PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\pop.wav");
}

error messages:
Indicator\TimeHistogramAlertTest.cs No overload for method 'TimeHistogram' takes '2' arguments CS1501 - click for info

Indicator\TimeHistogramAlertTest.cs Cannot apply indexing with [] to an expression of type 'int' CS0021 - click for info

Any ideas?

Thanks

NinjaTrader_Bertrand
11-12-2008, 03:10 PM
Hi dwalls,

Thanks for your post.

The 'Time Histogram' takes 5 boundary inputs and has no input series one. Please take a look at this snippet below and modify your code accordingly;


double myBoundary = 60;
if ((TimeHistogram(boundary1, boundary2, boundary3, boundary4, boundary5)[0] < myBoundary))
PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\pop.wav");


Of course you will need to define the myBoundary, boundary1, boundary2, boundary3, boundary4, boundary5 variables in the Variables() section of your code.

dwalls
11-12-2008, 04:05 PM
Thanks for your response.
It wound let me compile when using the "<" in the code. It seems to make sense to use it but it wont compile.
if ((TimeHistogram(boundary1, boundary2, boundary3, boundary4, boundary5) < myBoundary))

error message:
Indicator\TimeHistogramAlertTest.cs Operator '<' cannot be applied to operands of type 'NinjaTrader.Indicator.TimeHistogram' and 'int' CS0019 - click for info

I usually have to use the Rising/Falling or CrossBelow/CrossAbove too get these things to work. It never lets me use the "<" or ">".

Any help would be great.

Thanks

PS. I have the myBoundary, boundary1, boundary2, boundary3, boundary4, boundary5 variables (each as private int) in the Variables() section of your code and also as Parameters in the Properties Section.

dwalls
11-12-2008, 04:21 PM
sorry...should read...It wouldn't let me compile when using the "<" in the code.

NinjaTrader_Bertrand
11-12-2008, 04:49 PM
Hi dwalls,

Unfortunately my previous snippet was incorrect, please try this -


double myBoundary = 60;
if ((TimeHistogram(boundary1, boundary2, boundary3, boundary4, boundary5)[0] < myBoundary))
PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\pop.wav");

dwalls
11-13-2008, 09:36 AM
Hi NinjaTrader Bertrand,
Thanks for your help on this.
I got it to compile but the sound alert wont play.
I must have something wrong in the "Initialize" or with the "double".
I have the "double" in "Intialized "and in"On Bar Update". I dont know if thats right.
Could you please take a look and see if theres anything wrong and why the alert sound wont play?

Thanks

NinjaTrader_Bertrand
11-13-2008, 10:08 AM
Hi dwalls,

Thanks for your post.

Please use this code snipped in your code -


if (closeBelowmyBoundaryAlertSound)
{
if (timeGap < myBoundary)
{
PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\Alert4.wav");
}
}


1. You can use timeGap directly in your code, there's no need to call the complete TimeHistogram as a function for you.

2. Make sure you point the PlaySound() to a valid .wav file, I changed it to the Alert4.wav provided by us and it works fine.

dwalls
11-13-2008, 10:23 AM
Great.
I got it to work now.
Thanks for your help.

NinjaTrader_Bertrand
11-13-2008, 10:27 AM
You are welcome - great it works now!!