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

OrderMethod/Onexecution

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

    OrderMethod/Onexecution

    Hey guys, when you meet a profit target in a trade using the statement, SetProfitTarget("Long 1a", CalculationMode.Ticks, profitVar);

    Lets say I want to change certain variables in the Onexecution method when the "Long 1a" trade meets its profit target and is sold, how do I know which position was sold in OnExecution?

    #region OrderMethod
    protected override void OnExecution(IExecution execution)

    #2
    You can call SetProfitTarget() throughout OnBarUpdate() to change the values used without needing OnExecution.

    When using OnExecution to track orders you would likely want to use IOrders to manage your position as opposed to calling the SetProfitTarget() method.

    That being said this is possible to call SetProfitTarget() from OnExecution()

    For an example of determining which order called OnExecution please see: http://www.ninjatrader.com/support/f...ead.php?t=7499
    LanceNinjaTrader Customer Service

    Comment


      #3
      Hi, thanks for the info, but when I use SetProfitTarget like

      SetProfitTarget("Long 1a", CalculationMode.Ticks, profit1);

      entryOrder1 = EnterLong(0, DefaultQuantity, "Long 1a");

      protected override void OnExecution(IExecution execution)
      {
      if(entryOrder1 != null)

      entryOrder1 comes up as NULL here for some reason, not sure why?

      Comment


        #4
        Do you have a sample script that replicates the error.

        It is possible OnExecution would get called when the entry order is null but this would depend on your logic. In otherwords you could be setting it to null somewhere else or a different order could be calling OnExecution
        LanceNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by helpwanted, Today, 03:06 AM
        0 responses
        3 views
        0 likes
        Last Post helpwanted  
        Started by Brevo, Today, 01:45 AM
        0 responses
        7 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        5 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        242 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        384 views
        1 like
        Last Post Gavini
        by Gavini
         
        Working...
        X