I am trying to convert a strategy from Thinkorswim platform using Strategy Builder. I am new to NinjaTrader platform.
My strategy uses ES 233 tick values to generate buy and sell signals.
I know you can compare indicator outputs with other indicator outputs or values but what if I need to compute some numbers from VIX to compare with .
For example I need to check
RSI(14, ES 233 tick) < L+ K*VIX
How you can calculate L+K*VIX in a condition statement in Strategy Builder?
I got the impression that I have to write an indicator to calculate this simple value, so I wrote the following indicator which works on the ES tick chart. It simply plots O=L+K*VIX in the bottom panel. Inputs are 'K' and 'L' coefficients, output is 'O' which is L+K*VIX. This works with charts but doesnt work in strategybuilder. I would greatly appreciate if someone can tell me why this simple indicator doesnt work in StrategyBuilder.
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 DynaT : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "DynaT";
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;
L = 50;
K = 0.05;
AddPlot(Brushes.Orange, "O");
}
else if (State == State.Configure)
{
AddDataSeries("^VIX", BarsPeriods[0].BarsPeriodType, BarsPeriods[0].BaseBarsPeriodValue, Data.MarketDataType.Last);
}
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] > 10 && CurrentBars[1] > 10) {
//double ot;
if (BarsInProgress == 0)
O[0]=L+K*EMA(Closes[1],10)[0];
}
//Add your custom indicator logic here.
}
region Properties
[NinjaScriptProperty]
[Range(1, double.MaxValue)]
[Display(Name="L", Description="RSI treshold", Order=1, GroupName="Parameters")]
public double L
{ get; set; }
[NinjaScriptProperty]
[Range(-1, double.MaxValue)]
[Display(Name="K", Order=2, GroupName="Parameters")]
public double K
{ get; set; }
[Browsable(false)]
[XmlIgnore]
public Series<double> O
{
get { return Values[0]; }
}
#endregion
}
}
region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private DynaT[] cacheDynaT;
public DynaT DynaT(double l, double k)
{
return DynaT(Input, l, k);
}
public DynaT DynaT(ISeries<double> input, double l, double k)
{
if (cacheDynaT != null)
for (int idx = 0; idx < cacheDynaT.Length; idx++)
if (cacheDynaT[idx] != null && cacheDynaT[idx].L == l && cacheDynaT[idx].K == k && cacheDynaT[idx].EqualsInput(input))
return cacheDynaT[idx];
return CacheIndicator<DynaT>(new DynaT(){ L = l, K = k }, input, ref cacheDynaT);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.DynaT DynaT(double l, double k)
{
return indicator.DynaT(Input, l, k);
}
public Indicators.DynaT DynaT(ISeries<double> input , double l, double k)
{
return indicator.DynaT(input, l, k);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.DynaT DynaT(double l, double k)
{
return indicator.DynaT(Input, l, k);
}
public Indicators.DynaT DynaT(ISeries<double> input , double l, double k)
{
return indicator.DynaT(input, l, k);
}
}
}
#endregion

Comment