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 NT7 VPCI code to NT*

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

  • NinjaTrader_ChelseaB
    replied
    Hello dmking,

    Below is a link to a forum post with helpful information about getting started with NinjaScript.

    Leave a comment:


  • dmking
    replied
    Thanks Chelsea,

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

    Kind regards,

    D

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    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.

    Leave a comment:


  • dmking
    replied
    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.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    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.

    Leave a comment:


  • dmking
    started a topic Converting NT7 VPCI code to NT*

    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

Latest Posts

Collapse

Topics Statistics Last Post
Started by kujista, Today, 06:23 AM
4 responses
14 views
0 likes
Last Post NinjaTrader_ChelseaB  
Started by traderqz, Yesterday, 09:06 AM
2 responses
16 views
0 likes
Last Post traderqz  
Started by traderqz, Today, 12:06 AM
3 responses
6 views
0 likes
Last Post NinjaTrader_Gaby  
Started by RideMe, 04-07-2024, 04:54 PM
5 responses
28 views
0 likes
Last Post NinjaTrader_BrandonH  
Started by f.saeidi, Today, 08:13 AM
1 response
8 views
0 likes
Last Post NinjaTrader_ChelseaB  
Working...
X