Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Short side of strategy not behaving correctly

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

    Short side of strategy not behaving correctly

    Hi,

    I am having a problem with some code where the long exit strategy is working correctly but the short exit strategy is not.

    The problem with the short side is the trade is exited immediately after it is entered, is there anything I am missing here?

    I've just added the second exit strategy using or statement (myExecutionPrice) prior to this addition everything was working correctly.

    Here's my code;

    Code:
    // If we have a long position and the price is below offset for long (stop-loss) then immediately exit at market (code is in indicator)    
                if (Position.MarketPosition == MarketPosition.Long)
                {
                    if(this.CR(5, 4).TradePosition == 0 || lastPrice <= myExecutionPrice - (5 * TickSize))
                    {
    
                    // Checks to see if our Stop Order has been submitted already
                    //if (stopOrder != null)
                    //{
                        // Modifies stop-loss to an immediate exit 
                        stopOrder = ExitLong("long entry");
                    //}
                    }
                }
                
                // If we have a short position and the price is above offset for short (stop-loss) then immediately exit at market (code is in indicator)    
                if (Position.MarketPosition == MarketPosition.Short)
                {
                    if(this.CR(5, 4).TradePosition == 0 || lastPrice >= myExecutionPrice + (5 * TickSize))
                    {
    
                    // Checks to see if our Stop Order has been submitted already
                    //if (stopOrder != null)
                    //{
                        // Modifies stop-loss to an immediate exit 
                        stopOrder = ExitShort("short entry");
                    //}
                    }
                }
    Regards,
    suprsnipes

    #2
    suprsnipes, I would suggest to debug the order sequence you get with your changed script using the TraceOrders feature we have - http://www.ninjatrader.com/support/f...ead.php?t=3627

    In addition to that be sure to print when your short exit condition would exactly trigger -

    if(this.CR(5, 4).TradePosition == 0 || lastPrice >= myExecutionPrice + (5 * TickSize))

    As you sent then a market exit, so it must be triggering differently as you expected.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, Yesterday, 09:41 PM
    1 response
    27 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, Today, 02:41 AM
    0 responses
    10 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, Yesterday, 11:44 PM
    0 responses
    21 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    37 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    34 views
    0 likes
    Last Post CarlTrading  
    Working...
    X