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

I need help, to place stop loss in the strategy builder

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

    I need help, to place stop loss in the strategy builder

    I need help, to place stop loss in the strategy builder, I am creating a 20 period fast and 200 period slow moving average crossover strategy that opens a long position when the 20 moving average crosses the 200 moving average up and sets a stop loss below the previous bar, and opens a short position when the 20 moving average crosses the 200 moving average down and sets a stop loss above the last bar,
    I have already created it to open the positions as I want, but I have not been able to set the stop loss.

    I would also like to be able to place the first target at the highest high next to the long entry.

    And the first target at the lowest low of the short entry,
    I would be very grateful if you could help me please.

    #2
    Hello Miguelcuello16,

    Thank you for your post.

    Just to clarify, when you say you want to be able to place targets at the highest high and lowest low, do you mean of the session so far? For just a particular period prior to the entry? Also, when you say you want to put the stop above or below the previous bar, how far away are you wanting to put that?

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      The stop I mean to place it for example in a short position, at the moment the short position is opened, the stop should be at the top of the bar, prior to the position opening.
      And in the target I refer to the lowest peak, which is close to the opening of the position, I attach screenshots to explain it.
      Last edited by Miguelcuello16; 04-21-2022, 08:26 AM.

      Comment


        #4
        Hello Miguescuello16,

        Thank you for your reply.

        You'd need to more precisely define how many bars back you want to look for the lowest lows and highest highs. How far back are you specifically wanting to look for those conditions?

        Thanks in advance; I look forward to assisting you further.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Thank you for answering, for the Highs and lows would be the last 20 bars.

          Comment


            #6
            Hello Miguelcuello16,

            Thank you for your reply.

            I've only just noticed that you're wanting to do this with the Strategy Builder. In the Strategy Builder you cannot use dynamic values, such as bar prices, to place stops or targets using the Set methods on the stops and targets page. You would need to use Exit orders to exit the position. Also, if you try to submit both the stop and the target as exit orders at the same time, one will be ignored due to internal order handling rules as you cannot connect them via OCO from the Strategy Builder, so you would need to use a market order for the profit target.



            You are able to add dynamic stops using set methods when manually coding, the Builder just isn't capable of the logic necessary to do so.

            I'm attaching two example scripts that will enter long or short based upon which way the crossover of the two SMAs occurs. The Strategy Builder version uses Exit orders and the manually coded version, which you can view in the NinjaScript Editor, uses dynamically updated Set methods for the stop and target.

            Please let us know if we may be of further assistance to you.
            Attached Files
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              NinjaTrader_Kate

              Thank you very much for the examples, I'll check them right now, thank you

              Comment


                #8
                Click image for larger version

Name:	EMA Cross Example.jpg
Views:	989
Size:	91.7 KB
ID:	1205596EMA Cross Example.jpgNinjaTrader_Kate To continue this, how would one change the profit target from the previous high/Low to a profit target that is 1.5 times the distance to the stop from the entry point? The stop being the high/Low of the time period of the last two crosses?
                Attached Files
                Last edited by NewCode50; 06-17-2022, 05:26 PM.

                Comment


                  #9
                  Hello NewCode50,

                  Thank you for your reply.

                  This would be fairly difficult in the Strategy Builder, but could likely be achieved by using Custom Series to hold calculations. You could save the prior high or low to a series variable, then calculate the difference between that and the current price at the time of entry and save that to another series variable using offsets, and finally calculate the profit target price using offsets from that series.

                  You'd have to use exit orders for the entries and exits like in the above example in the Builder as well.

                  Please let us know if we may be of further assistance to you.
                  Kate W.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by burtoninlondon, Today, 12:38 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post burtoninlondon  
                  Started by AaronKoRn, Yesterday, 09:49 PM
                  0 responses
                  12 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
                  13 views
                  0 likes
                  Last Post strategist007  
                  Started by StockTrader88, 03-06-2021, 08:58 AM
                  44 responses
                  3,982 views
                  3 likes
                  Last Post jhudas88  
                  Working...
                  X