• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Count Down Counter Problems

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

    Count Down Counter Problems

    I am working on an indicator to count up bars and down bars. I implemented a counter to accomplish this, and I have never used that capability before. The indicator compiles and plots properly. I then built a strategy to use that indicator and it also compiles just fine. However, every time I put the strategy on a chart it blows up NT. I am suspicious of the counter portion, only because I've never done one before and perhaps I am doing something silly like dividing by zero. Here is the countdown counter code and associated code:

    Code:
    		protected override void OnBarUpdate()
    		{
    			if(CurrentBar <= Period)
    			{
    //				bar_Count.Set(0);
    //				up_Bar_Count.Set(0);
    //				dn_Bar_Count.Set(0);
    				return;
    			}
    		for (int x = Count_Length; x > 0; x--)
    		{
    			if( x == Count_Length)
    				{
    				bar_Count.Set(0);
    				up_Bar_Count.Set(0);
    				dn_Bar_Count.Set(0);				
    				}
    			
    			else if (Close[Count_Length] >= Open[Count_Length] )
    			{
    				bar_Count.Set(bar_Count[1] + 1) ;
    //				up_Bar_Count.Set(up_Bar_Count[1] + 1);
    				
    			}
    			
    			else if (Close[Count_Length] < Open [Count_Length] )
    			{
    				bar_Count.Set(bar_Count[1] - 1) ;
    //				dn_Bar_Count.Set(dn_Bar_Count[1] + 1);
    			}
    			
    		}
    //			double ratio = up_Bar_Count[0] / dn_Bar_Count[0];
    
    
    				
    				UpDnBarCount.Set(bar_Count[0] );
    				Max_Ratio.Set((MAX(UpDnBarCount, Period)[0]));
    				Min_Ratio.Set((MIN(UpDnBarCount, Period)[0]));
    				Avg_Count.Set(EMA(UpDnBarCount, Period)[0]);
    			
    		if (Prnt_Values)
    				{
    				Print(CurrentBar + "  Bar Count   " + Instrument.FullName + " is " + UpDnBarCount);	
    //				Print (CurrentBar + "  Average True Range for  " + Instrument.FullName + " is " + Value[0]);
    				}
    The section in red is the counter code. The rest is me counting whether the bar is up or down and then incrementing or decrementing the bar count variable to add or subtract a 1 based on whether the bar was up or down. Am I doing something obviously wrong with the counter? Why would it compile and run as an indicator but blow up a strategy even though the code compiles?
    Thanks
    DaveN

    #2
    Hello DaveN,
    To assist you further can you please send a toy NinjaScript code* (the cs file of both the strategy and the indicator or use the Export feature to export the strategy) replicating the behavior to support[AT]ninjatrader[DOT]com

    Please append Attn:Joydeep in the subject line of the email and give a reference of this thread in the body of the email.

    I look forward to assisting you further.

    *The "toy" just means something that is a stripped down version that isn't necessarily the whole logic. It makes things easier to rout out.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      For some reason I can't send my files to you through my e-mail. I will keep trying but it seems that my Outlook instance is broken for the moment.
      DaveN

      Comment


        #4
        DaveN,

        We received your files this morning and will be following up shortly

        Thanks.
        MatthewNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ksarin, Today, 12:39 PM
        3 responses
        11 views
        0 likes
        Last Post NinjaTrader_PatrickG  
        Started by ttodua, Today, 12:03 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by tomtr27, Today, 11:35 AM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Uregon, Today, 07:30 AM
        2 responses
        13 views
        0 likes
        Last Post bltdavid  
        Started by Induna, 02-20-2020, 05:38 AM
        4 responses
        26 views
        0 likes
        Last Post NinjaTrader_Kate  
        Working...
        X