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

The attached indicator leads the crash

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

    The attached indicator leads the crash

    [NinjaTrader Version]
    6.5.1000.14

    [Brief summary of the problem encounterd]
    I am learning Ninja script and trying to use the update() method in a indicator. I have successfully compiled it but the application was clashed when I applied it to a chart.

    [Discribe in steps how to reproduce this issue]
    1. Create a daily chart.
    2. Add the attached indicator to the chart.

    Code:
            protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Dot, "trade"));
                Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Dot, "position"));   
                CalculateOnBarClose = false;
                Overlay    = true;
                PriceTypeSupported = true;
       PaintPriceMarkers = false;
       HorizontalGridLines = false;
       VerticalGridLines = false;
            }
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
     
       if (CurrentBar < 50 )
        return;
     
       if(FirstTickOfBar)
       {
         Plot0.Set(Plot0[1]);        
         Plot1.Set(0);    
                 // Condition set 1
                 if (Plot0[0] <= 0 && Close[0] > EMA(50)[0]
                     && CrossAbove(MACD(fast, slow, smooth).Avg, MACD(fast, slow, smooth), 1))
                 {
         Plot0.Set(1);
         Plot1.Set(1);
                 }
                 // Condition set 2
                 if (Plot0[0] >= 0 && Close[0] < EMA(50)[0]
                     && CrossBelow(MACD(fast, slow, smooth).Avg, MACD(fast, slow, smooth), 1))
                 {
         Plot0.Set(-1);
         Plot1.Set(-1);
                 }
                 // Condition set 3
                 if (Plot0[0] == 1 && Close[0] > EMA(50)[0]
                     && CrossBelow(MACD(fast, slow, smooth).Avg, MACD(fast, slow, smooth), 1))
                 {
         Plot0.Set(0);
         Plot1.Set(2);
                 }
                 // Condition set 4
                 if (Plot0[0] == -1 && Close[0] < EMA(50)[0]
                     && CrossAbove(MACD(fast, slow, smooth).Avg, MACD(fast, slow, smooth), 1))
                 {
         Plot0.Set(0);
         Plot1.Set(-2);
                 }
                // Use this method for calculating your indicator values. Assign a value to each
                // plot below by replacing 'Close[0]' with your own formula.
       }
       else
       {
        Plot0.Set(Plot0[1]);        
        Plot1.Set(Plot1[1]);   
       }
       Print(ToDay(Time[0]));Print(Plot0[0]);
            }
            #region Properties
     
      [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
            [XmlIgnore()]  // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
            public DataSeries Plot0
            {
                get { 
        Update();
        return Plot0; }
            }
      [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
            [XmlIgnore()]  // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
            public DataSeries Plot1
            {
                get {
        Update();
        return Plot1; }
            }
     
            [Description("Fast period for MACD")]
            [Category("Parameters")]
            public int Fast
            {
                get { return fast; }
                set { fast = Math.Max(1, value); }
            }
      [Description("Slow period for MACD")]
      [Category("Parameters")]
      public int Slow
      {
       get { return slow; }
       set { slow = Math.Max(1, value); }
      }
     
      [Description("Smoothing period for MACD")]
      [Category("Parameters")]
      public int Smooth
      {
       get { return smooth; }
       set { smooth = Math.Max(1, value); }
      }
            #endregion
    What am I writing wrong?
    Attached Files
    Last edited by takeo; 12-24-2009, 08:35 PM.

    #2
    1. Overlay = false;
    2. replace everywhere "Plot0[0]" on Value[0], or on Values[0][0]
    3. replace for each plot
    Code:
            
    public DataSeries Plot0
    {
      get { 
              Update();
              return Plot0; 
              }
    }
    on
    Code:
            
    public DataSeries Plot0
    {
      get { 
              Update();
              return Values[0]; 
            }
    }
    See in attach correct version, that works

    And look on picture, how it works
    Attached Files
    Last edited by fx.practic; 12-25-2009, 03:04 AM.
    fx.practic
    NinjaTrader Ecosystem Vendor - fx.practic

    Comment


      #3
      fx.practic,

      You do not need to use Update() at all in these instances.

      Code:
      public DataSeries Plot0
      {
             get { return Values[0]; }
      }
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        Thank's Josh. Still don't know what Update() do - as well going to read manual
        fx.practic
        NinjaTrader Ecosystem Vendor - fx.practic

        Comment


          #5
          Update() is for when you want to ensure another script referencing the first script will get most recent values. There may be special circumstances when you may not necessarily receive the most recent value when you start nesting a bunch of scripts. Use case for this is generally limited unless doing something fairly complex.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            fx.practic and Josh, thanks for your kind advice

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by PaulMohn, Today, 05:00 AM
            0 responses
            8 views
            0 likes
            Last Post PaulMohn  
            Started by ZenCortexAuCost, Today, 04:24 AM
            0 responses
            6 views
            0 likes
            Last Post ZenCortexAuCost  
            Started by ZenCortexAuCost, Today, 04:22 AM
            0 responses
            3 views
            0 likes
            Last Post ZenCortexAuCost  
            Started by SantoshXX, Today, 03:09 AM
            0 responses
            16 views
            0 likes
            Last Post SantoshXX  
            Started by DanielTynera, Today, 01:14 AM
            0 responses
            5 views
            0 likes
            Last Post DanielTynera  
            Working...
            X