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

Price channel %PC indicator Compile Error

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

    Price channel %PC indicator Compile Error

    Hi there,

    I have no coding experience whatsoever. I need some help if possible.

    I am trying to covert a few of my favorite indicators and keep getting the same error even after corrections. Can't get it to compile without errors. This is a price channel %PC indicator. Similar to this https://help.tradestation.com/10_00/...indicator_.htm


    Hoping someone can help me fix the errors.

    Thanks!


    region Using declarations
    using System;
    using System.ComponentModel;
    using System.Windows.Media;
    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;
    #endregion

    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class PriceChannelPctNinja : Indicator
    {
    private Brush backgroundColorAlertCell;
    private bool colorPercentP;
    private Brush percentPHighColor;
    private Brush percentPLowColor;
    private Brush percentPVeryHighColor;
    private Brush percentPVeryLowColor;

    private double lowerBand;
    private double upperBand;
    private double percentP;
    private double scaledPercentP;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"The Price Channel % PC indicator calculates the percent change of the price channel.";
    Name = "PriceChannelPctNinja";
    Calculate = Calculate.OnPriceChange;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;

    length = 20;
    colorPercentP = true;
    percentPVeryHighColor = Brushes.Yellow;
    percentPHighColor = Brushes.Red;
    percentPLowColor = Brushes.Magenta;
    percentPVeryLowColor = Brushes.Cyan;
    backgroundColorAlertCell = Brushes.DarkGray;

    AddPlot(Brushes.Cyan, "%P");
    AddLine(Brushes.DarkGreen, 100, "Upper Band");
    AddLine(Brushes.DarkGreen, 50, "Middle Band");
    AddLine(Brushes.DarkGreen, 0, "Lower Band");
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    lowerBand = MIN(Low, length)[1];
    upperBand = MAX(High, length)[1];
    percentP = (upperBand != lowerBand) ? (Close[0] - lowerBand) / (upperBand - lowerBand) : 0;
    scaledPercentP = 100 * percentP;

    Plot[0].Values[0] = scaledPercentP;

    PlotBrushes[0][0] = (colorPercentP) ?
    (scaledPercentP > 100 ? percentPVeryHighColor :
    (scaledPercentP >= 50 ? percentPHighColor :
    (scaledPercentP > 0 ? percentPLowColor : percentPVeryLowColor)))
    : Brushes.Cyan;

    double upperLine = MAX(High, length)[0];
    double lowerLine = MIN(Low, length)[0];

    if (Close[0] > upperLine)
    {
    BackBrush = backgroundColorAlertCell;
    Alert("Price making new high", Priority.High, "Price making new high");
    }
    else if (Close[0] < lowerLine)
    {
    BackBrush = backgroundColorAlertCell;
    Alert("Price making new low", Priority.High, "Price making new low");
    }
    else
    {
    BackBrush = null;
    }
    }

    region Properties
    [Browsable(false)]
    [XmlIgnore()]



    region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private PriceChannelPctNinja[] cachePriceChannelPctNinja;
    public PriceChannelPctNinja PriceChannelPctNinja()
    {
    return PriceChannelPctNinja(Input);
    }

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

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.PriceChannelPctNinja PriceChannelPctNinja()
    {
    return indicator.PriceChannelPctNinja(Input);
    }

    public Indicators.PriceChannelPctNinja PriceChannelPctNinja(ISeries<double> input )
    {
    return indicator.PriceChannelPctNinja(input);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.PriceChannelPctNinja PriceChannelPctNinja()
    {
    return indicator.PriceChannelPctNinja(Input);
    }

    public Indicators.PriceChannelPctNinja PriceChannelPctNinja(ISeries<double> input )
    {
    return indicator.PriceChannelPctNinja(input);
    }
    }
    }

    #endregion

    Here are the errors.
    Error Code Line Column
    #endregion directive expected CS1038 160 1
    Type expected CS1031 106 1
    Invalid token 'namespace' in class, struct, or interface member declaration CS1519 106 1
    Invalid token '{' in class, struct, or interface member declaration CS1519 107 1
    } expected CS1513 157 2
    Class member declaration expected. 99 21
    Class member declaration expected. 105 44
    '}' expected. 156 1


    #2
    Hello tjfintrade,

    Thanks for your post.

    If you look at the compile error you could see what the possible line of code the error is located.

    The '#endregion directive expected' error means that you have not closed a region directive. Each region direction must be closed by using #endregion.

    You would need to go through your script to find where there is a missing #endregion directive and then add #endregion to the script at the end of the specified region. It seems your region Properties does not have an #endregion called after you define the properties in that region.

    The 'Class member declaration expected errors are being caused because you have not properly defined a property in the Properties region of the script.

    If you want to create a NinjaScript property, see the help guide page below. Otherwise, this section of code could likely be removed.

    NinjaScriptPropertyAttribute: https://ninjatrader.com/support/help...yattribute.htm
    Creating User-Defined Input Parameters: https://ninjatrader.com/support/help...d_input_pa.htm

    Then, you would need to resolve the '}' expected error which indicates that you are missing a closing curly brace somewhere in the script. Each opening curly brace ( '{' ) must have a closing curly brace associated with it ( '}' ). You would need to go through each line of code to see which specific opening curly brace is missing a closing curly brace.

    Below is a link to a forum post with helpful information about getting started with NinjaScript.
    https://ninjatrader.com/support/foru...040#post786040

    Please let me know if I may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by 1001111, Today, 01:35 AM
    0 responses
    1 view
    0 likes
    Last Post 1001111
    by 1001111
     
    Started by ETFVoyageur, Yesterday, 07:05 PM
    1 response
    15 views
    0 likes
    Last Post ETFVoyageur  
    Started by MarianApalaghiei, Today, 12:35 AM
    1 response
    7 views
    0 likes
    Last Post MarianApalaghiei  
    Started by Rogers101, 05-05-2024, 11:30 AM
    17 responses
    56 views
    0 likes
    Last Post Rogers101  
    Started by haas88, 03-21-2024, 02:22 AM
    13 responses
    154 views
    0 likes
    Last Post haas88
    by haas88
     
    Working...
    X