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

How to get value of stopOrder price?

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

    How to get value of stopOrder price?

    I am using unmanaged orders and want to find out where my current stopOrder is . How do i get the price of my currently stopOrder value?

    I want to compare and build a logic around where to place my stop orders.



    I have a long that executes:

    EnterLong(Convert.ToInt32(PositionSize), @"myLong L");




    This is where it places my stop and target orders:

    //////////////////////////////////////////////////////////////////////
    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {

    if (Position.MarketPosition == MarketPosition.Long)
    {
    // Stop-Loss order 4 ticks below our entry price
    stopOrder = ExitLongStopMarket(0, true, execution.Order.Filled, execution.Order.AverageFillPrice - StopLoss * TickSize, "myLong LSTOP", "myLong L");

    // Target order 8 ticks above our entry price
    targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AverageFillPrice + ProfitTarget * TickSize, "myLong T", "myLong L");
    }

    }


    ////////////////////////////////////////////////////////

    I want to change my stopOrder couple of times based on price.

    Then I want to move stop only if current stopOrder is lower then my expected price.


    I'm not sure what the exact syntax would be:


    if (Close[0] >= stopOrder.ToString.Value?? + 10 * TickSize) < --- is this right?
    {
    .
    .
    .
    }

    #2
    Hello priceisking,

    You can find the properties which an Order object has in the help guide here: https://ninjatrader.com/support/help...lightsub=order

    You can access the various prices your order may have with StopPrice and LimitPrice.

    Code:
    stopOrder.StopPrice
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you!!

      Comment


        #4
        If I use:

        SetStopLoss("MYLONG", CalculationMode.Price, currentTrail, false);

        How do I find out where the stop is currently? In the above example you gave works great in the Onexecutionupdate function, however, i want to use the setstoploss to modify it dynamically and when i do, i want to find out where it currently before moving it.


        Comment


          #5
          Hello priceisking,

          We have a sample of finding stoploss/profit target orders submitted with the Set methods in the following link. You basically just need to pay attention to the name shown in the control center orders tab for the order in question, for example a stop loss shows up as "Stop loss". Once you locate the order in OnOrderUpdate or OnExecutionUpdate you can store it to a variable and use its values.

          In your use case OnOrderUpdate would be needed to get the order while it is working.

          The linked sample makes use of a List to hold the orders and do comparisons for the purpose of that sample, you may just want to use a Order variable as shown in other samples involving OnExecutionUpdate.

          Code:
          Order myStop;



          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CortexZenUSA, Today, 12:53 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by CortexZenUSA, Today, 12:46 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by usazencortex, Today, 12:43 AM
          0 responses
          5 views
          0 likes
          Last Post usazencortex  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          168 responses
          2,265 views
          0 likes
          Last Post sidlercom80  
          Started by Barry Milan, Yesterday, 10:35 PM
          3 responses
          11 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X