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 Rapine Heihei, 04-23-2024, 07:51 PM
        2 responses
        30 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        942 views
        0 likes
        Last Post spwizard  
        Started by Max238, Today, 01:28 AM
        0 responses
        9 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by rocketman7, Today, 01:00 AM
        0 responses
        4 views
        0 likes
        Last Post rocketman7  
        Started by wzgy0920, 04-20-2024, 06:09 PM
        2 responses
        28 views
        0 likes
        Last Post wzgy0920  
        Working...
        X