Simple reversal indicator
This commit is contained in:
parent
6df1d0d857
commit
8fb8117b9f
155
indicators/SimpleReversal.cs
Normal file
155
indicators/SimpleReversal.cs
Normal file
@ -0,0 +1,155 @@
|
||||
#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
|
||||
{
|
||||
public class SimpleReversal : Indicator
|
||||
{
|
||||
protected override void OnStateChange()
|
||||
{
|
||||
if (State == State.SetDefaults)
|
||||
{
|
||||
Description = @"";
|
||||
Name = "Simple Reversal";
|
||||
Calculate = Calculate.OnBarClose;
|
||||
IsOverlay = true;
|
||||
DisplayInDataBox = true;
|
||||
DrawOnPricePanel = true;
|
||||
ScaleJustification = ScaleJustification.Right;
|
||||
IsSuspendedWhileInactive = true;
|
||||
}
|
||||
else if (State == State.Configure)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnBarUpdate()
|
||||
{
|
||||
if (CurrentBar < 2)
|
||||
return;
|
||||
|
||||
if (LongReversal())
|
||||
DrawTriangle(true);
|
||||
else if (ShortReversal())
|
||||
DrawTriangle(false);
|
||||
}
|
||||
|
||||
private bool LongReversal()
|
||||
{
|
||||
return (Close[2] < Open[2]) &&
|
||||
(Low[1] < Low[2]) &&
|
||||
(Low[1] < Low[0]) &&
|
||||
(Close[0] > High[1]) &&
|
||||
(Close[0] > High[2]);
|
||||
}
|
||||
|
||||
private bool ShortReversal()
|
||||
{
|
||||
return (Close[2] > Open[2]) &&
|
||||
(High[1] > High[2]) &&
|
||||
(High[1] > High[0]) &&
|
||||
(Close[0] < Low[1]) &&
|
||||
(Close[0] < Low[2]);
|
||||
}
|
||||
|
||||
private void DrawTriangle(bool isLong)
|
||||
{
|
||||
var brush = isLong ? Brushes.LimeGreen : Brushes.Red;
|
||||
var yValue = isLong ? Low[0] : High[0];
|
||||
|
||||
if (isLong)
|
||||
{
|
||||
var triangleUp = Draw.TriangleUp(this, "LongReversal@" + CurrentBar, true, 0, yValue, brush);
|
||||
triangleUp.OutlineBrush = Brushes.Transparent;
|
||||
}
|
||||
else
|
||||
{
|
||||
var triangleDown = Draw.TriangleDown(this, "ShortReversal@" + CurrentBar, true, 0, yValue, brush);
|
||||
triangleDown.OutlineBrush = Brushes.Transparent;
|
||||
}
|
||||
}
|
||||
|
||||
public override string DisplayName
|
||||
{
|
||||
get { return Name; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region NinjaScript generated code. Neither change nor remove.
|
||||
|
||||
namespace NinjaTrader.NinjaScript.Indicators
|
||||
{
|
||||
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
|
||||
{
|
||||
private SimpleReversal[] cacheSimpleReversal;
|
||||
public SimpleReversal SimpleReversal()
|
||||
{
|
||||
return SimpleReversal(Input);
|
||||
}
|
||||
|
||||
public SimpleReversal SimpleReversal(ISeries<double> input)
|
||||
{
|
||||
if (cacheSimpleReversal != null)
|
||||
for (int idx = 0; idx < cacheSimpleReversal.Length; idx++)
|
||||
if (cacheSimpleReversal[idx] != null && cacheSimpleReversal[idx].EqualsInput(input))
|
||||
return cacheSimpleReversal[idx];
|
||||
return CacheIndicator<SimpleReversal>(new SimpleReversal(), input, ref cacheSimpleReversal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
|
||||
{
|
||||
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
|
||||
{
|
||||
public Indicators.SimpleReversal SimpleReversal()
|
||||
{
|
||||
return indicator.SimpleReversal(Input);
|
||||
}
|
||||
|
||||
public Indicators.SimpleReversal SimpleReversal(ISeries<double> input )
|
||||
{
|
||||
return indicator.SimpleReversal(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace NinjaTrader.NinjaScript.Strategies
|
||||
{
|
||||
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
|
||||
{
|
||||
public Indicators.SimpleReversal SimpleReversal()
|
||||
{
|
||||
return indicator.SimpleReversal(Input);
|
||||
}
|
||||
|
||||
public Indicators.SimpleReversal SimpleReversal(ISeries<double> input )
|
||||
{
|
||||
return indicator.SimpleReversal(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
Loading…
Reference in New Issue
Block a user