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

Multiple Stops Possible

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

    Multiple Stops Possible

    Hello...is it possible to have more than two stop losses?...in the below code i have a stop loss of - 3 after 5 ticks, but i also want to have a stop loss at 7 ticks: how can I add an other stop loss? and what conditions can i use?

    thank you for your time,


    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetStopLoss("", CalculationMode.Ticks, 7, false);
    }

    else if (Position.MarketPosition == MarketPosition.Long)
    {

    if (Close[0] >= Position.AvgPrice + 5 * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice - 3 * TickSize);
    }
    }

    #2
    Yes you can, you could do this by splitting up your entry order into two orders with unique signal names. You can then call SetStopLoss() twice specifying each unique signal name.

    When running the strategy, make sure you set "Entry handling" paremeter to "UniqueEntries".
    RayNinjaTrader Customer Service

    Comment


      #3
      Thanx Ray for your reply...and how can i specify each unique name for setstoploss()?


      i wrote this code below...and my trades are getting only stopped out. is this how i split the entry order?


      if (CrossAbove(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1)
      && ToTime(Time[
      0]) >= ToTime(9, 50, 00)
      && ToTime(Time[
      0]) <= ToTime(13, 0, 0))
      {
      EnterLong(
      1, "");
      EnterLong(
      1, "Secondtime for the 2nd stop");
      }
      if (Position.MarketPosition == MarketPosition.Long)
      {
      if (Close[0] >= Position.AvgPrice + 5 * TickSize){
      SetStopLoss(CalculationMode.Price, Position.AvgPrice -
      3 * TickSize);
      }
      if (Close[0] >= Position.AvgPrice + 7 * TickSize){
      SetStopLoss(CalculationMode.Price, Position.AvgPrice +
      1 * TickSize);
      }

      }

      Comment


        #4
        You can use this overload method for it:
        SetStopLoss(string fromEntrySignal, CalculationMode mode, double value, bool simulated)
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          i tried this code below, and my stops aren't being triggered and when i choose unique entries - the code is opening two positions each time. I am completely lost...what am i doing wrong?




          if (CrossAbove(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1)
          && ToTime(Time[
          0]) >= ToTime(9, 50, 00
          )
          && ToTime(Time[
          0]) <= ToTime(13, 0, 0
          ))
          {
          EnterLong(
          1, ""
          );
          EnterLong(
          1, "Secondtime for the 2nd stop"
          );
          }
          if
          (Position.MarketPosition == MarketPosition.Long)
          {
          if (Close[0] >= Position.AvgPrice + 5 * TickSize)
          {
          SetStopLoss(CalculationMode.Price, Position.AvgPrice -
          3
          * TickSize);
          }
          if (Close[0] >= Position.AvgPrice + 7 * TickSize)
          {
          SetStopLoss("Secondtime for the 2nd stop", CalculationMode.Price, Position.AvgPrice +
          1
          * TickSize, false);
          }

          Comment


            #6
            I can't see at first glance where the logic flaw may be.

            - Strip things down so you only have one signal and one stop --> Get this to work
            - Then add the next layer of logic
            - I would provide unique signal name for each entry
            RayNinjaTrader Customer Service

            Comment


              #7
              A possible reason as to why it opens two SetStopLoss() for you is because
              Code:
              [SIZE=2][FONT=Courier New][SIZE=2] SetStopLoss(CalculationMode.Price, Position.AvgPrice - [/SIZE][SIZE=2][COLOR=#800080]3[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] * TickSize)[/SIZE][/FONT][/SIZE]
              submits a stop loss for ALL orders and then later on you do another one designed for your unique order. This may be why you end up with your two orders.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                two different stop loss orders

                I did what you suggested. However when I set "Entry handling" paremeter to "UniqueEntries", I did get the stop losses that I wanted but at the same time I got into the market on different directions.

                So the system show me a long open position and a short open position at the same time. How can I close the long positions if the stop loss has not been hit while opening new short positions?

                Thanks for your help.

                JCF

                Comment


                  #9
                  Use names for your entrySignals. Are you sure you got a long position and a short position from the same strategy? This shouldn't be possible from within one strategy, but is possible from multiple strategies.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    multiple entries

                    Hey Josh, thanks for your help.

                    I am using a strategy that enters the market on 3 different set ups. That is why the system can go long signal # 1 but at the same time short signal # 2. Since the stop didn't hit signal # 1, I am still long while on a short position.

                    I assume that if I create three different strategies for each entry set up, I wont get this problem. Am I right?

                    Thanks for your help

                    JCF

                    Comment


                      #11
                      Correct, three different strategies would be the desired approach.
                      RayNinjaTrader Customer Service

                      Comment


                        #12
                        how can I backtest three different strategies

                        Thanks for your answer.

                        I will try to create three different strategies to correct the problem. The problem now is how to backtest them. Is there a way to combine three different strategies and backtest them at the same time? I need to do that since strategy # 2 can not go long if I have an open position on strategy # 1 or strategy # 3 or viceversa.

                        Thanks for your help.

                        JCF

                        Comment


                          #13
                          Unfortunately that is not currently supported.
                          Josh P.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by DJ888, 04-16-2024, 06:09 PM
                          6 responses
                          18 views
                          0 likes
                          Last Post DJ888
                          by DJ888
                           
                          Started by Jon17, Today, 04:33 PM
                          0 responses
                          1 view
                          0 likes
                          Last Post Jon17
                          by Jon17
                           
                          Started by Javierw.ok, Today, 04:12 PM
                          0 responses
                          6 views
                          0 likes
                          Last Post Javierw.ok  
                          Started by timmbbo, Today, 08:59 AM
                          2 responses
                          10 views
                          0 likes
                          Last Post bltdavid  
                          Started by alifarahani, Today, 09:40 AM
                          6 responses
                          41 views
                          0 likes
                          Last Post alifarahani  
                          Working...
                          X