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

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.
    The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()


    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.


    Please let us know if you need further assistance.
    Alan P.NinjaTrader 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
    12 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Working...
    X