Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetProfitTarget and SetStopLoss - need event listeners?

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

    SetProfitTarget and SetStopLoss - need event listeners?

    Hi, I've been working on a strategy for a few weeks now and I've made it this far with all the great posts and documentation, but today I have met my match! I need the ability to execute code when either my SetProfitTarget or SetStopLoss have been triggered. I've looked into methods such as OnOrderUpdate() and OnPositionUpdate() but SetProfitTarget and SetProfitTarget don't seem to work with iOrder...? Basically I need an eventListener that executes when the target or stop has been met. How can this be done

    Thanks!

    #2
    Originally posted by 4dplane View Post
    Hi, I've been working on a strategy for a few weeks now and I've made it this far with all the great posts and documentation, but today I have met my match! I need the ability to execute code when either my SetProfitTarget or SetStopLoss have been triggered. I've looked into methods such as OnOrderUpdate() and OnPositionUpdate() but SetProfitTarget and SetProfitTarget don't seem to work with iOrder...? Basically I need an eventListener that executes when the target or stop has been met. How can this be done

    Thanks!
    There is sample code for that available right in this forum.

    ref: http://www.ninjatrader.com/support/f...ead.php?t=5790

    Comment


      #3
      Thank you very much! Sorry I missed the list of sample code, I had seen it a few weeks back and did a search but overlooked it.

      I ended up using this for my current control of ProfitTarget and StopLoss:

      Code:
       protected override void OnOrderUpdate(IOrder order){
                  //If Profit Target was met-------------------
                  if (order.OrderState == OrderState.Filled){
                      if(order.Name == "Profit target"){
                          Print(order.ToString());
                      }
                  }
                  //If stop loss was met-----------------------
                  if (order.OrderState == OrderState.Filled){
                      if(order.Name == "Stop loss"){
                          Print(order.ToString());
                      }
                  }
              }

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Perr0Grande, Yesterday, 08:16 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by f.saeidi, Yesterday, 08:12 AM
      3 responses
      24 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by algospoke, Yesterday, 06:40 PM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by quantismo, Yesterday, 05:13 PM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by The_Sec, 04-16-2024, 02:29 PM
      3 responses
      16 views
      0 likes
      Last Post NinjaTrader_ChristopherS  
      Working...
      X