NexusFi: Find Your Edge


Home Menu

 





Counter crossing the horizontal line


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one doitagaitforme with 7 posts (0 thanks)
    2. looks_two anachronist with 4 posts (6 thanks)
    3. looks_3 Big Mike with 1 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 4,973 views
    2. thumb_up 6 thanks given
    3. group 2 followers
    1. forum 12 posts
    2. attach_file 0 attachments




 
Search this Thread

Counter crossing the horizontal line

  #11 (permalink)
 doitagaitforme 
Rostov-na-Donu/ Russia
 
Experience: Beginner
Platform: Metatrader
Posts: 17 since Jul 2010
Thanks Given: 8
Thanks Received: 4

Hi anachronist. At this point, your code I transformed as follows:

 
Code
 protected override void OnBarUpdate()
        {
        
			if (CurrentBar == 0) return;
   			linedata ld = new linedata();
   			ld.id = "ld"+CurrentBar.ToString();
   			ld.startbar = CurrentBar-1;
   			ld.value = Close[1];
   			ld.count = 0;
   			lines.Add(ld);
   			foreach(linedata id in lines) {
      		        if (ld.value >= Low[0] && ld.value <= High[0])
         	       ++ld.count;
      		       if (ld.count <= 3)
         	
			DrawLine(ld.id, false, CurrentBar-ld.startbar, ld.value, -90000, ld.value, Color.Red, DashStyle.Solid, 1);
     			 else
         			lines.RemoveAll(ld); // don't need to track this line anymore 
				
					
   }

I can not understand what the problem is the last line after "else" (CS1502 and CS1503). I tried to replace lines.RemoveAll(ld) in lines.Remove(ld). The indicator is compiled, but when you add the indicator ninja crash.

I have it compiled without any conditions "else". The lines ended on the next bar. So I changed to zero -90 000, so they went further to the right.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
Cheap historycal L1 data for stocks
Stocks and ETFs
ZombieSqueeze
Platforms and Indicators
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
REcommedations for programming help
Sierra Chart
 
  #12 (permalink)
 
anachronist's Avatar
 anachronist 
San Jose, CA
 
Experience: Advanced
Platform: NinjaTrader
Trading: all
Posts: 27 since Apr 2012
Thanks Given: 0
Thanks Received: 16

OK, here's what I came up with, now that I got a chance to test it myself.

Warning, if you try to run this on too much data, NinjaTrader will appear to freeze up, because it adds a new line on every single bar (each new close). I'd keep it under 1000 bars.
 
Code
                            
#region Using declarations
// add this
using System.Collections.Generic// needed for List class
#endregion

//...

        #region Variables
        // parameters
        
private int maxcount 3// Default setting for Count
        // other
        
private class linedata {
            public 
string id;
            public 
int countstartbar;
            public 
double value;
            public 
linedata(int currentbardouble val) {
                
id "ln"+currentbar.ToString();
                
startbar currentbar 1;
                
value val;
                
count 0;
            }
        }
        private List<
linedatalinesto_remove;
        
#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()
        {
            
lines = new List<linedata>();
            
to_remove = new List<linedata>();
            
Overlay true;
            
CalculateOnBarClose true;
        }

        
/// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        
protected override void OnBarUpdate()
        {
            if (
CurrentBar == 0) return;
            
lines.Add(new linedata(CurrentBarClose[1]));
            
to_remove.Clear();
            foreach(
linedata d in lines) {
                if (
d.value >= Low[0] && d.value <= High[0])
                    ++
d.count;
                if (
d.count <= maxcount)
                    
DrawLine(d.idfalseCurrentBar-d.startbard.value0d.valueColor.RedDashStyle.Solid1);
                if (
d.count >= maxcount// we can stop extending this line
                    
to_remove.Add(d);    // add line to removal queue
            
}
            foreach(
linedata d in to_remove// empty the removal queue
                
lines.Remove(d);
        } 
I suspected that there might be a problem with removing elements from a list during a loop traversing that same list, so instead I collected the elements to remove in another list for cleanup outside the first loop.

And here's a picture:

Reply With Quote
  #13 (permalink)
 doitagaitforme 
Rostov-na-Donu/ Russia
 
Experience: Beginner
Platform: Metatrader
Posts: 17 since Jul 2010
Thanks Given: 8
Thanks Received: 4


but will arrive with you the eternal profit

Started this thread Reply With Quote




Last Updated on May 3, 2012


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts