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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      141 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      80 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      123 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      118 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      97 views
      0 likes
      Last Post CarlTrading  
      Working...
      X