Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Converting Bid/Ask info from TS

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

    Converting Bid/Ask info from TS

    In Tradestation, I developed a simple code the multiplys the CCI value by the difference between the Upticks and Downticks, as a percentage of their sum. Similar to:

    If UpTicks > DownTicks
    Bar = CCI * (UpTicks - DownTicks)/(UpTick + DownTicks)//plots blue bar above zero line

    If UpTicks < DownTicks
    Bar = CCI * (DownTicks - UpTicks)/(UpTick + DownTicks)*(-1)//plots red bar below zero line

    If UpTicks = DownTicks
    Bar = 0.

    Since CCI measures momentum to either side, this indicator would start to show when an uptrend (downtrend) is getting weak.


    Any help would be greatly appreciated.

    Thanks,

    #2
    MrPips55, welcome to our forums here at NinjaTrader!

    You would need to code the Up / DnTicks part out yourself unfortunately, more info can be found here - http://www.ninjatrader-support2.com/...ad.php?t=10900

    For general NinjaScript indicator programming tutorials, please check into this link - http://www.ninjatrader-support.com/H...verview18.html

    If you want this study professionally programmed for you, please contact those NinjaScript consultants - http://www.ninjatrader.com/webnew/pa...injaScript.htm
    BertrandNinjaTrader Customer Service

    Comment


      #3
      I think I'm getting close, but I get error codes:

      I'm getting error codes cs0021 and cs1502, as well as NT1503...





      if (FirstTickOfBar)
      {
      Up = 0;
      Down = 0;
      RVol = 0;
      }
      prevTick = currTick;
      currTick = Close[0];
      if (currTick > prevTick)
      Up++;
      else if (currTick < prevTick)
      Down++;
      if (Up > Down)
      RVol = ((Up-Down)/(Up + Down))*100;
      else if
      (Up < Down)
      RVol = ((Down -Up)/(Up + Down))*100;

      if (CurrentBar == 0)
      Value.Set(0);
      else
      {
      double mean = 0;
      for (int idx = Math.Min(CurrentBar, Period - 1); idx >= 0; idx--)
      mean += Math.Abs(RVol[idx] - SMA(RVol, Period)[0]);
      Value.Set((RVol[0] - SMA(RVol, Period)[0]) / (mean == 0 ? 1 : (0.015 * (mean / Math.Min(Period, CurrentBar + 1)))));
      }
      }

      can someone help?

      thanks!!!!

      Comment


        #4
        Hi there, what part of the code do the errors refer to? Can you post the complete code? That would help me pinpoint the errors.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Here is the whole code (sorry, couldn't export as zip file, NT says it's not compiled

          //
          // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
          // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
          // Version modified to include uptick and downtick differencial.

          #region Using declarations
          using System;
          using System.Diagnostics;
          using System.Drawing;
          using System.Drawing.Drawing2D;
          using System.ComponentModel;
          using System.Xml.Serialization;
          using NinjaTrader.Data;
          using NinjaTrader.Gui.Chart;
          #endregion

          // This namespace holds all indicators and is required. Do not change it.
          namespace NinjaTrader.Indicator
          {
          /// <summary>
          /// The Commodity Channel Index (CCI) measures the variation of a security's price from its statistical mean. High values show

          that prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
          /// </summary>
          [Description("The Commodity Channel Index (CCI) measures the variation of a security's price from its statistical mean. High

          values show that prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.")]
          public class MyCCI : Indicator
          {
          #region Variables
          private int period = 14;
          public int Up = 0;
          public int Down = 0;
          public int RVol = 0;
          public double currTick = 0;
          public double prevTick = 0;
          #endregion

          /// <summary>
          /// This method is used to configure the indicator and is called once before any bar data is loaded.
          /// </summary>
          protected override void Initialize()
          {
          Add(new Plot(Color.Orange, "CCI"));
          Add(new Line(Color.DarkGray, 200, "Level 2"));
          Add(new Line(Color.DarkGray, 100, "Level 1"));
          Add(new Line(Color.DarkGray, 0, "Zero line"));
          Add(new Line(Color.DarkGray, -100, "Level -1"));
          Add(new Line(Color.DarkGray, -200, "Level -2"));
          }

          /// <summary>
          /// Calculates the indicator value(s) at the current index.
          /// </summary>
          protected override void OnBarUpdate()
          {
          if (FirstTickOfBar)
          {
          Up = 0;
          Down = 0;
          RVol = 0;
          }
          prevTick = currTick;
          currTick = Close[0];
          if (currTick > prevTick)
          Up++;
          else if (currTick < prevTick)
          Down++;
          if (Up > Down)
          RVol = ((Up-Down)/(Up + Down))*100;
          else if
          (Up < Down)
          RVol = ((Down -Up)/(Up + Down))*100;

          if (CurrentBar == 0)
          Value.Set(0);
          else
          {
          double mean = 0;
          for (int idx = Math.Min(CurrentBar, Period - 1); idx >= 0; idx--)
          mean += Math.Abs(RVol[idx] - SMA(RVol, Period)[0]);
          Value.Set((RVol[0] - SMA(RVol, Period)[0]) / (mean == 0 ? 1 : (0.015 * (mean / Math.Min(Period,

          CurrentBar + 1)))));
          }
          }

          #region Properties
          /// <summary>
          /// </summary>
          [Description("Numbers of bars used for calculations")]
          [Category("Parameters")]
          public int Period
          {
          get { return period; }
          set { period = Math.Max(1, value); }
          }
          #endregion
          }
          }

          #region NinjaScript generated code. Neither change nor remove.
          // This namespace holds all indicators and is required. Do not change it.
          namespace NinjaTrader.Indicator
          {
          public partial class Indicator : IndicatorBase
          {
          private MyCCI[] cacheMyCCI = null;

          private static MyCCI checkMyCCI = new MyCCI();

          /// <summary>
          /// The Commodity Channel Index (CCI) measures the variation of a security's price from its statistical mean. High values show that

          prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
          /// </summary>
          /// <returns></returns>
          public MyCCI MyCCI(int period)
          {
          return MyCCI(Input, period);
          }

          /// <summary>
          /// The Commodity Channel Index (CCI) measures the variation of a security's price from its statistical mean. High values show that

          prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
          /// </summary>
          /// <returns></returns>
          public MyCCI MyCCI(Data.IDataSeries input, int period)
          {
          checkMyCCI.Period = period;
          period = checkMyCCI.Period;

          if (cacheMyCCI != null)
          for (int idx = 0; idx < cacheMyCCI.Length; idx++)
          if (cacheMyCCI[idx].Period == period && cacheMyCCI[idx].EqualsInput(input))
          return cacheMyCCI[idx];

          MyCCI indicator = new MyCCI();
          indicator.BarsRequired = BarsRequired;
          indicator.CalculateOnBarClose = CalculateOnBarClose;
          indicator.Input = input;
          indicator.Period = period;
          indicator.SetUp();

          MyCCI[] tmp = new MyCCI[cacheMyCCI == null ? 1 : cacheMyCCI.Length + 1];
          if (cacheMyCCI != null)
          cacheMyCCI.CopyTo(tmp, 0);
          tmp[tmp.Length - 1] = indicator;
          cacheMyCCI = tmp;
          Indicators.Add(indicator);

          return indicator;
          }

          }
          }

          // This namespace holds all market analyzer column definitions and is required. Do not change it.
          namespace NinjaTrader.MarketAnalyzer
          {
          public partial class Column : ColumnBase
          {
          /// <summary>
          /// The Commodity Channel Index (CCI) measures the variation of a security's price from its statistical mean. High values show that

          prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
          /// </summary>
          /// <returns></returns>
          [Gui.Design.WizardCondition("Indicator")]
          public Indicator.MyCCI MyCCI(int period)
          {
          return _indicator.MyCCI(Input, period);
          }

          /// <summary>
          /// The Commodity Channel Index (CCI) measures the variation of a security's price from its statistical mean. High values show that

          prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
          /// </summary>
          /// <returns></returns>
          public Indicator.MyCCI MyCCI(Data.IDataSeries input, int period)
          {
          return _indicator.MyCCI(input, period);
          }

          }
          }

          // This namespace holds all strategies and is required. Do not change it.
          namespace NinjaTrader.Strategy
          {
          public partial class Strategy : StrategyBase
          {
          /// <summary>
          /// The Commodity Channel Index (CCI) measures the variation of a security's price from its statistical mean. High values show that

          prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
          /// </summary>
          /// <returns></returns>
          [Gui.Design.WizardCondition("Indicator")]
          public Indicator.MyCCI MyCCI(int period)
          {
          return _indicator.MyCCI(Input, period);
          }

          /// <summary>
          /// The Commodity Channel Index (CCI) measures the variation of a security's price from its statistical mean. High values show that

          prices are unusually high compared to average prices whereas low values indicate that prices are unusually low.
          /// </summary>
          /// <returns></returns>
          public Indicator.MyCCI MyCCI(Data.IDataSeries input, int period)
          {
          if (InInitialize && input == null)
          throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()'

          method");

          return _indicator.MyCCI(input, period);
          }

          }
          }
          #endregion

          Comment


            #6
            And here is a picture of the error codes

            the error messages are shown on the pic, with the lines and errors noted by NT compiler
            Attached Files

            Comment


              #7
              All of those errors stem from the fact that RVol is an integer variable, but is called in many functions like it is a DataSeries.

              I'm not sure the specifics of what you're trying to accomplish, but I have a feeling that another DataSeries is necessary for your intermediate calculations.
              AustinNinjaTrader Customer Service

              Comment


                #8
                Not sure how to fix that

                What exactly is a data series? couldn't just be number... I tried to define RVol as a double, and that didn't work either...
                I 'stole' the formula from the CCI that comes with Ninja, and replaced "Typical", with RVol.

                BTW: thank you so much for the quick replies.

                Comment


                  #9
                  A DataSeries is basically just a set/history of double values. There is a reference sample that demonstrates how to use a DataSeries to store calculations values here.
                  AustinNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by bortz, 11-06-2023, 08:04 AM
                  47 responses
                  1,603 views
                  0 likes
                  Last Post aligator  
                  Started by jaybedreamin, Today, 05:56 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post jaybedreamin  
                  Started by DJ888, 04-16-2024, 06:09 PM
                  6 responses
                  18 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by Jon17, Today, 04:33 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post Jon17
                  by Jon17
                   
                  Started by Javierw.ok, Today, 04:12 PM
                  0 responses
                  12 views
                  0 likes
                  Last Post Javierw.ok  
                  Working...
                  X