• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Converting NT7 VPCI code to NT*

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

    Converting NT7 VPCI code to NT*

    I'm using NT 8 more and thought that I would give converting some indicators from 7 to 8 a try. Can someone take a look at the following NT8 conversion of the Volume Price Confirmation Indicator code and tell me where I'm making a mistake? The VPCI and VPCIS(the EMA of the VPCI) seem to be identical.

    Thanks in advance for any suggestions.

    #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
    {

    /// <summary>
    /// Volume Price Confirmation.
    /// </summary>
    public class VolumePriceConfirmation : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Volume Price Confirmation Indicator from the July 2007 issue of Stocks & Commodities";
    Name = "VolumePriceConfirmation";
    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;
    longPeriod = 50;
    shortPeriod = 10;

    AddPlot(Brushes.Navy, "VPCI");
    AddPlot(Brushes.Red, "VPCIS");
    AddLine(Brushes.Black, 1, "ZeroLine");
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.

    double vpc = VWMA(longPeriod)[0] - SMA(longPeriod)[0];
    double vpr = (VWMA(shortPeriod)[0] / SMA(shortPeriod)[0]);
    double vm = SMA(Volume, shortPeriod)[0] / SMA(Volume, longPeriod)[0];

    VPCI[0] = (vpc * vpr * vm);
    double VPCIS = EMA(VPCI, longPeriod)[0];

    }

    #region Properties
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="longPeriod", Description="Default value of the long term period", Order=1, GroupName="Parameters")]
    public int longPeriod
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="shortPeriod", Description="Default value of the short term period", Order=2, GroupName="Parameters")]
    public int shortPeriod
    { get; set; }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> VPCI
    {
    get { return Values[0]; }
    }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> VPCIS
    {
    get { return Values[1]; }
    }

    #endregion

    }
    }

    #region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private VolumePriceConfirmation[] cacheVolumePriceConfirmation;
    public VolumePriceConfirmation VolumePriceConfirmation(int longPeriod, int shortPeriod)
    {
    return VolumePriceConfirmation(Input, longPeriod, shortPeriod);
    }

    public VolumePriceConfirmation VolumePriceConfirmation(ISeries<double> input, int longPeriod, int shortPeriod)
    {
    if (cacheVolumePriceConfirmation != null)
    for (int idx = 0; idx < cacheVolumePriceConfirmation.Length; idx++)
    if (cacheVolumePriceConfirmation[idx] != null && cacheVolumePriceConfirmation[idx].longPeriod == longPeriod && cacheVolumePriceConfirmation[idx].shortPeriod == shortPeriod && cacheVolumePriceConfirmation[idx].EqualsInput(input))
    return cacheVolumePriceConfirmation[idx];
    return CacheIndicator<VolumePriceConfirmation>(new VolumePriceConfirmation(){ longPeriod = longPeriod, shortPeriod = shortPeriod }, input, ref cacheVolumePriceConfirmation);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.VolumePriceConfirmation VolumePriceConfirmation(int longPeriod, int shortPeriod)
    {
    return indicator.VolumePriceConfirmation(Input, longPeriod, shortPeriod);
    }

    public Indicators.VolumePriceConfirmation VolumePriceConfirmation(ISeries<double> input , int longPeriod, int shortPeriod)
    {
    return indicator.VolumePriceConfirmation(input, longPeriod, shortPeriod);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.VolumePriceConfirmation VolumePriceConfirmation(int longPeriod, int shortPeriod)
    {
    return indicator.VolumePriceConfirmation(Input, longPeriod, shortPeriod);
    }

    public Indicators.VolumePriceConfirmation VolumePriceConfirmation(ISeries<double> input , int longPeriod, int shortPeriod)
    {
    return indicator.VolumePriceConfirmation(input, longPeriod, shortPeriod);
    }
    }
    }

    #endregion

    #2
    Hello dmking,

    Are you getting an error?
    If so, what is the error?

    One thing I'm noticing is that you've got a Series<double> called VPCIS declared in the scope of the class, and you are also trying to create a local double with the same name as the last line in OnBarUpdate.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the reply Chelsea.

      No errors. The code compiles, but there should be 2 plots: The VPCI -Blue, and the VPCIS (EMA of VPCI) - Red.The VPCI plots in blue but "not the VPCIS". If I comment out the plotting of the VPCI, the VPCIS plots in red which implies to me that the VPCI overlaps the VPCIS and they are identical - The VPCI plot is the same as the VPCIS.

      Comment


        #4
        Hello dmking,

        The VPCIS series (plot) is never set. You are only setting a local double variable and then never using this local variable.

        Maybe you don't want to be declaring VPCIS locally as a double and set it the same way you set VPCI[0]??

        Also to export a NinjaTrader 8 NinjaScript so that this can be shared do the following:
        1. Click Tools -> Export -> NinjaScript...
        2. Click the 'add' link -> check the box(es) for the script(s) you want to include
        3. Click the 'Export' button
        4. Enter a unique name for the file in the value for 'File name:'
        5. Choose a save location -> click Save
        6. Click OK to clear the export location message

        By default your exported file will be in the following location:
        • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>


        Below is a link to the help guide on Exporting NinjaScripts.
        http://ninjatrader.com/support/helpG...-us/export.htm
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks Chelsea,

          That did the trick. Learning C#, NinjaScript and converting from 7-->8 caused some confusion which you cleared up.

          Kind regards,

          D

          Comment


            #6
            Hello dmking,

            Below is a link to a forum post with helpful information about getting started with NinjaScript.
            http://ninjatrader.com/support/forum...609#post503609
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by dariuszszyc, Today, 12:07 AM
            1 response
            6 views
            0 likes
            Last Post login_dejavu  
            Started by KennyK, Yesterday, 09:28 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by vindiou, Yesterday, 02:37 AM
            1 response
            24 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by login_dejavu, Yesterday, 10:55 AM
            2 responses
            27 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by joemiller, Yesterday, 03:30 AM
            3 responses
            11 views
            0 likes
            Last Post joemiller  
            Working...
            X