Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exiting trade & entering (when it should be just exiting)?

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

    Exiting trade & entering (when it should be just exiting)?

    I have an indicator on my chart that will draw a line below the price to indicate a long trade, and then will flip above the price to indicate a short trade. This line is also used as a stop loss. I'm working on a simple strategy that would enter long if the bar closes up and opens above this indicator line, and would exit the trade once the bar closes below the indicator line (short trades would also be entered and exited the same way).

    When I run backtest, it's always in a trade, so instead of just exiting long, it's exiting long and entering short instantly, and vice versa the other direction. For example, when I look at my chart for an exit long, the bar closed below the indicator but it did not open below the indicator, so I'm not sure why it'd be entering short. Here's a sample of my code:

    Code:
    protected override void OnBarUpdate()
    {
    	// Condition set 1 - If bar open is above BCD line AND bar is green
    	if (Open[0] > BCDLine[0] && Close[0] > Open[0])
    	{
    		EnterLongLimit(DefaultQuantity, Close[0], "long");
    	}
    
    	// Condition set 2 - If close crosses below BCD line
    	if (Close[0] < BCDLine[0])
    	{
    		ExitLong("exit long", "long");
    	}
    
    	// Condition set 3 - If bar close is below BCD line AND bar is red
    	if (Open[0] < BCDLine[0] && Close[0] < Open[0])
    	{
    		EnterShortLimit(DefaultQuantity, Close[0], "short");
    	}
    
    	// Condition set 4 - If close crosses above BCD line
    	if (Close[0] > BCDLine[0])
    	{
    		ExitShort("exit short", "short");
    	}
    }
    I should mention that my bars are tall, so there should be a significant difference between the open and close in most cases. Any and all help is appreciated. Thanks!

    #2
    Hi GuySmiley, if you examine the case where this happened was the bar open anywhere near the reference line, so it could be potentially just giving the visual appearance that it did not fulfill the condition while if you were to print all associated vales for debug they would trigger it? That's what I would first look into to understand better - http://www.ninjatrader.com/support/f...ead.php?t=3418

    Also, in the managed mode your limit order placed would just expire if not filled in one bar. So if your condition is true for continuous bars you will resbumit an order until then a fill would be seen.
    BertrandNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Felix Reichert, 04-26-2024, 02:12 PM
    5 responses
    39 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by cmtjoancolmenero, 04-29-2024, 03:40 PM
    15 responses
    45 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by ETFVoyageur, Yesterday, 06:05 PM
    6 responses
    37 views
    0 likes
    Last Post ETFVoyageur  
    Started by rbeckmann05, Today, 02:35 PM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by Torontobluejays, Yesterday, 08:43 AM
    6 responses
    34 views
    0 likes
    Last Post rc5781
    by rc5781
     
    Working...
    X