Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing original stop loss value

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

    Accessing original stop loss value

    If a strategy enters a trade using EnterLong or EnterStop, having previously called SetStopLoss and SetProfit target, then the stop loss and profit target orders are generated automatically. Shouldn't I then be able to access information about the order from OnExecution? The following code prints out "Original stop loss is 0". Can you tell me what I am doing wrong please? (Complete code attached)

    protectedoverridevoid OnBarUpdate()
    {
    if (CrossAbove(SMA(fast), SMA(slow), 1))
    {
    entryOrder = EnterLong(DefaultQuantity,
    "LongEntry");
    Print(
    "Entered long");
    }
    elseif (CrossBelow(SMA(fast), SMA(slow), 1))
    {
    entryOrder = EnterShort(DefaultQuantity,
    "ShortEntry");
    Print(
    "Entered short");
    }
    }

    protectedoverridevoid OnExecution(IExecution execution)
    {
    if (entryOrder != null && entryOrder.Token == execution.Order.Token)
    {
    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
    {
    origStopPrice = execution.Order.StopPrice;
    Print(
    "Original stop price is " + origStopPrice.ToString());
    }
    }
    }
    Attached Files

    #2
    annettes,

    Set() methods do not come with IOrder objects. What you are doing is you are setting the Entry order to the entryOrder IOrder object, not the stop/targets. In your OnExecution() you are then filtering for entryOrder which would definitely not pick up the SetStopLoss() order.

    If you want to monitor the SetStopLoss() order, please see this reference sample: http://www.ninjatrader.com/support/f...ead.php?t=5790
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh. That reference sample was very helpful. But one thing I am still not clear on is how to know which stop loss/profit target order is linked to which buy/sell order. I guess the FromEntrySignal field of IOrder gives some indication, but there can be multiple orders with the same FromEntrySignal value.

      I should add that what I am untilmately trying to do is this: each time the trade moves a further 50 pips into profit, I want to move my stop by 50 pips. I have looked at the code sample titled SamplePriceModification.cs, but it only moves the stop loss once. I may want to move it multiple times as the profit increases, so need to be able to find either the current or original value of the stop loss.
      Last edited by annettes; 09-12-2010, 10:56 PM. Reason: Additional information

      Comment


        #4
        You would then not neccessarily need to go down the IOrder route, you know your entryPrice and first stoploss value and from there you can for example save the modified stop value to a variable after each change based on open profit for exmaple.

        Comment


          #5
          That would only work if I had only one trade open at a time. I would like to be able to code for a more general situation and I would still like to know how to determine which profit target/stop loss order is associated with which buy/sell order for other reasons.
          Thanks.

          Comment


            #6
            Then you would need to go with the IOrder management suggestions, as you can access the order.FromEntrySignal property then.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            639 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            366 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            107 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            569 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            572 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X