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

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 arvidvanstaey, Today, 02:19 PM
      4 responses
      11 views
      0 likes
      Last Post arvidvanstaey  
      Started by samish18, 04-17-2024, 08:57 AM
      16 responses
      61 views
      0 likes
      Last Post samish18  
      Started by jordanq2, Today, 03:10 PM
      2 responses
      9 views
      0 likes
      Last Post jordanq2  
      Started by traderqz, Today, 12:06 AM
      10 responses
      18 views
      0 likes
      Last Post traderqz  
      Started by algospoke, 04-17-2024, 06:40 PM
      5 responses
      48 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X