• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnBarUpdate, OnOrderUpdate, and setting Target Price

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

    OnBarUpdate, OnOrderUpdate, and setting Target Price

    I have been trying to set up my strategy so that my target price is calculated from the price I enter the trade at. I don't want to enter a generic amount for every trade; I plan to calculate my target based on specific trade types so I want to know the best way to do so dynamically, as well as how I can update these orders later on. If I'm not mistaken, submitting two profit targets is submitting two separate orders.

    So for now I've overrided OnOrderUpdate, which provides me with averageFillPrice, and the method I used was as follows:

    in onOrderUpdate:

    if (orderState == OrderState.Filled) {
    entry_price = averageFillPrice;
    }

    So in onBarUpdate, I had put something like:

    takeLong();
    setProfitTarget(entry_price + 4);
    setStopLoss(entry_price - 4);


    From this I notice one issue and I have one question as well.
    When I call the function to take the long, will that function complete, then call onOrderUpdate, and THEN call setProfitTarget? It seems that when my code is executed, the entry_price variable is not updated to the most recent price. Instead, it uses the previous trade's prices. And if I put setProfitTarget above takeLong, the orderState won't be filled, and so that doesn't work either. I'm sure there's an easier way to do this, so if someone knows it I'd appreciate the help!

    Thanks!
    Last edited by gredenko; 07-14-2018, 09:50 PM.

    #2
    Hello gredenko,

    Thank you for your note.

    The following example demonstrates how to submit profit target and stop loss orders from OnExecution, which would work in your case as the execution would contain your fill price.
    https://ninjatrader.com/support/foru...ead.php?t=7499

    The example below demonstrates how to reset your stop/target calls when flat to prevent them from using previous price should you wish to use the SetProfitTarget SetStopLoss Methods.
    https://ninjatrader.com/support/foru...ead.php?t=3222

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by abfefmu, Today, 05:33 AM
    0 responses
    1 view
    0 likes
    Last Post abfefmu
    by abfefmu
     
    Started by bbdjad, Today, 04:36 AM
    0 responses
    4 views
    0 likes
    Last Post bbdjad
    by bbdjad
     
    Started by mittie3, Today, 03:33 AM
    0 responses
    7 views
    0 likes
    Last Post mittie3
    by mittie3
     
    Started by Againmain1, Today, 03:04 AM
    0 responses
    8 views
    0 likes
    Last Post Againmain1  
    Started by tonytimpa, Today, 01:33 AM
    0 responses
    5 views
    0 likes
    Last Post tonytimpa  
    Working...
    X