#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// anaSuperTrend Indicator
/// </summary>
[Description("Modified SuperTrend Indicator based on a Moving Median")]
public class anaSuperTrendsounds : Indicator
{
#region Variables
private int periodMedian = 5; // Default setting for Median Period
private int periodATR = 21; // Default setting for ATR Period
private double multiplier = 3; // Default setting for Multiplier
private bool showArrows = true;
private bool showStopLine = true;
private bool paintBars = false;
private bool currentUpTrend = true;
private bool priorUpTrend = true;
private bool gap = false;
private double newStop = 0;
private double priorStop = 0;
private int plot0Width = 2;
private PlotStyle plot0Style = PlotStyle.Line;
private DashStyle dash0Style = DashStyle.Dash;
private Color upColor = Color.Blue;
private Color downColor = Color.Red;
private Color neutralColor = Color.Transparent;
private Color priorColor = Color.Empty;
private BoolSeries upTrend;
private MovingMedian1 MM;
private ATR MAE;
private int ticksound = 2;
#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.Gray, PlotStyle.Line, "StopLine"));
CalculateOnBarClose = true;
Overlay = true;
PriceTypeSupported = true;
PlotsConfigurable = true;
upTrend = new BoolSeries(this);
}
protected override void OnStartUp()
{
Plots[0].Pen.Width = plot0Width;
Plots[0].PlotStyle = plot0Style;
Plots[0].Pen.DashStyle = dash0Style;
gap = (plot0Style == PlotStyle.Line)||(plot0Style == PlotStyle.Square);
if (ShowStopLine)
Plots[0].Pen.Color = Color.Gray;
else
Plots[0].Pen.Color = Color.Transparent;
MM = MovingMedian1(Inputs[0], periodMedian);
MAE = ATR(Inputs[0],periodATR);
}
/// <summary>
/// Called on each bar update event (incoming tick)
protected override void OnBarUpdate()
{
if (CurrentBar == 0)
{
upTrend.Set(true);
StopLine.Set (Close[0]);
PlotColors[0][0] = neutralColor;
return;
}
if (FirstTickOfBar)
{
priorUpTrend = upTrend[1];
priorStop = StopLine[1];
priorColor = PlotColors[0][1];
}
if (Close[0] > priorStop)
{
upTrend.Set(true);
newStop = MM[0] - Multiplier * MAE[0];
currentUpTrend = true;
if (!priorUpTrend) // trend change up
StopLine.Set(newStop);
else
StopLine.Set(Math.Max(newStop, priorStop));
}
else if (Close[0] < priorStop)
{
upTrend.Set(false);
newStop = MM[0]+ Multiplier * MAE[0];
currentUpTrend = false;
if (priorUpTrend) // trend change down
StopLine.Set(newStop);
else
StopLine.Set(Math.Min(newStop,priorStop));
}
else
{
upTrend.Set(priorUpTrend);
currentUpTrend = priorUpTrend;
StopLine.Set(priorStop);
}
if(PaintBars)
{
if (currentUpTrend)
{
CandleOutlineColor = upColor;
if(Open[0] < Close[0] && ChartControl.ChartStyleType == ChartStyleType.CandleStick )
BarColor = Color.Transparent;
else
BarColor = upColor;
}
else
{
CandleOutlineColor = downColor;
if(Open[0] < Close[0] && ChartControl.ChartStyleType == ChartStyleType.CandleStick )
BarColor = Color.Transparent;
else
BarColor = downColor;
}
}
if(ShowArrows)
{
if(currentUpTrend && !priorUpTrend)
DrawArrowUp(CurrentBar.ToString(), true, 1, newStop - 8*TickSize, upColor);
else if(!currentUpTrend && priorUpTrend)
DrawArrowDown(CurrentBar.ToString(), true, 1, newStop + 8*TickSize, downColor);
}
if(ShowStopLine)
{
if(currentUpTrend && !priorUpTrend)
{
if (gap)
PlotColors[0][0]= neutralColor;
else
PlotColors[0][0] = upColor;
}
else if (currentUpTrend)
PlotColors[0][0] = upColor;
else if(!currentUpTrend && priorUpTrend)
{
if (gap)
PlotColors[0][0]= neutralColor;
else
PlotColors[0][0] = downColor;
}
else
PlotColors[0][0] = downColor;
}
;;
;
//Soundcheck 2 ticks up n down before trend switches
Comment