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

Negative values in SetStopLoss by Currency?

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

    Negative values in SetStopLoss by Currency?



    Should SetStopLoss by Currency always be a positive value, or can it be set to a negative or positive value?

    Say my current unrealized gain is $30. I want to set a stop loss at -$20, or $50 from my current realized gain. Would the proper statement then be:

    SetStopLoss(CalculationMode.Currency, -20);


    Or, say I want to set an initial stop loss at -$20 from entry price. Then, after a gain, I want to reset to +$20 from entry price. Would this be:

    SetStopLoss(CalculationMode.Currency, -20);
    SetStopLoss(CalculationMode.Currency, 20);

    The reference code uses only a positive value, so I'm unsure how to use currency to specify the -$20/$20 case.

    How to do? Thanks,





    Last edited by timmbbo; 03-14-2024, 05:56 PM.

    #2
    Hello timmbbo,

    Thank you for your post.

    When using Currency for the calculation mode, it must be a positive number. if you put 20, then the stop loss will be placed at a value of $20 PnL away from the average entry price. If it is for a long entry, the stop loss will be placed below the entry price and if it is for a short entry, the stop loss will be placed above the entry price. There is no need to specify positive or negative, as the platform will know which side of the market to place the stop loss.

    On the following page, Currency is described as, "PnL away from average entry. Calculated by the dollar per tick value for the order quantity used. When this mode is used, StopTargetHandling will automatically be set to ByStrategyPosition"


    Please test out SetStopLoss() with the calculation mode set to currency and observe the behavior. It can be most simple to test in the Playback Connection as you can observe the real-time behavior and manipulate the playback time/speed as needed:


    Please let us know if we may be of further assistance.

    Emily C.NinjaTrader Customer Service

    Comment


      #3

      Emily, thanks. Given this, it seems like one can not use currency to reset to use for trailing stops. Say I do

      EnterProfitTarget(Current, $100)
      EnterStopLoss(Currency, $20)
      EnterLong()

      After I enter long, I have an unrealized gain of $40. Now, I want to set my stop loss to +$30, to protect my gain. Since I've entered long, EnterStopLoss by Currency will always set the stop loss under the entry price. There's no method to use EnterStopLoss/Currency to set the stop loss above the entry price.

      Therefore, it would seem like EnterStopLoss / Currency can not be used to implemented trailing stops, correct?




      Comment


        #4
        Originally posted by timmbbo View Post
        Emily, thanks. Given this, it seems like one can not use currency to reset to use for trailing stops. Say I do

        EnterProfitTarget(Current, $100)
        EnterStopLoss(Currency, $20)
        EnterLong()

        After I enter long, I have an unrealized gain of $40. Now, I want to set my stop loss to +$30, to protect my gain. Since I've entered long, EnterStopLoss by Currency will always set the stop loss under the entry price. There's no method to use EnterStopLoss/Currency to set the stop loss above the entry price.

        Therefore, it would seem like EnterStopLoss / Currency can not be used to implemented trailing stops, correct?
        You can use SetStopLoss() with a Currency calculation mode for the initial stop loss value, though if you would like to have it trail later on you would likely need to use SetStopLoss() dynamically with the Price calculation mode. If you know the dollar per tick value for the instrument being traded, you could set the stop loss to +$30 by setting it to a Price of Position.AveragePrice + ___ * TickSize, with the underscore being however many ticks in profit you would like to move the stop loss to. For an example of modifying stop and target orders, please see this strategy:


        Please let us know if we may be of further assistance.
        Emily C.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by llanqui, Today, 03:53 AM
        0 responses
        1 view
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by burtoninlondon, Today, 12:38 AM
        0 responses
        10 views
        0 likes
        Last Post burtoninlondon  
        Started by AaronKoRn, Yesterday, 09:49 PM
        0 responses
        14 views
        0 likes
        Last Post AaronKoRn  
        Started by carnitron, Yesterday, 08:42 PM
        0 responses
        11 views
        0 likes
        Last Post carnitron  
        Started by strategist007, Yesterday, 07:51 PM
        0 responses
        14 views
        0 likes
        Last Post strategist007  
        Working...
        X