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

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;
    			}
    [COLOR="Red"]		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);
    			}
    			
    		}[/COLOR]
    //			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 algospoke, Yesterday, 06:40 PM
        2 responses
        23 views
        0 likes
        Last Post algospoke  
        Started by ghoul, Today, 06:02 PM
        3 responses
        14 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        45 views
        0 likes
        Last Post jeronymite  
        Started by Barry Milan, Yesterday, 10:35 PM
        7 responses
        22 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by AttiM, 02-14-2024, 05:20 PM
        10 responses
        181 views
        0 likes
        Last Post jeronymite  
        Working...
        X