Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trigger after multiple UP / DOWN in a row in indicator

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

    Trigger after multiple UP / DOWN in a row in indicator

    I have an issue very similar to the one described and solved in the thread below.
    http://www.ninjatrader.com/support/f...ghlight=period

    The code below is a little modified from the thread but fits more of what I want.

    Code:
            
    protected override void OnBarUpdate()
            {
                // Condition set 1
            		int count = 0;
    					for(int i = period - 1; i >= 0; i--)
    					{
    						if(Close[i] >= Close[i+1])
    						{
    							count++;
    						}
    					}
    					if(count == period)
    					{
    						DrawArrowDown("My down arrow" + CurrentBar, false, 0, High[1] + 3 * TickSize, Color.Red);
    						Print("Entered Long");
    						EnterLong(1, "Long 1");
    					}
    					
            }
    The code on this is great but I want the trigger to enter or exit trades to be based on my indicator and not on the price of the instrument. How would I swap out the "i" integer for the value of an indicator? I'm using the MACD and would like to enter a trade after 5 MACD increases in a row.

    #2
    Hello BReal,

    Thank you for your post.

    The code would be the following for long:
    Code:
    			int count = 0;
    			for(int i = period; i >= 0; i--)
    			{
    				if(MACD(12, 26, 9)[i] > MACD(12, 26, 9)[i+1])
    					count++;
    			}
    			if(count == period)
    			{
    				EnterLong();
    			}

    Comment


      #3
      Works great! Thanks!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      639 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      366 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      107 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      569 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      572 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X