![]() |
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Jan 2007
Location: Calgary, Canada
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
I simply want a vertical line of specified width and color to appear in the price panel given a certain trend condition. I used the wizard to create a custom indicator with no inputs and no plots. The code I'm using is (for example):
Code:
protected override void Initialize()
{
CalculateOnBarClose = true;
Overlay = true;
PriceTypeSupported = false;
}
protected override void OnBarUpdate()
{
if (CrossAbove(EMA(50), EMA(200), 1))
{
DrawVerticalLine("UP", 5, Color.Red, DashStyle.Solid, 6);
}
}
Thx in advance. KD |
|
|
|
|
|
#2 | |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
|
Works fine and as you have coded it. Ifyou want a separate line instance for each CrossAbove() condition, then you have to supply unique tag names.
Quote:
Ray
NinjaTrader Customer Service |
|
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Jan 2007
Location: Calgary, Canada
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks for the reply.
It looks as if none of the shared draw items will work for me using this method. They all compile fine, I can apply the indicator to a chart, but nothing appears. I have tried changing the condition to Low[0] > Low[5], and have tried other objects up arrow, dot, etc with nothing appearing on any chart to which I apply the indicator. However,the objects draw correctlywhen I use the same logic in a strategy instead of an indicator. What am I missing? Complete code follows: Code:
#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// draw vertical bar with xma crossover
/// </summary>
[Description("draw vertical bar with xma crossover")]
[Gui.Design.DisplayName("vertical bar")]
public class kdtrend1 : Indicator
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;
Overlay = true;
PriceTypeSupported = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (CrossAbove(EMA(50), EMA(200), 5))
{
DrawVerticalLine(Time[0].ToString(), 5, Color.Red, DashStyle.Solid, 6);
}
}
|
|
|
|
|
|
#4 |
|
Junior Member
Join Date: Jan 2007
Location: Calgary, Canada
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
OK, that's just too weird. After I applied and un-applied the strategy with the same logic, the indicatordraws properly now.
Thanks again for your help! KD |
|
|
|
|
|
#5 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
|
Any time you re-compile an indicator or strategy, the changed implementation is not automatically loaded in any charts. You can force the reload via right mouse click "Reload NinjaScript"
Ray
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#6 | |
|
Junior Member
Join Date: Jan 2007
Location: Calgary, Canada
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
ninjatrader wrote:
Quote:
BTW, I'm using 6.0.0.6 Live (ZenFire) version KD |
|
|
|
|
|
|
#7 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
|
I would double check your logic. If you get stuck, build a basic indicatorthat draws an arrow on each bar without any logic to confirm all is well, then build from there.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Junior Member
Join Date: Jan 2007
Location: Calgary, Canada
Posts: 12
Thanks: 0
Thanked 0 times in 0 posts
|
Well, what is so frustrating is that some logic seems to work and some doesn't. A simple DrawVerticalLine() with no conditions draws on every bar. However,
Code:
protected override void OnBarUpdate()
{
if (MIN(Low, 14)[1] > EMA(50)[1])
{
DrawVerticalLine(Time[0].ToString(), 0, Color.Red, DashStyle.Solid, 6);
}
}
Interestingly if I replace the above condition with Code:
if (MIN(Low, 14)[0] > EMA(50)[0]) Changing the reference by one bar breaks it in an indicator - but it stilldraws correctlyin a strategy. Could this be a bug? If it's not, I must bemissing something very basic. Thanks for your patience KD |
|
|
|
|
|
#9 | |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
|
You should always check the log tab if stuff does not work since NT will spit out error information. Its very clear why your code is failing. If you check your logs, you will have some sort of "index out of the boundsof the array" error.
You are checking for a value of 1 bar ago. On the first bar of a chart, there is no 1 bar agao and thus you get an error. Make sure there are enough bars ago on the chart first. Quote:
Ray
NinjaTrader Customer Service |
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|