#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
///
/// For Educational Purposes Only
///
public class BlueZBouncePoint : Indicator
{
private double cciVal = 0.0;
private double atrVal = 0.0;
private double upTrend = 0.0;
private double downTrend = 0.0;
private Series lineColor;
private Series flatSection;
private Series _direction;
private Series _signal;
private bool ArrowPrintedUP = false;
private bool ArrowPrintedDOWN = false;
SimpleFont textFontSymbolWing = new SimpleFont("Wingdings", 10);//, FontStyle.Bold);
private SimpleFont textFont;
private SimpleFont textFont1;
private SimpleFont textFont2;
private SimpleFont textFont3;
private int markersize = 30;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"An ATR based trendline regulated by the position of CCI and its zero line.";
Name = "BlueZBouncePoint";
Calculate = Calculate.OnBarClose;//OnPriceChange;//
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
IsOverlay = true;
DrawOnPricePanel = true;
IsSuspendedWhileInactive = true;
cciPeriod = 2;//30;
atrPeriod = 2;//50;
atrMult = 0;//0.55;
// useCciTrendColor = false;
// ColorBackground = false;//true;
// ColorBars = false;//true;
DrawArrows = true;//false;//
ArrowDisplacement = 30;
ArrowUpColor = Brushes.AliceBlue;
ArrowDownColor = Brushes.AliceBlue;
// BullBrush = Brushes.Transparent;//Lime;
PlotColor = Brushes.Yellow;
// BearBrush = Brushes.Transparent;//Red;
AddPlot(new Stroke(Brushes.Black, 4), PlotStyle.Dot, Name);
}
else if (State == State.DataLoaded)
{
Trend[0] = 0;
lineColor = new Series(this);
flatSection = new Series(this);
_direction = new Series(this, MaximumBarsLookBack.Infinite);
_signal = new Series(this, MaximumBarsLookBack.Infinite);
}
}
protected override void OnBarUpdate()
{
//ARROWS
if(CurrentBar == 0)
{
textFont = new SimpleFont("Wingdings 3",markersize);
textFont1 = new SimpleFont("Wingdings 3",markersize *0.8);//0.75
textFont2 = new SimpleFont("Wingdings 2",markersize *1.5);//t or u are diamonds
textFont3 = new SimpleFont("Wingdings 3",markersize);//t or u are diamonds
}
if (CurrentBar < cciPeriod || CurrentBar < atrPeriod)
return;
cciVal = CCI(Close, cciPeriod)[0];
atrVal = ATR(Close, atrPeriod)[0];
upTrend = Low[0] - atrVal * atrMult;
downTrend = High[0] + atrVal * atrMult;
if (cciVal >= 0)
if (upTrend < Trend[1])
Trend[0] = Trend[1];
else
Trend[0] = upTrend;
else
if (downTrend > Trend[1])
Trend[0] = Trend[1];
else
Trend[0] = downTrend;
// if (useCciTrendColor)
// lineColor[0] = cciVal > 0 ? 1 : -1;
// else
// lineColor[0] = Trend[0] > Trend[1] ? 1 : Trend[0] < Trend[1] ? -1 : lineColor[1];
// PlotBrushes[0][0] = lineColor[0] == 1 ? BullBrush : BearBrush;
flatSection[0] = Trend[0] == Trend[1];
PlotBrushes[0][0] = flatSection[0] ? PlotColor : Brushes.Transparent;
_direction[0]=(Trend[0] > Trend[1] ? 1 :
Trend[0] < Trend[1] ? -1 : 0);
// if (ColorBackground) BackBrushes[0] = (_direction[0] >0 ? Brushes.PaleGreen : _direction[0] <0 ? Brushes.Pink : Brushes.Transparent);
_signal[0]=((_direction[1]<1 && _direction[0]>0) || (CrossAbove(_direction,0.5,1) && _direction[0]>0)) ? 1 :
((_direction[1]>-1 && _direction[0]<0) || (CrossBelow(_direction,-0.5,1) && _direction[0]<0)) ? -1 : 0;
if (_signal[0] == 0)
{
ArrowPrintedUP = false;
ArrowPrintedDOWN = false;
}
double val = 0;
double spot = 0;
if(DrawArrows)
{
if (!ArrowPrintedUP && _signal[0]>0)
{
val = Low[0]-ArrowDisplacement*TickSize;
spot = Math.Min(Low[0],Trend[0])-ArrowDisplacement*TickSize;
// Draw.ArrowUp(this,"sigup"+ CurrentBar, true, 0, Low[0] - ArrowDisplacement * TickSize, ArrowUpColor);
Draw.Text(this, "sigup" + (CurrentBar),true, "h"/*"l"*/, 0, spot,0, ArrowUpColor, textFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 5);
ArrowPrintedUP = true;
}
else
if (!ArrowPrintedDOWN && _signal[0]<0)
{
val = High[0]+ArrowDisplacement*TickSize;
spot = Math.Max(High[0],Trend[0])+ArrowDisplacement*TickSize;
//Draw.ArrowDown(this,"sigdown"+ CurrentBar, true, 0, High[0] + ArrowDisplacement * TickSize, ArrowDownColor);
Draw.Text(this, "sigdown" + (CurrentBar),true, "i"/*"l"*/, 0, spot,0, ArrowDownColor, textFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 5);
ArrowPrintedDOWN = true;
}
}
}//end of OnBarUpdate()
public override string DisplayName
{
get { if (State == State.SetDefaults) return "BlueZBouncePoint"; else return ""; }
}
#region Properties
[Browsable(false)] [XmlIgnore()] public Series Trend { get { return Values[0]; } }
[Browsable(false)] [XmlIgnore()] public Series FlatSection { get { Update(); return flatSection; } }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="CCI Period", Order=1, GroupName="Parameters")]
public int cciPeriod
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="ATR Period", Order=2, GroupName="Parameters")]
public int atrPeriod
{ get; set; }
// [NinjaScriptProperty]
[Range(-20, int.MaxValue)]
[Display(Name="ATR Multiplier", Order=3, GroupName="Parameters")]
public double atrMult
{ get; set; }
// //[NinjaScriptProperty]
// [Display(Name="Use CCI Trend for Line Color", Order=4, GroupName="Parameters")]
// public bool useCciTrendColor
// { get; set; }
// [XmlIgnore()]
// [Display(Name = "Bull Color", GroupName="Colors", Order=1)]
// public Brush BullBrush
// { get; set; }
// [Browsable(false)]
// public string BullBrushSerialize
// {
// get { return Serialize.BrushToString(BullBrush); }
// set { BullBrush = Serialize.StringToBrush(value); }
// }
[XmlIgnore()]
[Display(Name = "Plot Color", GroupName="Colors", Order=2)]
public Brush PlotColor
{ get; set; }
[Browsable(false)]
public string PlotColorSerialize
{
get { return Serialize.BrushToString(PlotColor); }
set { PlotColor = Serialize.StringToBrush(value); }
}
// [XmlIgnore()]
// [Display(Name = "Bear Color", GroupName="Colors", Order=3)]
// public Brush BearBrush
// { get; set; }
// [Browsable(false)]
// public string BearBrushSerialize
// {
// get { return Serialize.BrushToString(BearBrush); }
// set { BearBrush = Serialize.StringToBrush(value); }
// }
// [Browsable(false)]
// [XmlIgnore]
// public Series Trend
// {
// get { return Values[0]; }
// }
[Display(ResourceType = typeof(Custom.Resource), Name = "01. Draw Arrows?", GroupName = "Drawing Objects", Order = 1)]
public bool DrawArrows
{ get; set; }
[Display(ResourceType = typeof(Custom.Resource), Name = "02. Arrow Displacement", GroupName = "Drawing Objects", Order = 2)]
public int ArrowDisplacement
{ get; set; }
[XmlIgnore()]
[Display(Name = "03. Color for Up Arrows?", Description = "Color for Up Arrow", GroupName = "Drawing Objects", Order = 3)]
public Brush ArrowUpColor
{ get; set; }
[Browsable(false)]
public string ArrowUpColorSerialize
{ get; set; }
[XmlIgnore()]
[Display(Name = "04. Color for Down Arrows?", Description = "Color for Down Arrows", GroupName = "Drawing Objects", Order = 4)]
public Brush ArrowDownColor
{ get; set; }
[Browsable(false)]
public string ArrowDownColorSerialize
{ get; set; }
// [Display(Name="Color Background", Description="Colors the Background", Order=4, GroupName="Display Options")]
// public bool ColorBackground
// { get; set; }
// [Display(ResourceType = typeof(Custom.Resource), Name = "Color Bars", GroupName = "Display Options", Order = 4)]
// public bool ColorBars
// { get; set; }
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private BlueZBouncePoint[] cacheBlueZBouncePoint;
public BlueZBouncePoint BlueZBouncePoint(int cciPeriod, int atrPeriod)
{
return BlueZBouncePoint(Input, cciPeriod, atrPeriod);
}
public BlueZBouncePoint BlueZBouncePoint(ISeries input, int cciPeriod, int atrPeriod)
{
if (cacheBlueZBouncePoint != null)
for (int idx = 0; idx < cacheBlueZBouncePoint.Length; idx++)
if (cacheBlueZBouncePoint[idx] != null && cacheBlueZBouncePoint[idx].cciPeriod == cciPeriod && cacheBlueZBouncePoint[idx].atrPeriod == atrPeriod && cacheBlueZBouncePoint[idx].EqualsInput(input))
return cacheBlueZBouncePoint[idx];
return CacheIndicator(new BlueZBouncePoint(){ cciPeriod = cciPeriod, atrPeriod = atrPeriod }, input, ref cacheBlueZBouncePoint);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.BlueZBouncePoint BlueZBouncePoint(int cciPeriod, int atrPeriod)
{
return indicator.BlueZBouncePoint(Input, cciPeriod, atrPeriod);
}
public Indicators.BlueZBouncePoint BlueZBouncePoint(ISeries input , int cciPeriod, int atrPeriod)
{
return indicator.BlueZBouncePoint(input, cciPeriod, atrPeriod);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.BlueZBouncePoint BlueZBouncePoint(int cciPeriod, int atrPeriod)
{
return indicator.BlueZBouncePoint(Input, cciPeriod, atrPeriod);
}
public Indicators.BlueZBouncePoint BlueZBouncePoint(ISeries input , int cciPeriod, int atrPeriod)
{
return indicator.BlueZBouncePoint(input, cciPeriod, atrPeriod);
}
}
}
#endregion