Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

In ES strategy , I need to compare indicator outputs with processed values of VIX

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    In ES strategy , I need to compare indicator outputs with processed values of VIX

    Hello,

    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​

    #2
    Hello ,algomaniac

    If you made an indicator that calculates the value the easiest way forward would be to just use that indicator in the strategy builder. Doing math in the builder is a much more complicated process because you need to use series and offsets to do that math. The indicator approach would be the suggested way to do any math that takes more than 1 operation.

    The indicator appears to be coded so that it would produce a plot which the builder can then reference, was there some issue with using that in the builder? We would need to know what kind of condition you had used inthe builder and what the result was to better understand what's happening.

    Comment


      #3
      Thanks for the reply.

      This is the condition I want to implement in Strategy Builder:

      RSI(11,2),Avg[0]<=DynaT(LongT,0.05)[0]



      Here DynaT is the indicator I wrote to calculate LongT+0.05*EMA(VIX,10)


      The indicator works just fine on a ES 233tick chart. As you can see from the attached screenshot, it plots 50+0.05*EMA(VIX,10) in the bottom panel.

      When I call this indicator from Strategy Builder to compare indicator value with RSI value, it doesnt work. No error message, nothing ... When I backtest it , strategy analyzer just quits and returns no result.

      I had included the indicator code in my first post , do you see any anomaly in the code that can cause problems in strategy builder?


      Indicator on ES 233 tick chart

      Click image for larger version  Name:	Screenshot 2023-11-08 180659.png Views:	0 Size:	170.2 KB ID:	1277099


      Indicator Code
      Click image for larger version

Name:	Screenshot 2023-11-08 212332.png
Views:	148
Size:	59.1 KB
ID:	1277124

      Strategy builder condition that doesnt work

      Click image for larger version

Name:	Screenshot 2023-11-08 212619.png
Views:	147
Size:	6.2 KB
ID:	1277125
      Attached Files
      Last edited by algomaniac; 11-08-2023, 08:27 PM.

      Comment


        #4
        Hello algomaniac,

        If nothing happens with your condition that likely just means the condition was not true. To know what is happening you would need to use a Misc -> Print action to output the indicators values from the strategy. You can do that in a new empty set so you can see the indicator values for every bar. Based on that observation you can determine why the condition is not becoming ture based on the values you see.

        Comment


          #5
          Thank you for the reply. I resolved the issue but now I am facing another problem which is I can not get VIX values for extended hours. I know VIX index is an RTH-only data. Is there a way to use the last RTH value of VIX in extended hours and globex session in my code. Thanks in advance

          Comment


            #6
            Hello algomaniac,

            If the instrument you add only uses RTH and does not have ETH data then that would be all the data that could be used from that instrument. You can still reference that series in price conditions and the last closed bar of data would be used from that series. From your image you are using an indicator with the secondary series so after the RTH hours the value would not change until the following day.



            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            53 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            130 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            70 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            44 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            49 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X