• 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

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 Uwe1981, Today, 03:41 AM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_Kate  
      Started by 7robert, Today, 10:07 AM
      0 responses
      1 view
      0 likes
      Last Post 7robert
      by 7robert
       
      Started by emuns, Today, 09:36 AM
      1 response
      3 views
      0 likes
      Last Post NinjaTrader_PaulH  
      Started by lmatiukas, Today, 09:31 AM
      0 responses
      4 views
      0 likes
      Last Post lmatiukas  
      Started by Irukandji, Today, 09:09 AM
      3 responses
      9 views
      0 likes
      Last Post NinjaTrader_PatrickG  
      Working...
      X