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 judysamnt7, 03-13-2023, 09:11 AM
      4 responses
      59 views
      0 likes
      Last Post DynamicTest  
      Started by ScottWalsh, Today, 06:52 PM
      4 responses
      36 views
      0 likes
      Last Post ScottWalsh  
      Started by olisav57, Today, 07:39 PM
      0 responses
      7 views
      0 likes
      Last Post olisav57  
      Started by trilliantrader, Today, 03:01 PM
      2 responses
      21 views
      0 likes
      Last Post helpwanted  
      Started by cre8able, Today, 07:24 PM
      0 responses
      10 views
      0 likes
      Last Post cre8able  
      Working...
      X