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

SetStopLoss/SetProfitTarget w/ CalculationMode.Currency Multi-Entry Problems

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

    SetStopLoss/SetProfitTarget w/ CalculationMode.Currency Multi-Entry Problems

    Hello,

    I have a strategy (see attached file) with 2 different entry signal names, and my goal is to use "SetStopLoss" and "SetProfitTarget" with CalculationMode.Currency as the mode parameter to set stop losses and profit targets for both entries, using different values for each. For instance, for the entry named "LE1", I want to gain/lose $400, but for the entry named "LE2", I want to gain/lose $1,000.

    I added the following lines of code were added to the proper places in the "OnStateChange()" section:

    // In "if (State == State.SetDefaults)" section
    Code:
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    EntryHandling = EntryHandling.UniqueEntries;
    // In "else if (State == State.Configure)" section
    SetStopLoss("LE1", CalculationMode.Currency, 400, false);
    SetStopLoss("LE2", CalculationMode.Currency, 1000, false);

    SetProfitTarget("LE1", CalculationMode.Currency, 400, false);
    SetProfitTarget("LE2", CalculationMode.Currency, 1000, false);

    When I try running the attached strategy, two problems occur:

    Problem #1: The NT8 Log has a message that reads "Stop/target handling set to 'By strategy position' since currency based stop order was placed."

    Problem #2: When both positions (one for each entry) are open at the same time, the stop loss or profit target that gets filled first in fact behaves in a way consistent with the message described in "Problem #1", in that instead of gaining/losing $400 for the position on which I set the stop loss and profit target to $400, it exits with a gain/loss of only $200, because presumably it sees that the two positions together are up/down $400. Note that the single remaining position does exit with the full $1,000 loss/gain.

    Is this problem by design, or is it a bug that needs to be fixed?

    You should be able to reproduce this issue by running the attached file on SPY.

    Thank you very much,

    EquityTrader
    Attached Files

    #2
    Hello EquityTrader,

    Thanks for opening the thread.

    The message that you received is a deliberate message from the platform notifying you that it has taken an action to change the Stop/Target Handling based on how the Strategy was written. It is an expected message/behavior and is not a bug. The strategy will have to be tailored to using StopTargetHandling.ByStrategyPosition.

    You could use the order quantity as a modifier to set the Profit Target and Stop Loss in proportion to the position that the entry takes up in the strategy. For example, if one entry uses 1/3 of the contracts used in the strategy position, you can multiply the currency value by 3 to have it represent the currency in relation to the portion of the position taken.

    I would advise to use reference the Quantity and MarketPosition of the Strategy's Position as well as submitting your orders to Orders objects so you can accurately keep track of the quantity the Order takes for the strategy's position. I would also suggest to use dynamic Profit Targets and Stop Losses for more flexibility.

    The SampleOnOrderUpdate strategy also provides a good demonstartion for using Order objects.

    Position - http://ninjatrader.com/support/helpG...s/position.htm

    Order - http://ninjatrader.com/support/helpG...n-us/order.htm

    SetProfitTarget() (See dynamic under Tips) - http://ninjatrader.com/support/helpG...ofittarget.htm

    SampleOnOrderUpdate() - http://ninjatrader.com/support/forum...ead.php?t=7499

    Please let me know if I may be of further help.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hello NinjaTrader_Jim,

      Thanks for the detailed response. I understand. I will work around this behavior.

      Thanks again,

      EquityTrader

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by RookieTrader, Today, 09:37 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by alifarahani, Today, 09:40 AM
      0 responses
      4 views
      0 likes
      Last Post alifarahani  
      Started by Gerik, Today, 09:40 AM
      0 responses
      4 views
      0 likes
      Last Post Gerik
      by Gerik
       
      Started by KennyK, 05-29-2017, 02:02 AM
      3 responses
      1,283 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by AttiM, 02-14-2024, 05:20 PM
      11 responses
      185 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X