I'm attempting to plot an indicator that uses a higher timeframe as an input but running into issues. I can access the data from the indicator but I can't figure out how to plot it on the chart.
After looking into the issue, I now know that AddChartIndicator() doesn't work with indicators that use a data series that is not the primary data series. In some other forum threads I've seen some references to using AddPlot() within the strategy to display the data from the indicator but, most of the documentation for AddPlot() revolves around using it within an indicator. I've played around with AddPlot() but haven't been able to wrap my head around I should be using it.
The sample strategy below is being applied to a 1 minute chart and attempting to plot an Aroon indicator using a 15 minute data series. With the sample code below, how would I display the Aroon15Min indicator on the chart? As it is written, AddChartIndicator(Aroon15Min) generates a blank indicator panel that does not plot any of the data.
#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.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class HigherTimeframeIndicator : Strategy
{
private Aroon Aroon15Min;
private Aroon AroonPrimary;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "HigherTimeframeIndicator";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
OverboughtThreshold = 70;
OversoldThreshold = 30;
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Minute, 15);
}
else if (State == State.DataLoaded)
{
Aroon15Min = Aroon(Closes[1], 14);
Aroon15Min.Plots[0].Brush = Brushes.DarkCyan;
Aroon15Min.Plots[1].Brush = Brushes.SlateBlue;
AddChartIndicator(Aroon15Min);
AroonPrimary = Aroon(Close, 14);
AroonPrimary.Plots[0].Brush = Brushes.DarkCyan;
AroonPrimary.Plots[1].Brush = Brushes.SlateBlue;
AddChartIndicator(AroonPrimary);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1
|| CurrentBars[1] < 0)
return;
// Set 1
if ((Aroon15Min.Up[0] >= OverboughtThreshold)
&& (AroonPrimary.Up[0] >= OverboughtThreshold))
{
EnterLong(Convert.ToInt32(DefaultQuantity), @"Long");
}
// Set 2
if ((Position.MarketPosition == MarketPosition.Long)
&& (Aroon15Min.Up[0] < OverboughtThreshold)
&& (AroonPrimary.Up[0] < OverboughtThreshold))
{
ExitLong(Convert.ToInt32(DefaultQuantity), @"ExitLong", @"Long");
}
}
#region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="OverboughtThreshold", Order=1, GroupName="Parameters")]
public int OverboughtThreshold
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="OversoldThreshold", Order=2, GroupName="Parameters")]
public int OversoldThreshold
{ get; set; }
#endregion
}
}

Comment