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