Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
is EMA+/-(2*ATR) indicator on indicator?
Collapse
X
-
-
protected override void OnBarUpdate()
{
if (CurrentBar < 1) return;
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
PlotHi.Set("My line2" + CurrentBar, 1, EMA(EMAperiod)[1] + (ATR(ATRperiod)[1]) * (1 + 1),
0, EMA(EMAperiod)[0] + (ATR(ATRperiod)[0]) * (1 + 1), Color.Red);
//PlotLo.Set(Close[0]);
}
Comment
-
That is again because you are trying to set a Plot() to something other than a double. (Emphasis mine). If you want to draw a line, you should be saying so.Originally posted by JimPunkrockford View Postprotected override void OnBarUpdate()
{
if (CurrentBar < 1) return;
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
PlotHi.Set("My line2" + CurrentBar, 1, EMA(EMAperiod)[1] + (ATR(ATRperiod)[1]) * (1 + 1),
0, EMA(EMAperiod)[0] + (ATR(ATRperiod)[0]) * (1 + 1), Color.Red);
//PlotLo.Set(Close[0]);
}
Code:DrawLine("My line2" + CurrentBar, 1, EMA(EMAperiod)[1] + (ATR(ATRperiod)[1]) * (1 + 1), 0, EMA(EMAperiod)[0] + (ATR(ATRperiod)[0]) * (1 + 1), Color.Red);
Comment
-
ok then, now we're cooking with gas. that was originally what i had minus your current bar< 1. so that was really the key piece of code.
the only thing that i would like is if i could use the colors from Plot0 and Plot1. i identified them as lines, red and green respectively, and they show up as user defined options when loading the indicator. but because i stipulate "Color.Red" and "Color.Green" in my event handler, i am unable to change them around while loading the indicator. is there some way to change "Color.Red" so instead it is the color of Plot0?
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Plot0"));
Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "Plot1"));
Overlay = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar < 1) return;
DrawLine("My line2" + CurrentBar, 1, EMA(eMAPeriod)[1] + (ATR(aTRPeriod)[1]) * (1 * offsetMultiplier),
0, EMA(eMAPeriod)[0] + (ATR(aTRPeriod)[0]) * (1 * offsetMultiplier), Color.Red);
DrawLine("My line" + CurrentBar, 1, EMA(eMAPeriod)[1] + (ATR(aTRPeriod)[1]) * (-1 * offsetMultiplier),
0, EMA(eMAPeriod)[0] + (ATR(aTRPeriod)[0]) * (-1 * offsetMultiplier), Color.Green);
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
//Plot0.Set(Close[0]);
//Plot1.Set(Close[0]);
}
Comment
-
Hello JimPunkrockford,
Plot0 will have the same color as you set (Color.Red) and these should be linked.
If you're having issues changing the color, it may because you have not removed/re-added the indicator to your chart.
Anything in the Initialize() method will only be called once the indicator is added. This means if you changed Color.Red to Color.DarkRed, you wouldn't see this change until you reapplied the indicator to your chart.MatthewNinjaTrader Product Management
Comment
-
hmm, i don't think so. no matter what i do the lines are always red and green. i remove the indicator hit "ok" then reload, change colors hit "ok" and still same colors.
Comment
-
Jim, can you please give this variation here a try -
if (CurrentBar < 1) return;
DrawLine("My line2" + CurrentBar, 1, EMA(eMAPeriod)[1] + (ATR(aTRPeriod)[1]) * (1 * offsetMultiplier),
0, EMA(eMAPeriod)[0] + (ATR(aTRPeriod)[0]) * (1 * offsetMultiplier), Plots[0].Pen.Color);
DrawLine("My line" + CurrentBar, 1, EMA(eMAPeriod)[1] + (ATR(aTRPeriod)[1]) * (-1 * offsetMultiplier),
0, EMA(eMAPeriod)[0] + (ATR(aTRPeriod)[0]) * (-1 * offsetMultiplier), Plots[1].Pen.Color);
Comment
-
ahh yes, the colors can now be set. unfortunately that is all, i can't change line widths or make dashed or change to dots.
would that be an easy fix? if not, no worries
Comment
-
Great on the colors, you can switch to using another DrawLine overload that includes the width / dashstyle parameter, please see - http://www.ninjatrader.com/support/h...7/drawline.htm
Comment
-
If your Plot()s are never being set, what is the purpose of having the objects at all? Just using them as a repository of color seems rather a waste, as making the line colors a parameter just makes a little more sense.Originally posted by JimPunkrockford View Postahh yes, the colors can now be set. unfortunately that is all, i can't change line widths or make dashed or change to dots.
would that be an easy fix? if not, no worries
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
580 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
336 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
554 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
552 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment