Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is there an event related to ProfitTarget being hit?

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

    Is there an event related to ProfitTarget being hit?

    In my strategy, I set
    SetProfitTarget("", CalculationMode.Price, entryStopPrice + (entryStopPrice-Low[1]));
    SetStopLoss("", CalculationMode.Price, Low[1], false);
    How do I get to know that whether my profit target got hit? Is there an event telling me that? Or what is the best practice on this?

    Current I can only thinking of using if High[0]> MyTarget, then I know it is hit. But this is can obviously introduce error...

    #2
    Lookup these items:


    Code:
    protected override void OnPositionUpdate(IPosition position)
    {
    
    if (position.MarketPosition == MarketPosition.Flat)
    {
    	Print ( ToDay (Time[0]) + "," + ToTime(Time[0]) + ",ES," + "Flat"   );
    
    }
    else if (position.MarketPosition == MarketPosition.Long)
    {
    
    }
    else if (position.MarketPosition == MarketPosition.Short)
    {
    
    }

    Comment


      #3
      Hello leontancfa,

      Thank you for your inquiry.

      You would want to use Close[0] and not High[0]. High[0] would return the high value of the current bar and not the current price of the bar.

      You could do Close[0] >= myTarget to check if you hit the target or went above the target, but this necessarily won't mean that the target has filled.

      If you would like to check if the target was filled, you would have to use the OnExecution() method. You can read more about this in the NinjaTrader help guide at this link: http://ninjatrader.com/support/helpG...nexecution.htm

      Here's an example of what you could do:
      Code:
      protected override void OnExecution(IExecution execution)
      {
           if (execution.Order != null && execution.Name == "Profit target" && execution.Order.OrderState == OrderState.Filled)
           {
                Print("Target filled!");
           }
      }
      Please note, however, that programming to this method is considered advanced programming and exposed for experienced programmers.

      Please, let us know if we may be of further assistance.
      Zachary G.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

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