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

Problem modifying an existing NT8 Indicator a Heuristic exercize - Not Urgent

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

    Problem modifying an existing NT8 Indicator a Heuristic exercize - Not Urgent

    I want to change the existing "Pivots" indicator and save it under a new name - "Pivot". I make some changes and compile it. The compile completes with no errors. When I go to add the indicator to a chart I get the following:
    Unhandled exception. Unable to cast object of type 'NinjaTrader.NinjaScript.Indicators.Pivot to type 'NinjaTrader.NinjaScript.Indicators.Pivots'
    Here is the code:
    [CODE
    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    [TypeConverter("NinjaTrader.NinjaScript.Indicators. PivotsTypeConverter")]
    public class Pivot : Indicator
    {
    private DateTime cacheMonthlyEndDate = Globals.MinDate;
    private DateTime cacheSessionDate = Globals.MinDate;
    private DateTime cacheSessionEnd = Globals.MinDate;
    private DateTime cacheTime;
    private DateTime cacheWeeklyEndDate = Globals.MinDate;
    private DateTime currentDate = Globals.MinDate;
    private DateTime currentMonth = Globals.MinDate;
    private DateTime currentWeek = Globals.MinDate;
    private DateTime sessionDateTmp = Globals.MinDate;
    private HLCCalculationMode priorDayHlc;
    private PivotRange pivotRangeType;
    private SessionIterator storedSession;
    private double currentClose;
    private double currentHigh = double.MinValue;
    private double currentLow = double.MaxValue;
    private double dailyBarClose = double.MinValue;
    private double dailyBarHigh = double.MinValue;
    private double dailyBarLow = double.MinValue;
    private double pp;
    private double r1;
    private double r2;
    private double r3;
    private double s1;
    private double s2;
    private double s3;
    private double userDefinedClose;
    private double userDefinedHigh;
    private double userDefinedLow;
    private int cacheBar;
    private int width = 20;
    private readonly List<int> newSessionBarIdxArr = new List<int>();

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "\r\nThe Daily Pivots indicator can be used to display floor pivots, Globex pivots and the high, low and close of the prior day.";
    Name = "Pivot";
    Calculate = Calculate.OnBarClose;
    DisplayInDataBox = true;
    DrawOnPricePanel = false;
    IsAutoScale = false;
    IsOverlay = true;
    PaintPriceMarkers = true;
    ScaleJustification = ScaleJustification.Right;

    // AddPlot(Brushes.Goldenrod, NinjaTrader.Custom.Resource.PivotPP);
    AddPlot(new Stroke(Brushes.White,3), PlotStyle.Hash,"PP");
    // AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.PivotR1);
    AddPlot(new Stroke(Brushes.Red,3), PlotStyle.Hash,"R1");
    // AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.PivotR2);
    AddPlot(new Stroke(Brushes.Red,3), PlotStyle.Hash,"R2");
    // AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.PivotR3);
    AddPlot(new Stroke(Brushes.Red,3), PlotStyle.Hash,"R3");
    // AddPlot(Brushes.Crimson, NinjaTrader.Custom.Resource.PivotS1);
    AddPlot(new Stroke(Brushes.Lime,3), PlotStyle.Hash,"S1");
    // AddPlot(Brushes.Crimson, NinjaTrader.Custom.Resource.PivotS2);
    AddPlot(new Stroke(Brushes.Lime,3), PlotStyle.Hash,"S2");
    // AddPlot(Brushes.Crimson, NinjaTrader.Custom.Resource.PivotS3);
    AddPlot(new Stroke(Brushes.Lime,3), PlotStyle.Hash,"S3");
    }
    else if (State == State.Configure)
    {
    if (priorDayHlc == HLCCalculationMode.DailyBars)
    AddDataSeries(BarsPeriodType.Day, 1);
    }
    else if (State == State.DataLoaded)
    {
    storedSession = new SessionIterator(Bars);
    }
    else if (State == State.Historical)
    {
    if (priorDayHlc == HLCCalculationMode.DailyBars && BarsArray[1].DayCount <= 0)
    {
    Draw.TextFixed(this, "NinjaScriptInfo", NinjaTrader.Custom.Resource.PiviotsDailyDataError, TextPosition.BottomRight);
    Log(NinjaTrader.Custom.Resource.PiviotsDailyDataEr ror, LogLevel.Error);
    return;
    }



    [/CODE]

    Looks like there's a limit on the number of characters - which sucks. Let me know if this is enough or if I need to do something else to show more/all of the code.

    #2
    Hello dmking,

    Thanks for your post.

    If you right click on an open Pivots Indicator, and select Save As, you can clone the indicator. You will still need to make sure that all references for "Pivots" are renamed to match your new indicator class. This indicator also uses a TypeConverter, so the TypeConverter will have to be updated for the new indicator. Additionally, there variables declared in the global namespace that would need to be renamed as well.

    I have attached a version of this indicator that is duplicated. Please compare this source code against the original indicator source code using your favorite diff utility to note the exact changes.

    Please let us know if we can be of further assistance.
    Attached Files
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Brevo, Today, 01:45 AM
    0 responses
    2 views
    0 likes
    Last Post Brevo
    by Brevo
     
    Started by aussugardefender, Today, 01:07 AM
    0 responses
    3 views
    0 likes
    Last Post aussugardefender  
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    238 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    9 responses
    384 views
    1 like
    Last Post Gavini
    by Gavini
     
    Started by oviejo, Today, 12:28 AM
    0 responses
    4 views
    0 likes
    Last Post oviejo
    by oviejo
     
    Working...
    X