Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JesseNinjaTrader Customer Service

    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 kaywai, 09-01-2023, 08:44 PM
      5 responses
      601 views
      0 likes
      Last Post NinjaTrader_Jason  
      Started by xiinteractive, 04-09-2024, 08:08 AM
      6 responses
      22 views
      0 likes
      Last Post xiinteractive  
      Started by Pattontje, Yesterday, 02:10 PM
      2 responses
      19 views
      0 likes
      Last Post Pattontje  
      Started by flybuzz, 04-21-2024, 04:07 PM
      17 responses
      230 views
      0 likes
      Last Post TradingLoss  
      Started by agclub, 04-21-2024, 08:57 PM
      3 responses
      17 views
      0 likes
      Last Post TradingLoss  
      Working...
      X