I want to return a 1 for an uptrend and -1 for a downtrend to the market analyzer.
Please see code below and let me know how i can do this.
#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 Trend : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "Trend";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
AddPlot(new Stroke(Brushes.Transparent), PlotStyle.Line, "Plot1");
}
else if (State == State.Configure)
{
AddPlot(new Stroke(Brushes.Transparent), PlotStyle.Line, "Plot1");
}
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] < 95 )
return;
int FirstUpswingHighh = ZigZag(DeviationType.Points, .0000001, true).HighBar(0,1,100);
int FirstDnswingLowl = ZigZag(DeviationType.Points,.0000001 , true).LowBar(0,1,100);
int FirstUpswingLow = ZigZag(DeviationType.Points, .0000001, false).LowBar(0,1,100);
int FirstUpswingLowl = ZigZag(DeviationType.Points, .0000001, true).LowBar(0,1,100);
double trend=0;
if (
EMA(18)[FirstUpswingHighh]> EMA(40)[FirstUpswingHighh]
&& EMA(40)[FirstUpswingHighh]> EMA(90)[FirstUpswingHighh]
&& (Slope(EMA(40), 10, 0) >0 || Slope(EMA(20), 10, 0) >0 )
&& (Slope(EMA(40), 10, 0) >0 || Slope(EMA(90), 10, 0) >0 )
)
{
trend =1;
}
else if ( EMA(18)[FirstDnswingLowl] < EMA(40)[FirstDnswingLowl]
&& EMA(40)[FirstDnswingLowl] < EMA(90)[FirstDnswingLowl]
&& (Slope(EMA(40), 10, 0) <0 ||Slope(EMA(20), 10, 0) <0 )
&& (Slope(EMA(40), 10, 0) <0 ||Slope(EMA(90), 10, 0) <0 )
)
{
trend=-1;
}
else
{
trend =0;
}
Values[0][0]=trend;
}
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private Trend[] cacheTrend;
public Trend Trend()
{
return Trend(Input);
}
public Trend Trend(ISeries<double> input)
{
if (cacheTrend != null)
for (int idx = 0; idx < cacheTrend.Length; idx++)
if (cacheTrend[idx] != null && cacheTrend[idx].EqualsInput(input))
return cacheTrend[idx];
return CacheIndicator<Trend>(new Trend(), input, ref cacheTrend);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.Trend Trend()
{
return indicator.Trend(Input);
}
public Indicators.Trend Trend(ISeries<double> input )
{
return indicator.Trend(input);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.Trend Trend()
{
return indicator.Trend(Input);
}
public Indicators.Trend Trend(ISeries<double> input )
{
return indicator.Trend(input);
}
}
}
#endregion
Comment