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

When stoploss is filled strategy still thinks it has a position

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

    When stoploss is filled strategy still thinks it has a position

    Hi, I have noticed that when a stoploss is hit and filled the strategy is not synching its position to the account position (which would now be flat) and continues to think it has a position. I am using ExitLongStopMarket for the stoploss. How can I get it to know that if the stop gets hit, it is in fact now flat?
    Thanks

    #2
    Hello RaygunWizzle,

    Thank you for your post.

    I suggest reviewing the information about strategy position vs. account position here:


    The positions only check for a sync when enabling a strategy, depending on the start behavior selected, or if you right-click the Strategies tab and select Synchronize All Positions. Syncing account positions is described here:


    After the stop loss is hit, what do you see on the Strategies tab for the strategy position and for the account position? Where are you seeing that the strategy continues to think it has a position? What is your logic for ExitLongStopMarket()? Is this a position with multiple contracts, and if so does the quantity for your exit order match the quantity that was entered?

    I look forward to your reply.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      So the account will be flat but the strategy will think it still has a position. I am seeing this in the strategies tab, it will show it as having a position and continue showing the theoretical Unrealized. My logic for the stop exits looks like this, and you can see it constantly updates to Position.Quantity:

      protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
      {
      if (execution.Order.OrderState == OrderState.Filled && execution.MarketPosition == MarketPosition.Long)
      {
      if (currentStop == 0)
      {
      ExitLongStopMarket(0, true, Position.Quantity, (Position.AveragePrice - 140), "PositionStop", "");
      }
      else if (currentStop > 0)
      {
      ExitLongStopMarket(0, true, Position.Quantity, currentStop, "PositionStop", "");
      }
      }
      if (execution.Order.OrderState == OrderState.Filled && execution.MarketPosition == MarketPosition.Long && execution.Order.Name == "PositionStop")
      {
      EnterLong(1, "");
      }
      }
      protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string comment)
      {
      if (order.OrderType == OrderType.StopMarket && order.OrderState == OrderState.Accepted)
      currentStop = order.StopPrice;
      }​

      Comment


        #4
        Oh and that EnterLong bit was an attempt at getting it to restart after the stop filling but that doesnt seem to be working either.

        Comment


          #5
          Hello RaygunWizzle,

          Thank you for your reply.

          Please add print statements and enable TraceOrders in your strategy so you may better understand its behavior and narrow down which parts of your logic are being hit and causing the unexpected long strategy position. We have a guide to using these tools for debugging here:


          If you are unsure of the meaning of the output, please feel free to share it by right-clicking the NinjaScript Output window and selecting Save As. This will create a text file that you may attach to your reply here with any additional questions you have.

          Please let us know if we may be of further assistance.
          Emily C.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by rhyminkevin, Today, 04:58 PM
          1 response
          31 views
          0 likes
          Last Post Anfedport  
          Started by iceman2018, Today, 05:07 PM
          0 responses
          4 views
          0 likes
          Last Post iceman2018  
          Started by lightsun47, Today, 03:51 PM
          0 responses
          7 views
          0 likes
          Last Post lightsun47  
          Started by 00nevest, Today, 02:27 PM
          1 response
          14 views
          0 likes
          Last Post 00nevest  
          Started by futtrader, 04-21-2024, 01:50 AM
          4 responses
          49 views
          0 likes
          Last Post futtrader  
          Working...
          X