Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Fixed dynamic profit target and stop loss orders in OnBarUpdate()

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

    Fixed dynamic profit target and stop loss orders in OnBarUpdate()

    My profit target and stop loss orders change with every setup since they are calculated using the highs and lows within the setup. I would like to use liveuntilcanceled entry orders, but need the profit and stop order amounts to be based on the original setup, not the new bars that have passed since the entry order was submitted but not filled.
    What's the best way to do this?

    Edit:Edit2: with every passing bar that the order is not filled-the exits change.
    How would I "record" the original exit values to be used later?
    Last edited by rdaoogle; 06-10-2014, 12:23 PM.

    #2
    Hello rdaoogle,

    Thanks for writing in.

    If you would like the entry price of the order to add or subtract ticks from you can use the Position AvgPrice or the IOrder handle's AvgFillPrice.

    For example:

    SetStopLoss(CalculationMode.Ticks, Position.AvgPrice + 5 * TickSize);

    Or if you have an IOrder called myOrder (or any name you would like).

    SetStopLoss(CalculationMode.Ticks, myOrder.AvgFillPrice + 5 * TickSize);

    You will want to make sure that the position is taken before using Position.AvgPrice (probably best to do in OnPositionUpdate() but you don't have too) and you will want to make sure that the order has filled before using myOrder.AvgFillPrice (best to do in OnExecution() but again not required).

    Below is a link to the help guide on Position.AvgPrice.
    http://www.ninjatrader.com/support/h...7/avgprice.htm

    And a link on IOrder.
    http://www.ninjatrader.com/support/h...nt7/iorder.htm
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    651 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    370 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    109 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    574 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    577 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X