Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Check if my last StopLoss is from a Long/Short position

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

    Check if my last StopLoss is from a Long/Short position

    How do I check if my last StopLoss is from a Long/Short position?

    This is my Stop Loss function:
    Code:
    // ************ Stop Loss *****************************
    
                if     (
                    Profit <= -StopLoss
                    )                             
                {                        
                    ExitLong(Position.Quantity,"StopLoss(Long)","EnterLong");    
                    ExitShort(Position.Quantity,"StopLoss(Short)","EnterShort");    
                }
    I would like to

    if (LastExit == StopLoss(Long))
    EnterShort

    if(LastExit == StopLoss(Short))
    EnterLong

    Thank you!

    #2
    Hello johnnybegoode,

    The most simple way would be to use OnExecutionUpdate and look for Filled orders. When you locate an order with one of the names you supplied you could set a variable to the direction order that was.



    Code:
    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
      if(execution.Order.Name == "StopLoss(Long)")
      {
          //set a variable or do an action, last stop loss was long 
      }
      Print(execution.ToString());
    }
    I look forward to being of further assistance.

    Comment


      #3
      ...or, set an int to 1 when entering a long or -1 when going short. Check that number when exiting at a stop loss. After exit reset to 0;
      eDanny
      NinjaTrader Ecosystem Vendor - Integrity Traders

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      50 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      126 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      69 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X