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

Stop Loss - Low previous candle

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

    Stop Loss - Low previous candle

    Hi

    I have a very simple question but I don't know why I can't solve. I would like to be able to put the stop-loss at the low of the previous candle after my entry.

    -I create a double variable
    -When my order is executed I define the value of the variable is equal to the "Low" of the previous candle and then I define the stoploss with the value of that variable, but it doesn't work.

    I think the problem may be due to the conversion of arithmetic to ticks, or currency, price ... I don't know

    I'm going crazy

    Thank you

    #2
    Welcome to the forums jmrumbo!

    If you would like to place the stop loss at the Low of the previous candle please use a CalculationMode of Price with SetStopLoss and then use Low[1] for the price. This would have to be done in OnBarUpdate and cannot be done with the Strategy Builder. Please see the example below for using SetStopLoss in OnBarUpdate.

    SamplePriceModification - https://ninjatrader.com/support/help...of_stop_lo.htm

    If you want to place a stop loss to the low of the previous candle in the Strategy Builder, you will need to create your own logic using Exit methods in Conditions and Actions to do so since prices cannot be referenced in the Stop and Targets section. I have attached an example that can demonstrate using ExitLongStopMarket in the Conditions and Actions page to place and move the stop loss.

    We look forward to assisting.
    Attached Files
    Last edited by NinjaTrader_Jim; 04-20-2020, 01:08 PM.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks for your answer Jim

      Maybe I didn't explain well. I have a whole strategy created in the strategy builder with my input parameters and my take profit. The problem is only to define the stop loss. I would like the stop be at the previous candle low to my point of entry, and remain fixed at that price all the time

      Thanks

      Comment


        #4
        Hello jmrumbo,

        Since you want to place the stop based on price action, you will want to use Exit methods in the Conditions and Actions page. The example I attached in post #2 can demonstrate how you can use Exit methods in the Conditions and Actions page for your stop loss.

        We look forward to assisting.
        JimNinjaTrader Customer Service

        Comment


          #5
          Hello Jim,

          I am also trying to do the same. However, it is not working for me. Currently, I have this under the "Do the following":

          ExitLongStopMarket(Contracts, (Position.AveragePrice + (-10 * TickSize)), @"LongExit", @"Long");

          So say my entry price was 4492, therefore, the stoploss should have hit on 4489.50; but it never did.

          Can you make a quick video describing this?

          Thank you in advance.

          Comment


            #6
            Hello jaspindersingh,

            Thanks for your notes.

            We do not have a video demonstrating this specifically.

            You could view the sample strategy shared by NinjaTrader_Jim on post # 2 which demonstrates using Exit methods in the Conditions and Actions screen of the Strategy Builder to place the stop market order 10 ticks below the AveragePrice of the entry order that was placed.

            After downloading the script, you could import it onto your NinjaTrader platform by going to Tools > Import > NinjaScript AddOn.

            Once the script is imported, you could open a New > Strategy Builder window, select the 'MultiStepBreakeven' strategy on the Welcome screen of the Strategy Builder, and then navigate to the Conditions and Actions screen to see how the Exit methods are set up.

            To understand why the script is behaving as it is, such as placing orders or not placing orders when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating. In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

            Below is a link to a forum post that demonstrates how to use prints to understand behavior.
            https://ninjatrader.com/support/foru...121#post791121​​
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Thank you for replying. Still didn't work though.

              I have a Set 1 where I created group called Long. Here if the current price is above the previous high then under "Do the following" it will enter a long.

              I created a new variable to stoplossmode and set it equal to 0. Then I have a new set called Set 2 and here, I created another group called ExitLong which only has Position.MarketPosition = MarketPostionLong. Then under "Do the following" I have the following:

              ExitLongStopMarket(Contracts, (Position.AveragePrice + (-10 * TickSize)), @"LongExit", @"ExitLong");
              StopLossMode =1 ​


              still nothing.

              Comment


                #8
                Hello jaspindersingh,

                Thanks for your notes.

                Do you see any error messages in the Log tab of the Control Center when running the strategy? If so, what does the error report?

                Have you added debugging prints to your script to understand how your logic is evaluating?

                If the expected trade(s) are not appearing, this would indicate that the condition to place the order is not evaluating as true or the order is being ignored for other reasons.

                To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

                In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

                Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).​

                Below is a link to a forum post that demonstrates how to use prints to understand behavior.
                https://ninjatrader.com/support/foru...121#post791121
                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you.

                  I found a video that was helpful along with your suggestions. Putting it here for the ROW to use:

                  Try these examples: https://tradesaber.com/code-samplesJoin our Discord: https://discord.gg/2YU9GDme8j……………………………………………………………………………………………………………………….Trail Sto...


                  My strategy still doesn't take any profit. The comment section in this video says to create two longs and exits. That doesn't make sense. Strategy builder is not working as intended. If the current price is 10 ticks in the money then it should take profit. However, it doesn't.

                  Here's the sample strategy I'm trying to create.

                  current close is > then previous high = Long
                  take profit if current price is 10 ticks above the entry.
                  stop at the previous low.

                  I was able to get everything else to work except for the take profit. Please help.
                  Last edited by jaspindersingh; 08-21-2023, 09:38 PM. Reason: adding additional information

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by love2code2trade, Yesterday, 01:45 PM
                  4 responses
                  28 views
                  0 likes
                  Last Post love2code2trade  
                  Started by funk10101, Today, 09:43 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post funk10101  
                  Started by pkefal, 04-11-2024, 07:39 AM
                  11 responses
                  37 views
                  0 likes
                  Last Post jeronymite  
                  Started by bill2023, Yesterday, 08:51 AM
                  8 responses
                  45 views
                  0 likes
                  Last Post bill2023  
                  Started by yertle, Today, 08:38 AM
                  6 responses
                  26 views
                  0 likes
                  Last Post ryjoga
                  by ryjoga
                   
                  Working...
                  X