using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
namespace NinjaTrader.NinjaScript.Indicators
{
public class ReversalIndicator : Indicator
{
// Set up variables to track the high and low of the current range
double rangeHigh = 0;
double rangeLow = 0;
// Set up variables to track the reversal direction
bool reversalUp = false;
bool reversalDown = false;
// This method is called at the beginning of each bar
protected override void OnBarUpdate()
{
// Check if we are at the start of a new range
if (BarsInProgress == 0)
{
// Set the high and low of the range to the current open price
rangeHigh = Open[0];
rangeLow = Open[0];
}
// Update the range high and low if the current high or low is higher/lower than the current range
rangeHigh = Math.Max(rangeHigh, High[0]);
rangeLow = Math.Min(rangeLow, Low[0]);
// Check if the current close is outside the range
if (Close[0] > rangeHigh || Close[0] < rangeLow)
{
// Set the reversal direction
if (Close[0] > rangeHigh)
{
reversalUp = true;
reversalDown = false;
}
else
{
reversalDown = true;
reversalUp = false;
}
// Reset the range high and low
rangeHigh = Open[0];
rangeLow = Open[0];
}
else
{
// No reversal
reversalUp = false;
reversalDown = false;
}
}
// This method is called to draw the indicator on the chart
protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
{
// Draw an up arrow if the reversalUp variable is true
if (reversalUp)
{
chartControl.ChartPanel.Add(new Gui.Chart.ChartArrow(
new Pen(Color.Green, 2),
new Pen(Color.Green, 2),
0,
0,
50,
50,
-45,
chartControl.GetXByTime(Time[0]),
chartControl.GetYByValue(High[0]),
Comment