#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
namespace NinjaTrader.Indicator
{
[Description("")]
[Gui.Design.DisplayName("FractalPivot (TradeStation)")]
public class FractalPivot_TradeStation : Indicator
{
#region Variables
private int pLeftStrength = 2;
private int pRightStrength = 2;
private int pTickSeparation = 3;
#endregion
protected override void Initialize()
{
Add(new Plot(new Pen(Color.Red,12), PlotStyle.TriangleDown, "Highs"));
Add(new Plot(new Pen(Color.Blue,12), PlotStyle.TriangleUp, "Lows"));
//PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\Alert4.wav");
CalculateOnBarClose = false;
Overlay = true;
PriceTypeSupported = false;
}
protected override void OnBarUpdate()
{
if(CurrentBar < Math.Max((pLeftStrength+pRightStrength)*3,15))
return;
if(pType == FractalPivot_TradeStation_Type.Both || pType == FractalPivot_TradeStation_Type.Highs) {
int bar = (int)Pivot_EasyLanguage(1, 1, pLeftStrength, pRightStrength+1, pRightStrength).PivotBarRelative[0];
if(bar>=0) Values[0].Set(pRightStrength, High[pRightStrength]+TickSize * pTickSeparation);
}
if(pType == FractalPivot_TradeStation_Type.Both || pType == FractalPivot_TradeStation_Type.Lows) {
int bar = (int)Pivot_EasyLanguage(-1, 1, pLeftStrength, pRightStrength+1, pRightStrength).PivotBarRelative[0];
if(bar>=0) Values[1].Set(pRightStrength, Low[pRightStrength]-TickSize * pTickSeparation);
}
}
//====================================================================
#region Properties
[Description("Ticks separation from bar")]
[Category("Visual")]
public int TickSeparation
{
get { return pTickSeparation; }
set { pTickSeparation = Math.Max(1,value); }
}
[Description("Left strength")]
[Category("Parameters")]
public int LeftStrength
{
get { return pLeftStrength; }
set { pLeftStrength = Math.Max(1,value); }
}
[Description("Right strength")]
[Category("Parameters")]
public int RightStrength
{
get { return pRightStrength; }
set { pRightStrength = Math.Max(1,value); }
}
private FractalPivot_TradeStation_Type pType = FractalPivot_TradeStation_Type.Both;
[Description("High prices, Low prices, or both")]
[Category("Parameters")]
public FractalPivot_TradeStation_Type Type
{
get { return pType; }
set { pType = value; }
}
#endregion
}
}
public enum FractalPivot_TradeStation_Type {
Highs,
Lows,
Both
}
#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
public partial class Indicator : IndicatorBase
{
private FractalPivot_TradeStation[] cacheFractalPivot_TradeStation = null;
private static FractalPivot_TradeStation checkFractalPivot_TradeStation = new FractalPivot_TradeStation();
/// <summary>
///
/// </summary>
/// <returns></returns>
public FractalPivot_TradeStation FractalPivot_TradeStation(int leftStrength, int rightStrength, FractalPivot_TradeStation_Type type)
{
return FractalPivot_TradeStation(Input, leftStrength, rightStrength, type);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public FractalPivot_TradeStation FractalPivot_TradeStation(Data.IDataSeries input, int leftStrength, int rightStrength, FractalPivot_TradeStation_Type type)
{
if (cacheFractalPivot_TradeStation != null)
for (int idx = 0; idx < cacheFractalPivot_TradeStation.Length; idx++)
if (cacheFractalPivot_TradeStation[idx].LeftStrength == leftStrength && cacheFractalPivot_TradeStation[idx].RightStrength == rightStrength && cacheFractalPivot_TradeStation[idx].Type == type && cacheFractalPivot_TradeStation[idx].EqualsInput(input))
return cacheFractalPivot_TradeStation[idx];
lock (checkFractalPivot_TradeStation)
{
checkFractalPivot_TradeStation.LeftStrength = leftStrength;
leftStrength = checkFractalPivot_TradeStation.LeftStrength;
checkFractalPivot_TradeStation.RightStrength = rightStrength;
rightStrength = checkFractalPivot_TradeStation.RightStrength;
checkFractalPivot_TradeStation.Type = type;
type = checkFractalPivot_TradeStation.Type;
if (cacheFractalPivot_TradeStation != null)
for (int idx = 0; idx < cacheFractalPivot_TradeStation.Length; idx++)
if (cacheFractalPivot_TradeStation[idx].LeftStrength == leftStrength && cacheFractalPivot_TradeStation[idx].RightStrength == rightStrength && cacheFractalPivot_TradeStation[idx].Type == type && cacheFractalPivot_TradeStation[idx].EqualsInput(input))
return cacheFractalPivot_TradeStation[idx];
FractalPivot_TradeStation indicator = new FractalPivot_TradeStation();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.LeftStrength = leftStrength;
indicator.RightStrength = rightStrength;
indicator.Type = type;
Indicators.Add(indicator);
indicator.SetUp();
FractalPivot_TradeStation[] tmp = new FractalPivot_TradeStation[cacheFractalPivot_TradeStation == null ? 1 : cacheFractalPivot_TradeStation.Length + 1];
if (cacheFractalPivot_TradeStation != null)
cacheFractalPivot_TradeStation.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheFractalPivot_TradeStation = tmp;
return indicator;
}
}
}
}
// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
public partial class Column : ColumnBase
{
/// <summary>
///
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.FractalPivot_TradeStation FractalPivot_TradeStation(int leftStrength, int rightStrength, FractalPivot_TradeStation_Type type)
{
return _indicator.FractalPivot_TradeStation(Input, leftStrength, rightStrength, type);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public Indicator.FractalPivot_TradeStation FractalPivot_TradeStation(Data.IDataSeries input, int leftStrength, int rightStrength, FractalPivot_TradeStation_Type type)
{
return _indicator.FractalPivot_TradeStation(input, leftStrength, rightStrength, type);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
///
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.FractalPivot_TradeStation FractalPivot_TradeStation(int leftStrength, int rightStrength, FractalPivot_TradeStation_Type type)
{
return _indicator.FractalPivot_TradeStation(Input, leftStrength, rightStrength, type);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public Indicator.FractalPivot_TradeStation FractalPivot_TradeStation(Data.IDataSeries input, int leftStrength, int rightStrength, FractalPivot_TradeStation_Type type)
{
if (InInitialize && input == null)
throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
return _indicator.FractalPivot_TradeStation(input, leftStrength, rightStrength, type);
}
}
}
#endregion