//
// Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//
#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>
/// The TRIX (Triple Exponential Average) displays the percentage Rate of Change (ROC) of a triple EMA. Trix oscillates above and below the zero value. The indicator applies triple smoothing in an attempt to eliminate insignificant price movements within the trend that you're trying to isolate.
/// </summary>
[Description("The TRIX (Triple Exponential Average) displays the percentage Rate of Change (ROC) of a triple EMA. Trix oscillates above and below the zero value. The indicator applies triple smoothing in an attempt to eliminate insignificant price movements within the trend that you're trying to isolate.")]
public class TRIXc : Indicator
{
#region Variables
private int period = 8;
private int signalPeriod = 1;
private string sellText = @"SELL";
private Font pfont = new Font("Arial", 12, FontStyle.Bold, GraphicsUnit.Point);
private Color sColor = Color.Red;
private string buyText = @"BUY";
private Color bColor = Color.Black;
private int yPixels = 10;
private string upArrow = "Y";
#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()
{
Add(new Plot(Color.Black, "Default"));
Add(new Plot(Color.Red, "Signal"));
Add(new Line(Color.DarkGray, 0, "Zero line"));
// Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
// Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Plot1"));
}
/// <summary>
/// Calculates the indicator value(s) at the current index.
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar == 0)
{
Value.Set(Input[0]);
return;
}
EMA tripleEma = EMA(EMA(EMA(Input, period), period), period);
double trix = 100 * ((tripleEma[0] - tripleEma[1]) / tripleEma[0]);
Default.Set(trix);
// if ((trix > 0) && (trix > ( 100 * ((tripleEma[1] - tripleEma[2]) / tripleEma[1]))))
Signal.Set(EMA(Default, signalPeriod)[0]);
if (trix < 0) upArrow = "Y";
if (trix > 0)
if (trix > 100 * ((tripleEma[1] - tripleEma[2]) / tripleEma[1]))
BackColor = Color.LightSeaGreen; // set back ground color
else if (upArrow == "Y")
{
DrawArrowDown("MyArrowDown"+CurrentBar, 0, High[0]+2* TickSize, Color.Red);
// DrawDot(CurrentBar.ToString(), 0, High[1] + 10 * TickSize, Color.Red);
// DrawText("MyText"+CurrentBar, true,"Sell", 0, High[0] + 12 * TickSize, Color.Red,pfont);
DrawText("V"+CurrentBar, true, sellText, 0, High[0] + 8 * TickSize, yPixels, sColor, pfont,
StringAlignment.Center, Color.Empty, Color.Empty, 10) ;
upArrow = "N";
}
// *********************** trouble code here ******************************
// if (trix < 0)
// if (trix > 100 * ((tripleEma[1] - tripleEma[2]) / tripleEma[1]))
// BackColor = Color.LightPink; // set back ground color
// *************************************************************************
// if (CrossBelow(TRIX(period, signalPeriod).Default, TRIX(period, signalPeriod).Signal, 1))
/* if (CrossBelow(TRIX(period, signalPeriod).Default, 0,1))
{
DrawArrowDown("MyArrowDown"+CurrentBar, 0, High[0]+2* TickSize, Color.Red);
// DrawDot(CurrentBar.ToString(), 0, High[1] + 10 * TickSize, Color.Red);
// DrawText("MyText"+CurrentBar, true,"Sell", 0, High[0] + 12 * TickSize, Color.Red,pfont);
DrawText("V"+CurrentBar, true, sellText, 0, High[0] + 8 * TickSize, yPixels, sColor, pfont,
StringAlignment.Center, Color.Empty, Color.Empty, 10) ;
}
//if (CrossAbove(TRIX(period, signalPeriod).Default, TRIX(period, signalPeriod).Signal, 1))
if (CrossAbove(TRIX(period, signalPeriod).Default, 0,1))
{
DrawArrowUp("MyArrowUp"+CurrentBar, 0, Low[0] -2* TickSize, Color.Orange);
// DrawText("MyText"+CurrentBar, "Buy", 0, Low[0] - 6 * TickSize, Color.Green);
DrawText("V"+CurrentBar, true, buyText, 0, Low[0] - 10 * TickSize, yPixels, bColor, pfont,
StringAlignment.Center, Color.Empty, Color.Empty, 10) ;
}
*/
}
#region Properties
/// <summary>
/// </summary>
[Description("Numbers of bars used for calculations.")]
[Category("Parameters")]
public int Period
{
get { return period; }
set { period = Math.Max(1, value); }
}
[Description("Period for the signal line.")]
[Category("Parameters")]
[Gui.Design.DisplayNameAttribute("Signal period")]
public int SignalPeriod
{
get { return signalPeriod; }
set { signalPeriod = Math.Max(1, value); }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore]
public DataSeries Signal
{
get { return Values[1]; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore]
public DataSeries Default
{
get { return Values[0]; }
}
#endregion
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
code makes indicator goes blank
Collapse
X
-
code makes indicator goes blank
I was able to change the back ground to blue for an up trend but the code to set back ground to magenta for a down trend make it goes blank.
Code:Tags: None
-
Same problem.....could you go over the solution?
I'm having the same problem in retrieving a DataSeries of anything larger than [1] -- same "out of range" error in log. However, I'm not clear about how and where to enter the "CurrentBar > 1" statement. Should it be entered at the beginning of the 'OnBarUpdate' or within the IF statement calling for the DataSeries? What is the syntax? Thanks!
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
579 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
334 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 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
551 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|


Comment