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 Gerik, Today, 09:40 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by RookieTrader, Today, 09:37 AM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by alifarahani, Today, 09:40 AM
    0 responses
    5 views
    0 likes
    Last Post alifarahani  
    Started by KennyK, 05-29-2017, 02:02 AM
    3 responses
    1,284 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by AttiM, 02-14-2024, 05:20 PM
    11 responses
    185 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X