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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    154 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    74 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    125 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    79 views
    0 likes
    Last Post PaulMohn  
    Working...
    X