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 Question

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

    SetStopLoss Question

    I'm trying to create a SetStopLoss that will place the stop loss at the low of the previous bar minus 2 pips. My entry name is called L1.

    SetStopLoss("L1", CalculationMode.Price, Low[1]-2*TickSize, true);

    This is what I came up with but it seems not to be working when a place the strategy on the chart or the backtester. Thanks for any help.

    #2
    SetStopLoss() is a method that submits a stop loss triggered by the incoming fills of an order. Therefore, its called before any position is open.

    There are many approaches to get done what you want but it depends on several variables. First one is, are you entering "L1" using a market order?

    If yes, you can add the line as you shown in your post one line before your EnterLong() or EnterShort() call. This should do the trick.
    RayNinjaTrader Customer Service

    Comment


      #3
      Thank you, that works good. I was wondering if i can enter a EMA stop loss instead of a Low[1]-2*ticksize. The ema would follow the ema after each new bar. Do i have to enter a bar update code to have the stop loss follow the EMA?

      Comment


        #4
        Your understanding is correct. A few hints -

        - When long, make sure the EMA value is less than the current bid, current ask when short...otherwise you can get rejected orders since the price may be invalid

        - Yes, you have to update the price on each new OnBarUpdate() and pass in the new EMA value ... SetStopLoss("L1", CalculationMode.Price, EMA(20)[0], true);

        - Make sure that the above call is ONLY made if you have an open position
        RayNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by giulyko00, Yesterday, 12:03 PM
        3 responses
        12 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by habeebft, Today, 07:27 AM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_ChristopherS  
        Started by AveryFlynn, Today, 04:57 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by Max238, Today, 01:28 AM
        4 responses
        39 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by r68cervera, Today, 05:29 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X