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

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 llanqui, Today, 03:53 AM
    0 responses
    6 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    10 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    15 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Yesterday, 08:42 PM
    0 responses
    11 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Yesterday, 07:51 PM
    0 responses
    14 views
    0 likes
    Last Post strategist007  
    Working...
    X