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

avoid re-enter after a stop-loss is hit

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

    avoid re-enter after a stop-loss is hit

    Hi Ninjas.

    Assumed, that I am using a simple Strategie that goes long/short under the following circumstances:


    1) if (SMA(period)[0] > SMA(period)[1])
    --> Enter Long

    2) if (SMA(period)[0] < SMA(period)[1])
    --> Enter Short

    within that Strategie I am also using a simple Stop-Loss. For example something like that:

    // if long
    3) SetStopLoss(CalculationMode.Price, Math.Max(Close[0] - Distance, Close[1] - Distance));


    To prevent, that this simple Strategy will re-enter after a stop-loss, I need to check within condition (1) and (2), whether the stop-loss (3) was hit or not in the last Bar.

    How can I do that?

    I found something about Monitoring - perhaps this is the right thing?


    But I have no Idea how to use this in a simple way within my strategie.

    Hope someone can give me a Hint

    Regards
    Trendseeker

    #2
    Hi Trendseek, you spotted the correct sample - with the help of the sample code you could check if the last trade was a stop out and then avoid entering the next signal in this direction by working with bool flags in your conditions.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hello all,
      Since I am not a coder, does anyone know how to do this (prevent re-entry after stop loss) in Strategy Builder?

      Comment


        #4
        Hello DMDINAZ,

        Welcome to the NinjaTrader support forum.

        In the builder, you would essentially just want to prevent further entries after the first as you can only set stop losses which always apply and cannot monitor them in the builder.

        You can do this by using user variables, here is one example of toggling between long and short only allowing one entry per side.
        1. from the inputs and variables section, define a bool variable named CanEnterLong and set its default value to true.
        2. from the inputs and variables section, define a bool variable named CanEnterShort and set its default value to true.
        3. In the long entry condition, in addition to the existing conditions check that the CanEnterLong bool variable is true
        4. In the long entry action, in addition to entering set the value of the CanEnterLong to false.
        5. In the long entry action, in addition to entering set the value of the CanEnterShort to true.

        This creates a one time entry for the long side but also enables the short side. The short side would be set up in the same way except it would check CanEnterShort is true in its condition and set CanEnterShort to false and CanEnterLong to true in its action. This will toggle between long and short trading and only allow one entry in that direction as it sets the bool to false once you enter.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by funk10101, Yesterday, 09:43 PM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by TheWhiteDragon, 01-21-2019, 12:44 PM
        5 responses
        551 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by rtwave, 04-12-2024, 09:30 AM
        5 responses
        37 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by funk10101, Today, 12:02 AM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by GLFX005, Today, 03:23 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Erick  
        Working...
        X