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

Why it does not plot?

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

    Why it does not plot?

    Hi,

    I am coding the HiLo Activator in 3 time frames(with default next two time frames in 50mins and 1 day). but the step lines do not plot. I checked the codes several times, but still don't get it where is wrong.

    Besides, in the single time frame HiLo, whenever I delete the DrawArrow line, the indicator does not plot either. This seems wired, because it is logically parallel with Value.Set method.

    Any help about why is this happening is highly appreciated. Here is the code:

    Code:
    
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
        /// <summary>
        /// HiLo Activator with 3 time frames
        /// </summary>
        [Description("HiLo Activator with 3 time frames")]
        public class TripleHiLo : Indicator
        {
            #region Variables
            // Wizard generated variables
                private int length = 5; // Default setting for Length
                private int nextBars = 50; // Default setting for NextBars
                private int highBars = 1; // Default setting for HighBars
            // User defined variables (add any user defined variables below)
               private double Havg,Lavg,HavgNext,LavgNext,HavgHigh,LavgHigh;
    	   private int        swing,previous_swing,swingNext,previous_swingNext,swingHigh,previous_swingHigh;
            #endregion
    
            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar      data is loaded.
            /// </summary>
            protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.Salmon), PlotStyle.Square,     "OwnBottom"));
                Add(new Plot(Color.FromKnownColor(KnownColor.SteelBlue), PlotStyle.Square, "OwnHat"));
                Add(new Plot(Color.FromKnownColor(KnownColor.Salmon), PlotStyle.Square, "NextBottom"));
                Add(new Plot(Color.FromKnownColor(KnownColor.SteelBlue), PlotStyle.Square, "NextHat"));
    			Add(new Plot(Color.FromKnownColor(KnownColor.Salmon), PlotStyle.Square, "HighBottom"));
    			Add(new Plot(Color.FromKnownColor(KnownColor.SteelBlue), PlotStyle.Square, "HighHat"));
    			
    			Add(PeriodType.Minute, nextBars);
    			Add(PeriodType.Day,highBars);
    			
                CalculateOnBarClose	= false;
                Overlay				= true;
                PriceTypeSupported	= true; // Different price types can be selected when     applying an indicator to a chart
    
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                if(BarsInProgress==0)
    			{
    			    if(CurrentBar<length+1) return;
    			    Havg = SMA(High,length)[1];
       			    Lavg = SMA(Low,length)[1];
    			    if(Input[0]<Lavg) swing = -1;
    			    if(Input[0]>Havg) swing = 1;
    
                                if(swing==-1)
    			    {
    				    if(previous_swing!=swing) 
    					{
    						DrawArrowDown(CurrentBar.ToString(), true, 0, Havg,       Color.Tomato);
    						OwnHat.Set(Havg);
    					}
    			    }
    			    if(swing==1)
    			    {
    				    if(previous_swing!=swing)
    					{
    						DrawArrowUp(CurrentBar.ToString(),true, 0, Lavg, Color.SkyBlue);
    						OwnBottom.Set(Lavg);
    					}
    				  
    			    }
    			}
    			
    			if (BarsInProgress==1)
    			{
    				if(CurrentBar<length+1) return;
    			    HavgNext = SMA(Highs[1],length)[1];
    			    LavgNext = SMA(Lows[1],length)[1];
    			    if(Input[0]<LavgNext) swingNext = -1;
    			    if(Input[0]>HavgNext) swingNext = 1;
                      
                                if(swingNext==-1)
    			    {
    				    if(previous_swingNext!=swingNext) 
    					{
    						DrawArrowDown(CurrentBar.ToString(), true, 0, HavgNext, Color.Tomato);
    						NextHat.Set(HavgNext);
    					}
    			    }
    			    if(swingNext==1)
    			    {
    				    if(previous_swingNext!=swingNext) 
    					{
    						DrawArrowUp(CurrentBar.ToString(),true, 0, LavgNext, Color.SkyBlue);
    						NextBottom.Set(LavgNext);
    					}
    			    }
    			}
    			
    			if (BarsInProgress==2)
    			{
    				if(CurrentBar<length+1) return;
    			    HavgHigh = SMA(Highs[2],length)[1];
    			    LavgHigh = SMA(Lows[2],length)[1];
    			    if(Input[0]<LavgHigh) swingHigh = -1;
    			    if(Input[0]>HavgHigh) swingHigh = 1;
                 
                                if(swingHigh==-1)
    			    {
    			  	    if(previous_swingHigh!=swingHigh)
    					{
    						DrawArrowDown(CurrentBar.ToString(), true, 0, HavgHigh, Color.Tomato);
    						HighHat.Set(HavgHigh);
    					}
    			    }
    			    if(swingHigh==1)
    			    {
    				    if(previous_swingHigh!=swingHigh) 
    					{
    						DrawArrowUp(CurrentBar.ToString(),true, 0, LavgHigh, Color.SkyBlue);
    						HighBottom.Set(LavgHigh);
    					}
    			    }
    			}
    				
      						
    			previous_swing = swing;
    			previous_swingNext = swingNext;
    			previous_swingHigh = swingHigh;
    			
            }
    
            #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 OwnBottom
            {
                get { return Values[0]; }
            }
    
            [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 OwnHat
            {
                get { return Values[1]; }
            }
    
            [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 NextBottom
            {
                get { return Values[2]; }
            }
    
            [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 NextHat
            {
                get { return Values[3]; }
            }
    		
    		[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 HighBottom
            {
                get { return Values[4]; }
            }
    		
    		[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 HighHat
            {
                get { return Values[5]; }
            }
    
            [Description("Period for all 3 time frames")]
            [GridCategory("Parameters")]
            public int Length
            {
                get { return length; }
                set { length = Math.Max(1, value); }
            }
    
            [Description("Calculating Period for BarsArray[1] (in minutes)")]
            [GridCategory("Parameters")]
            public int NextBars
            {
                get { return nextBars; }
                set { nextBars = Math.Max(1, value); }
            }
    
            [Description("Calculating Period for BarsArray[2] (in days)")]
            [GridCategory("Parameters")]
            public int HighBars
            {
                get { return highBars; }
                set { highBars = Math.Max(1, value); }
            }
            #endregion
        }
    }

    #2
    Hello wolfcuring,
    I can see the indicator working fine at my end without throwing any errors.

    In your code you are not setting values for all the plot data series and thus the plot are plotted sporadically.

    Also, you have to set the plot values for the secondary series from the BarsInProgress == 0 only and not from its own BarsInProgress.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Thanks for the reply JoyDeep,

      Surely, the indicator does not throw any errors in grammar. But when I load it on a chart, I only got arrows, no step lines that I expect (plots only upper step line of SMA when price is less then SMA value, and plots only lower step line when price is greater than SMA).

      Comment


        #4
        Already fixed it. Thank you !

        Comment


          #5
          Can you please post a solution. I think, I have the same problem.

          Comment


            #6
            For my case, there are several errors in the above code. Hope could be helpful to you.

            First, all "actions" are happening in the first time frame, so statements like "if (BarsInProgress==1)" are dispensable. What you take from other time frame is only values of different dataseries object.

            Second, input[0] reference to the first time frame only, there is no such thing like "inputs[1][0]". So, in this case the right grammar is Closes[x][x] or Highs[x][x] .

            Third, there is a logical error. The code,
            Code:
                                        if(swingNext==1)
            			    {
            				    if(previous_swingNext!=swingNext) 
            					{
            						DrawArrowUp(CurrentBar.ToString(),true, 0, LavgNext,   Color.SkyBlue);
            						NextBottom.Set(LavgNext);
            					}
            			    }
            should be replaced by
            Code:
                                       if(swingNext==1)
            			    {
            				 if(previous_swingNext!=swingNext) 
            					{
            						DrawArrowUp(CurrentBar.ToString(),true, 0, LavgNext,         Color.SkyBlue);                 }
                                             NextBottom.Set(LavgNext);					
            			    }
            So, if your code has no grammar error, and still does not plot, you may have to check the logic. In my case, it is the plotting conditions are not satisfied, the logic is untrue, so Ninja does nothing.

            Besides, for a multi-time frame indicator, you have to check that there are enough bars to calculate in every time frame. In this case, the following code should be added before you start your calculation.
            Code:
            if (CurrentBars[0] <= length+1 || CurrentBars[1] <= length+1 || CurrentBars[2] <= length+1) return;
            Last edited by wolfcuring; 11-21-2012, 05:29 AM.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bortz, 11-06-2023, 08:04 AM
            47 responses
            1,606 views
            0 likes
            Last Post aligator  
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            9 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            19 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            6 views
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            15 views
            0 likes
            Last Post Javierw.ok  
            Working...
            X