• 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 cirzonorkecv, Yesterday, 11:52 PM
      0 responses
      6 views
      0 likes
      Last Post cirzonorkecv  
      Started by rickyblah12, Yesterday, 01:01 PM
      1 response
      14 views
      0 likes
      Last Post Erwin Beckers  
      Started by dadarara, Yesterday, 12:18 PM
      0 responses
      8 views
      0 likes
      Last Post dadarara  
      Started by joemiller, Yesterday, 07:33 AM
      2 responses
      13 views
      0 likes
      Last Post joemiller  
      Started by TheGameOfProbabilities, 07-18-2019, 06:56 AM
      7 responses
      38 views
      0 likes
      Last Post DaveS
      by DaveS
       
      Working...
      X